mirror of https://github.com/AMT-Cheif/drift.git
Save database after `RETURNING` write (#2206)
This commit is contained in:
parent
e2265eb597
commit
4644bce9dd
|
@ -181,7 +181,7 @@ class _WebDelegate extends DatabaseDelegate {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<QueryResult> runSelect(String statement, List<Object?> args) {
|
||||
Future<QueryResult> runSelect(String statement, List<Object?> args) async {
|
||||
_checkArgs(args);
|
||||
// todo at least for stream queries we should cache prepared statements.
|
||||
final stmt = _db.prepare(statement)..executeWith(args);
|
||||
|
@ -197,6 +197,11 @@ class _WebDelegate extends DatabaseDelegate {
|
|||
columnNames ??= []; // assume no column names when there were no rows
|
||||
|
||||
stmt.free();
|
||||
|
||||
if (statement.contains('RETURNING')) {
|
||||
await _handlePotentialUpdate();
|
||||
}
|
||||
|
||||
return Future.value(QueryResult(columnNames, rows));
|
||||
}
|
||||
|
||||
|
|
|
@ -64,4 +64,21 @@ void main() {
|
|||
final results = await db.customSelect('SELECT * FROM x1;').get();
|
||||
expect(results.length, 1);
|
||||
});
|
||||
|
||||
test('saves after returning', () async {
|
||||
final executor = WebExecutor();
|
||||
|
||||
var db = Database(executor.createConnection());
|
||||
addTearDown(() => executor.clearDatabaseAndClose(db));
|
||||
|
||||
await db.users.insertReturning(
|
||||
UsersCompanion.insert(name: 'my new user', birthDate: DateTime.now()));
|
||||
await db.close();
|
||||
|
||||
// Open a new database, the user should exist
|
||||
db = Database(executor.createConnection());
|
||||
final users = await db.users.select().get();
|
||||
expect(users,
|
||||
contains(isA<User>().having((e) => e.name, 'name', 'my new user')));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue