Add a required QueryExecutor
argument to transaction
callbacks.
This commit is contained in:
parent
f154013c48
commit
7e19bb2a47
4 changed files with 14 additions and 5 deletions
|
@ -1,6 +1,8 @@
|
||||||
# 2.1.0
|
# 2.1.0
|
||||||
* Split the formerly 600+ line `src/query.dart` up into
|
* Split the formerly 600+ line `src/query.dart` up into
|
||||||
separate files.
|
separate files.
|
||||||
|
* **BREAKING**: Add a required `QueryExecutor` argument to `transaction`
|
||||||
|
callbacks.
|
||||||
|
|
||||||
# 2.0.1
|
# 2.0.1
|
||||||
* Apply `package:pedantic` fixes.
|
* Apply `package:pedantic` fixes.
|
||||||
|
|
|
@ -34,7 +34,7 @@ class _FakeExecutor extends QueryExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<T> transaction<T>(FutureOr<T> Function() f) {
|
Future<T> transaction<T>(FutureOr<T> Function(QueryExecutor) f) {
|
||||||
throw UnsupportedError('Transactions are not supported.');
|
throw UnsupportedError('Transactions are not supported.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,9 +263,9 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
|
||||||
fields.map(adornWithTableName).toList())
|
fields.map(adornWithTableName).toList())
|
||||||
.then((it) => it.map(deserialize).toList());
|
.then((it) => it.map(deserialize).toList());
|
||||||
} else {
|
} else {
|
||||||
return executor.transaction(() async {
|
return executor.transaction((tx) async {
|
||||||
// TODO: Can this be done with just *one* query?
|
// TODO: Can this be done with just *one* query?
|
||||||
var existing = await get(executor);
|
var existing = await get(tx);
|
||||||
//var sql = compile(preamble: 'SELECT $tableName.id', withFields: false);
|
//var sql = compile(preamble: 'SELECT $tableName.id', withFields: false);
|
||||||
return executor
|
return executor
|
||||||
.query(tableName, sql, substitutionValues)
|
.query(tableName, sql, substitutionValues)
|
||||||
|
|
|
@ -11,6 +11,13 @@ abstract class QueryExecutor {
|
||||||
String tableName, String query, Map<String, dynamic> substitutionValues,
|
String tableName, String query, Map<String, dynamic> substitutionValues,
|
||||||
[List<String> returningFields]);
|
[List<String> returningFields]);
|
||||||
|
|
||||||
/// Begins a database transaction.
|
/// Enters a database transaction, performing the actions within,
|
||||||
Future<T> transaction<T>(FutureOr<T> f());
|
/// and returning the results of [f].
|
||||||
|
///
|
||||||
|
/// If [f] fails, the transaction will be rolled back, and the
|
||||||
|
/// responsible exception will be re-thrown.
|
||||||
|
///
|
||||||
|
/// Whether nested transactions are supported depends on the
|
||||||
|
/// underlying driver.
|
||||||
|
Future<T> transaction<T>(FutureOr<T> Function(QueryExecutor) f);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue