mirror of https://github.com/AMT-Cheif/drift.git
Fix zoned executors messing with other databases
This commit is contained in:
parent
cb46e2c07e
commit
7e798572a0
|
@ -84,7 +84,13 @@ abstract class DatabaseConnectionUser {
|
|||
/// but run them in a transaction-specific executor.
|
||||
@internal
|
||||
DatabaseConnectionUser get resolvedEngine {
|
||||
return (Zone.current[_zoneRootUserKey] as DatabaseConnectionUser?) ?? this;
|
||||
final fromZone = Zone.current[_zoneRootUserKey] as DatabaseConnectionUser?;
|
||||
|
||||
if (fromZone != null && fromZone.attachedDatabase == attachedDatabase) {
|
||||
return fromZone;
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/// Marks the [tables] as updated.
|
||||
|
|
|
@ -93,4 +93,21 @@ void main() {
|
|||
final db = TodoDb(executor);
|
||||
expect(db.customSelect('SELECT 1').getSingle(), throwsA('error'));
|
||||
});
|
||||
|
||||
test('zone database is ignored for operations on another database', () async {
|
||||
final ex1 = MockExecutor();
|
||||
final ex2 = MockExecutor();
|
||||
|
||||
final db1 = TodoDb(ex1);
|
||||
final db2 = TodoDb(ex2);
|
||||
addTearDown(db1.close);
|
||||
addTearDown(db2.close);
|
||||
|
||||
await db1.transaction(() async {
|
||||
await db2.customSelect('SELECT 1').get();
|
||||
});
|
||||
|
||||
verify(ex2.runSelect('SELECT 1', []));
|
||||
verifyNever(ex2.runSelect(any, any));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue