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
|
- Add `textEnum` column builder and `EnumNameConverter` to be able to store enum
|
||||||
values as string.
|
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
|
## 2.3.0-dev
|
||||||
|
|
||||||
|
|
|
@ -162,8 +162,13 @@ class Batch {
|
||||||
/// See also:
|
/// See also:
|
||||||
/// - [DatabaseConnectionUser.customStatement], the equivalent method outside
|
/// - [DatabaseConnectionUser.customStatement], the equivalent method outside
|
||||||
/// of batches.
|
/// 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 []);
|
_addSqlAndArguments(sql, args ?? const []);
|
||||||
|
_createdUpdates.addAll(updates);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _addContext(GenerationContext ctx) {
|
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 {
|
test('supports inserts with upsert clause', () async {
|
||||||
await db.batch((batch) {
|
await db.batch((batch) {
|
||||||
batch.insert(
|
batch.insert(
|
||||||
|
|
Loading…
Reference in New Issue