Line data Source code
1 : import 'package:drift/drift.dart';
2 : import 'package:drift_flutter/drift_flutter.dart';
3 : import 'package:the_storage/src/db/database_path.dart';
4 : import 'package:the_storage/src/db/storage_table.dart';
5 :
6 : part 'storage_database.g.dart';
7 :
8 : /// Drift database for the storage package.
9 : @DriftDatabase(tables: [StorageEntries])
10 : class StorageDatabase extends _$StorageDatabase {
11 : /// Creates a database with the default name.
12 3 : StorageDatabase([QueryExecutor? executor])
13 3 : : super(executor ?? _openConnection('storage.db'));
14 :
15 : /// Creates a database with a custom name.
16 0 : StorageDatabase.withName(String name, [QueryExecutor? executor])
17 0 : : super(executor ?? _openConnection(name));
18 :
19 3 : @override
20 : int get schemaVersion => 1;
21 :
22 0 : static QueryExecutor _openConnection(String name) {
23 0 : return driftDatabase(
24 : name: name,
25 0 : native: nativeDatabaseOptions(name),
26 0 : web: DriftWebOptions(
27 0 : sqlite3Wasm: Uri.parse('sqlite3.wasm'),
28 0 : driftWorker: Uri.parse('drift_worker.js'),
29 : ),
30 : );
31 : }
32 : }
|