Add updates parameter to Batch.customStatement

This commit is contained in:
Simon Binder 2022-12-12 22:31:48 +01:00
parent 8b4cb60f03
commit 5f887b8d2a
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
3 changed files with 18 additions and 1 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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(