Closed kmod-midori closed 3 years ago
That would be a nice addition indeed ! I've have personally did like this:
import 'dart:async';
import 'package:jaguar_query_sqflite/composer.dart';
import 'package:jaguar_query_sqflite/jaguar_query_sqflite.dart';
import 'package:kiwi_mobile/common/utils/logging.dart';
import 'package:logging/logging.dart';
import 'package:sqflite/sqflite.dart' as sqf;
class MySqfliteAdapter extends SqfliteAdapter {
sqf.Database _connection;
final _log = Logger('SQL');
MySqfliteAdapter.fromConnection(sqf.Database connection) : super.fromConnection(connection) {
_connection = connection;
}
/// Change connection to the database.
Future<void> switchDatabase(sqf.Database connection) async {
if(_connection.path == connection.path) {
//same database, do nothing
return;
}
if (_connection != null && _connection.isOpen) {
await close();
}
_connection = connection;
}
@override
Future<Map> findOne(Find st) async {
if(kSqliteDebug) {
_log.finest(composeFind(st));
}
final result = await super.findOne(st);
if(kSqliteDebug) {
_log.finest(result);
}
return result;
}
@override
Future<List<Map>> find(Find st) async {
if(kSqliteDebug) {
_log.finest(composeFind(st));
}
final results = await super.find(st);
if(kSqliteDebug) {
_log.finest(results);
}
return results;
}
@override
Future<int> remove(Remove st) {
if(kSqliteDebug) {
_log.finest(composeRemove(st));
}
return super.remove(st);
}
@override
Future<int> update(Update st) {
if(kSqliteDebug) {
_log.finest(composeUpdate(st));
}
return super.update(st);
}
@override
Future<T> insert<T>(Insert st) {
if(kSqliteDebug) {
_log.finest(composeInsert(st));
}
return super.insert(st);
}
@override
Future<void> insertMany<T>(InsertMany st) {
if(kSqliteDebug) {
_log.finest(composeInsertMany(st));
}
return super.insertMany(st);
}
@override
Future<void> updateMany(UpdateMany st) {
if(kSqliteDebug) {
_log.finest(composeUpdateMany(st));
}
return super.updateMany(st);
}
@override
Future<T> upsert<T>(Upsert st) {
if(kSqliteDebug) {
_log.finest(composeUpsert(st));
}
return super.upsert(st);
}
@override
Future<void> upsertMany<T>(UpsertMany st) {
if(kSqliteDebug) {
_log.finest(composeUpsertMany(st));
}
return super.upsertMany(st);
}
@override
Future<void> dropDb(DropDb st) {
if(kSqliteDebug) {
_log.finest(composeDropDb(st));
}
return super.dropDb(st);
}
@override
Future<void> dropTable(Drop st) {
if(kSqliteDebug) {
_log.finest(composeDrop(st));
}
return super.dropTable(st);
}
@override
Future<void> createDatabase(CreateDb st) {
if(kSqliteDebug) {
_log.finest(composeCreateDb(st));
}
return super.createDatabase(st);
}
@override
Future<void> createTable(Create st) {
if(kSqliteDebug) {
_log.finest(composeCreate(st));
}
return super.createTable(st);
}
@override
sqf.Database get connection => _connection;
@override
Future<void> alter(Alter st) {
if(kSqliteDebug) {
_log.finest(composeAlter(st));
}
return super.alter(st);
}
}
Like this I can see SQL and results
Master has this feature now. SqfliteAdapter(this.path, {this.version, this.logger});
Great! When can we see this released?
Currently the only way to inspect the final SQL for a
Find
statement seems to be have some kind of syntax error, which is quite annoying when things go wrong.Is it possible to inspect statements more conveniently, e.g. properly implement
toString
?