Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions lib/db/drift/shared_database.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'package:drift/drift.dart';
import 'package:drift_flutter/drift_flutter.dart';
import 'package:path/path.dart' as path;

import '../../utilities/stack_file_system.dart';

part 'shared_database.g.dart';

abstract final class SharedDrift {
static bool _didInit = false;

static SharedDatabase? _db;

static SharedDatabase get() {
if (!_didInit) {
driftRuntimeOptions.dontWarnAboutMultipleDatabases = true;
_didInit = true;
}

return _db ??= SharedDatabase._();
}
}

class CakepayOrders extends Table {
TextColumn get orderId => text()();

@override
Set<Column> get primaryKey => {orderId};
}

@DriftDatabase(tables: [CakepayOrders])
final class SharedDatabase extends _$SharedDatabase {
SharedDatabase._([QueryExecutor? executor])
: super(executor ?? _openConnection());

@override
int get schemaVersion => 1;

static QueryExecutor _openConnection() {
return driftDatabase(
name: "shared",
native: DriftNativeOptions(
shareAcrossIsolates: true,
databasePath: () async {
final dir = await StackFileSystem.applicationDriftDirectory();
return path.join(dir.path, "shared", "shared.db");
},
),
);
}
}
303 changes: 303 additions & 0 deletions lib/db/drift/shared_database.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading