mirror of https://github.com/AMT-Cheif/drift.git
Support contains (#527)
This commit is contained in:
parent
e90d72f25f
commit
81a476662c
|
@ -17,6 +17,13 @@ extension StringExpressionOperators on Expression<String> {
|
|||
return _LikeOperator(this, Variable.withString(regex), operator: 'REGEXP');
|
||||
}
|
||||
|
||||
/// Whether this expression contains [substring].
|
||||
///
|
||||
/// This is equivalent to calling [like] with `%<substring>%`.
|
||||
Expression<bool> contains(String substring) {
|
||||
return like('%$substring%');
|
||||
}
|
||||
|
||||
/// Uses the given [collate] sequence when comparing this column to other
|
||||
/// values.
|
||||
Expression<String> collate(Collate collate) {
|
||||
|
|
|
@ -32,4 +32,14 @@ void main() {
|
|||
expect(row.read(tomorrowStamp) - row.read(nowStamp),
|
||||
const Duration(days: 1).inSeconds);
|
||||
});
|
||||
|
||||
test('text contains', () async {
|
||||
const stringLiteral = Constant('Some sql string literal');
|
||||
final containsSql = stringLiteral.contains('sql');
|
||||
|
||||
final row =
|
||||
await (db.selectOnly(db.users)..addColumns([containsSql])).getSingle();
|
||||
|
||||
expect(row.read(containsSql), isTrue);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -31,6 +31,11 @@ void main() {
|
|||
expect(ctx.boundVariables, isEmpty);
|
||||
});
|
||||
|
||||
test('can use contains', () {
|
||||
expect(
|
||||
expression.contains('foo bar'), generates('col LIKE ?', ['%foo bar%']));
|
||||
});
|
||||
|
||||
test('can use string functions', () {
|
||||
expect(expression.upper(), generates('UPPER(col)'));
|
||||
expect(expression.lower(), generates('LOWER(col)'));
|
||||
|
|
Loading…
Reference in New Issue