matchSQL method
The SQL matching the regexp pattern (a placeholder) against value
(a column). castToText for a column that may not be text.
Implementation
String matchSQL(
String value,
String pattern, {
required bool caseInsensitive,
required bool not,
bool castToText = false,
}) {
switch (this) {
case postgres:
{
var v = castToText ? 'CAST($value AS TEXT)' : value;
return '$v ${not ? '!' : ''}~${caseInsensitive ? '*' : ''} $pattern';
}
case mysql:
{
var flags = caseInsensitive ? 'in' : 'cn';
return "${not ? 'NOT ' : ''}REGEXP_LIKE($value, $pattern, '$flags')";
}
case function:
case dart:
{
var flags = caseInsensitive ? 'i' : '';
return "${not ? 'NOT ' : ''}regexp($pattern, $value, '$flags')";
}
}
}