mirror of https://github.com/AMT-Cheif/drift.git
Log statements during migrations, if desired
This commit is contained in:
parent
83f8fdd105
commit
f15e06fbb0
|
@ -21,7 +21,7 @@ abstract class _DatabaseOwner extends QueryExecutor {
|
||||||
|
|
||||||
final bool logStatements;
|
final bool logStatements;
|
||||||
|
|
||||||
void _log(String sql, List args) {
|
void _log(String sql, [List args]) {
|
||||||
if (logStatements == true) {
|
if (logStatements == true) {
|
||||||
final formattedArgs = (args?.isEmpty ?? true) ? ' no variables' : args;
|
final formattedArgs = (args?.isEmpty ?? true) ? ' no variables' : args;
|
||||||
print('moor: $sql with $formattedArgs');
|
print('moor: $sql with $formattedArgs');
|
||||||
|
@ -94,12 +94,12 @@ class FlutterQueryExecutor extends _DatabaseOwner {
|
||||||
onCreate: (db, version) {
|
onCreate: (db, version) {
|
||||||
_hadMigration = true;
|
_hadMigration = true;
|
||||||
return databaseInfo.handleDatabaseCreation(
|
return databaseInfo.handleDatabaseCreation(
|
||||||
executor: (sql) => db.execute(sql),
|
executor: _migrationExecutor(db),
|
||||||
);
|
);
|
||||||
}, onUpgrade: (db, from, to) {
|
}, onUpgrade: (db, from, to) {
|
||||||
_hadMigration = true;
|
_hadMigration = true;
|
||||||
return databaseInfo.handleDatabaseVersionChange(
|
return databaseInfo.handleDatabaseVersionChange(
|
||||||
executor: (sql) => db.execute(sql), from: from, to: to);
|
executor: _migrationExecutor(db), from: from, to: to);
|
||||||
}, onOpen: (db) async {
|
}, onOpen: (db) async {
|
||||||
db = db;
|
db = db;
|
||||||
// the openDatabase future will resolve later, so we can get an instance
|
// the openDatabase future will resolve later, so we can get an instance
|
||||||
|
@ -113,6 +113,16 @@ class FlutterQueryExecutor extends _DatabaseOwner {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SqlExecutor _migrationExecutor(s.Database db) {
|
||||||
|
return (sql) {
|
||||||
|
if (logStatements) {
|
||||||
|
_log(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
db.execute(sql);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
TransactionExecutor beginTransaction() {
|
TransactionExecutor beginTransaction() {
|
||||||
return _SqfliteTransactionExecutor.startFromDb(this);
|
return _SqfliteTransactionExecutor.startFromDb(this);
|
||||||
|
|
Loading…
Reference in New Issue