mirror of https://github.com/AMT-Cheif/drift.git
Add substr to Dart query builder (#2555)
This commit is contained in:
parent
fae8be00d2
commit
f3e6ef26c4
|
@ -3,6 +3,8 @@
|
||||||
- Add support for subqueries in the Dart query builder.
|
- Add support for subqueries in the Dart query builder.
|
||||||
- Add `isInExp` and `isNotInExp` to construct `IS IN` expressions with arbitrary
|
- Add `isInExp` and `isNotInExp` to construct `IS IN` expressions with arbitrary
|
||||||
expressions.
|
expressions.
|
||||||
|
- Add the `substr` extension on `Expression<String>` to call the sqlite3 function from
|
||||||
|
the Dart API.
|
||||||
- Add `isolateSetup` to `NativeDatabase.createInBackground()` to override libraries.
|
- Add `isolateSetup` to `NativeDatabase.createInBackground()` to override libraries.
|
||||||
|
|
||||||
## 2.10.0
|
## 2.10.0
|
||||||
|
|
|
@ -128,6 +128,21 @@ extension StringExpressionOperators on Expression<String> {
|
||||||
Expression<String> trimRight() {
|
Expression<String> trimRight() {
|
||||||
return FunctionCallExpression('RTRIM', [this]);
|
return FunctionCallExpression('RTRIM', [this]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Calls the [`substr`](https://sqlite.org/lang_corefunc.html#substr)
|
||||||
|
/// function on this string.
|
||||||
|
///
|
||||||
|
/// Note that the function has different semantics than the [String.substring]
|
||||||
|
/// method for Dart strings - for instance, the [start] index starts at one
|
||||||
|
/// and [length] can be negative to return a section of the string before
|
||||||
|
/// [start].
|
||||||
|
Expression<String> substr(int start, [int? length]) {
|
||||||
|
return FunctionCallExpression('SUBSTR', [
|
||||||
|
this,
|
||||||
|
Constant<int>(start),
|
||||||
|
if (length != null) Constant<int>(length),
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A `text LIKE pattern` expression that will be true if the first expression
|
/// A `text LIKE pattern` expression that will be true if the first expression
|
||||||
|
|
|
@ -123,6 +123,10 @@ void main() {
|
||||||
const literal = Constant(' hello world ');
|
const literal = Constant(' hello world ');
|
||||||
expect(eval(literal.trimRight()), completion(' hello world'));
|
expect(eval(literal.trimRight()), completion(' hello world'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('substring', () {
|
||||||
|
expect(eval(Constant('hello world').substr(7)), completion('world'));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('coalesce', () async {
|
test('coalesce', () async {
|
||||||
|
|
|
@ -48,4 +48,9 @@ void main() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('substr', () {
|
||||||
|
expect(expression.substr(10), generates('SUBSTR(col, 10)'));
|
||||||
|
expect(expression.substr(10, 2), generates('SUBSTR(col, 10, 2)'));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue