mirror of https://github.com/AMT-Cheif/drift.git
Update existing tests to respect transactions
This commit is contained in:
parent
049a970b37
commit
b5237bf36b
|
@ -117,7 +117,10 @@ mixin QueryEngine on DatabaseConnectionUser {
|
||||||
final affectedRows =
|
final affectedRows =
|
||||||
executor.doWhenOpened((_) => executor.runUpdate(query, mappedArgs));
|
executor.doWhenOpened((_) => executor.runUpdate(query, mappedArgs));
|
||||||
|
|
||||||
await streamQueries.handleTableUpdates(updates.map((t) => t.$tableName).toSet());
|
if (updates != null) {
|
||||||
|
await streamQueries
|
||||||
|
.handleTableUpdates(updates.map((t) => t.$tableName).toSet());
|
||||||
|
}
|
||||||
|
|
||||||
return affectedRows;
|
return affectedRows;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ class DeleteStatement<UserTable> extends Query<UserTable, dynamic> {
|
||||||
await ctx.database.executor.runDelete(ctx.sql, ctx.boundVariables);
|
await ctx.database.executor.runDelete(ctx.sql, ctx.boundVariables);
|
||||||
|
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
database.markTableUpdated(table.$tableName);
|
database.markTablesUpdated({table.$tableName});
|
||||||
}
|
}
|
||||||
return rows;
|
return rows;
|
||||||
});
|
});
|
||||||
|
|
|
@ -44,7 +44,7 @@ class InsertStatement<DataClass> {
|
||||||
|
|
||||||
await database.executor.doWhenOpened((e) async {
|
await database.executor.doWhenOpened((e) async {
|
||||||
await database.executor.runInsert(ctx.sql, ctx.boundVariables);
|
await database.executor.runInsert(ctx.sql, ctx.boundVariables);
|
||||||
database.markTableUpdated(table.$tableName);
|
database.markTablesUpdated({table.$tableName});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ class UpdateStatement<T, D> extends Query<T, D> {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
database.markTableUpdated(table.$tableName);
|
database.markTablesUpdated({table.$tableName});
|
||||||
}
|
}
|
||||||
|
|
||||||
return rows;
|
return rows;
|
||||||
|
|
|
@ -49,7 +49,7 @@ void main() {
|
||||||
|
|
||||||
await db.delete(db.users).go();
|
await db.delete(db.users).go();
|
||||||
|
|
||||||
verify(streamQueries.handleTableUpdates('users'));
|
verify(streamQueries.handleTableUpdates({'users'}));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('are not issued when no data was changed', () async {
|
test('are not issued when no data was changed', () async {
|
||||||
|
|
|
@ -24,7 +24,7 @@ void main() {
|
||||||
test('streams fetch when the underlying data changes', () {
|
test('streams fetch when the underlying data changes', () {
|
||||||
db.select(db.users).watch().listen((_) {});
|
db.select(db.users).watch().listen((_) {});
|
||||||
|
|
||||||
db.markTableUpdated('users');
|
db.markTablesUpdated({'users'});
|
||||||
|
|
||||||
// twice: Once because the listener attached, once because the data changed
|
// twice: Once because the listener attached, once because the data changed
|
||||||
verify(executor.runSelect(any, any)).called(2);
|
verify(executor.runSelect(any, any)).called(2);
|
||||||
|
@ -34,7 +34,7 @@ void main() {
|
||||||
test('when no listeners were attached', () {
|
test('when no listeners were attached', () {
|
||||||
db.select(db.users).watch();
|
db.select(db.users).watch();
|
||||||
|
|
||||||
db.markTableUpdated('users');
|
db.markTablesUpdated({'users'});
|
||||||
|
|
||||||
verifyNever(executor.runSelect(any, any));
|
verifyNever(executor.runSelect(any, any));
|
||||||
});
|
});
|
||||||
|
@ -44,7 +44,7 @@ void main() {
|
||||||
clearInteractions(executor);
|
clearInteractions(executor);
|
||||||
|
|
||||||
subscription.cancel();
|
subscription.cancel();
|
||||||
db.markTableUpdated('users');
|
db.markTablesUpdated({'users'});
|
||||||
|
|
||||||
verifyNever(executor.runSelect(any, any));
|
verifyNever(executor.runSelect(any, any));
|
||||||
});
|
});
|
||||||
|
|
|
@ -67,7 +67,7 @@ void main() {
|
||||||
content: 'Updated content',
|
content: 'Updated content',
|
||||||
));
|
));
|
||||||
|
|
||||||
verify(streamQueries.handleTableUpdates('todos'));
|
verify(streamQueries.handleTableUpdates({'todos'}));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('are not issued when no data was changed', () async {
|
test('are not issued when no data was changed', () async {
|
||||||
|
@ -109,8 +109,7 @@ void main() {
|
||||||
test('informs about updated tables', () async {
|
test('informs about updated tables', () async {
|
||||||
await db.customUpdate('', updates: {db.users, db.todosTable});
|
await db.customUpdate('', updates: {db.users, db.todosTable});
|
||||||
|
|
||||||
verify(streamQueries.handleTableUpdates('users'));
|
verify(streamQueries.handleTableUpdates({'users', 'todos'}));
|
||||||
verify(streamQueries.handleTableUpdates('todos'));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue