mirror of https://github.com/AMT-Cheif/drift.git
Add updates parameter to Batch.customStatement
This commit is contained in:
parent
8b4cb60f03
commit
5f887b8d2a
|
@ -2,6 +2,8 @@
|
|||
|
||||
- Add `textEnum` column builder and `EnumNameConverter` to be able to store enum
|
||||
values as string.
|
||||
- Add `updates` parameter to `Batch.customStatement` - it can be used to specify
|
||||
which tables are affected by the custom statement.
|
||||
|
||||
## 2.3.0-dev
|
||||
|
||||
|
|
|
@ -162,8 +162,13 @@ class Batch {
|
|||
/// See also:
|
||||
/// - [DatabaseConnectionUser.customStatement], the equivalent method outside
|
||||
/// of batches.
|
||||
void customStatement(String sql, [List<dynamic>? args]) {
|
||||
void customStatement(
|
||||
String sql, [
|
||||
List<dynamic>? args,
|
||||
Iterable<TableUpdate> updates = const Iterable.empty(),
|
||||
]) {
|
||||
_addSqlAndArguments(sql, args ?? const []);
|
||||
_createdUpdates.addAll(updates);
|
||||
}
|
||||
|
||||
void _addContext(GenerationContext ctx) {
|
||||
|
|
|
@ -81,6 +81,16 @@ void main() {
|
|||
);
|
||||
});
|
||||
|
||||
test('custom statement can update queries', () async {
|
||||
final update = TableUpdate.onTable(db.users);
|
||||
|
||||
await db.batch((batch) {
|
||||
batch.customStatement('SELECT 1', [], {update});
|
||||
});
|
||||
|
||||
verify(streamQueries.handleTableUpdates(argThat(contains(update))));
|
||||
});
|
||||
|
||||
test('supports inserts with upsert clause', () async {
|
||||
await db.batch((batch) {
|
||||
batch.insert(
|
||||
|
|
Loading…
Reference in New Issue