mirror of https://github.com/AMT-Cheif/drift.git
moving transaction savepoint statements to NoTransactionDelegate
This commit is contained in:
parent
43f75dd3af
commit
72368c9171
|
@ -3,6 +3,12 @@ import 'dart:async' show FutureOr;
|
||||||
import 'package:drift/drift.dart';
|
import 'package:drift/drift.dart';
|
||||||
import 'package:drift/src/runtime/executor/helpers/results.dart';
|
import 'package:drift/src/runtime/executor/helpers/results.dart';
|
||||||
|
|
||||||
|
String _defaultSavepoint(int depth) => 'SAVEPOINT s$depth';
|
||||||
|
|
||||||
|
String _defaultRelease(int depth) => 'RELEASE s$depth';
|
||||||
|
|
||||||
|
String _defaultRollbackToSavepoint(int depth) => 'ROLLBACK TO s$depth';
|
||||||
|
|
||||||
/// An interface that supports sending database queries. Used as a backend for
|
/// An interface that supports sending database queries. Used as a backend for
|
||||||
/// drift.
|
/// drift.
|
||||||
///
|
///
|
||||||
|
@ -132,6 +138,18 @@ class NoTransactionDelegate extends TransactionDelegate {
|
||||||
/// database engine.
|
/// database engine.
|
||||||
final String rollback;
|
final String rollback;
|
||||||
|
|
||||||
|
/// The statement that will create a savepoint for a given depth of a transaction
|
||||||
|
/// on this database engine.
|
||||||
|
final String Function(int depth) savepoint;
|
||||||
|
|
||||||
|
/// The statement that will release a savepoint for a given depth of a transaction
|
||||||
|
/// on this database engine.
|
||||||
|
final String Function(int depth) release;
|
||||||
|
|
||||||
|
/// The statement that will perform a rollback to a savepoint for a given depth
|
||||||
|
/// of a transaction on this database engine.
|
||||||
|
final String Function(int depth) rollbackToSavepoint;
|
||||||
|
|
||||||
/// Construct a transaction delegate indicating that native transactions
|
/// Construct a transaction delegate indicating that native transactions
|
||||||
/// aren't supported and need to be emulated by issuing statements and
|
/// aren't supported and need to be emulated by issuing statements and
|
||||||
/// locking the database.
|
/// locking the database.
|
||||||
|
@ -139,6 +157,9 @@ class NoTransactionDelegate extends TransactionDelegate {
|
||||||
this.start = 'BEGIN TRANSACTION',
|
this.start = 'BEGIN TRANSACTION',
|
||||||
this.commit = 'COMMIT TRANSACTION',
|
this.commit = 'COMMIT TRANSACTION',
|
||||||
this.rollback = 'ROLLBACK TRANSACTION',
|
this.rollback = 'ROLLBACK TRANSACTION',
|
||||||
|
this.savepoint = _defaultSavepoint,
|
||||||
|
this.release = _defaultRelease,
|
||||||
|
this.rollbackToSavepoint = _defaultRollbackToSavepoint,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -187,11 +187,9 @@ class _StatementBasedTransactionExecutor extends _TransactionExecutor {
|
||||||
_StatementBasedTransactionExecutor.nested(
|
_StatementBasedTransactionExecutor.nested(
|
||||||
_StatementBasedTransactionExecutor this._parent, int depth)
|
_StatementBasedTransactionExecutor this._parent, int depth)
|
||||||
: _delegate = _parent._delegate,
|
: _delegate = _parent._delegate,
|
||||||
_startCommand = 'SAVEPOINT s$depth',
|
_startCommand = _parent._delegate.savepoint(depth),
|
||||||
_commitCommand = _parent._db.dialect == SqlDialect.mariadb
|
_commitCommand = _parent._delegate.release(depth),
|
||||||
? 'RELEASE SAVEPOINT s$depth' : 'RELEASE s$depth',
|
_rollbackCommand = _parent._delegate.rollbackToSavepoint(depth),
|
||||||
_rollbackCommand = _parent._db.dialect == SqlDialect.mariadb
|
|
||||||
? 'ROLLBACK TO SAVEPOINT s$depth' : 'ROLLBACK TO s$depth',
|
|
||||||
super(_parent._db);
|
super(_parent._db);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
Loading…
Reference in New Issue