aboutsummaryrefslogtreecommitdiff
path: root/lib/model/db/db_extension.dart
diff options
context:
space:
mode:
Diffstat (limited to 'lib/model/db/db_extension.dart')
-rw-r--r--lib/model/db/db_extension.dart13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/model/db/db_extension.dart b/lib/model/db/db_extension.dart
new file mode 100644
index 0000000..a0d2a66
--- /dev/null
+++ b/lib/model/db/db_extension.dart
@@ -0,0 +1,13 @@
+import 'package:sqflite/sqflite.dart';
+
+extension ExtraDatabase on Database {
+ // check table existence via `sqlite_master`
+ // `sqlite_schema` is the alias used in SQLite documentation,
+ // but it was introduced in SQLite v3.33.0 and it is unavailable on Android API < 34,
+ // and the historical alias `sqlite_master` is still supported.
+ // cf https://www.sqlite.org/faq.html#q7
+ Future<bool> tableExists(String table) async {
+ final results = await query('sqlite_master', where: 'type = ? AND name = ?', whereArgs: ['table', table]);
+ return results.isNotEmpty;
+ }
+}