Feat: Ersetzt die Isar-Datenbank durch die drift-Datenbank
This commit is contained in:
59
lib/Entities/drift_database.dart
Normal file
59
lib/Entities/drift_database.dart
Normal file
@@ -0,0 +1,59 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:drift_flutter/drift_flutter.dart';
|
||||
|
||||
import 'time_frame_enum.dart';
|
||||
|
||||
part 'drift_database.g.dart';
|
||||
|
||||
class Accounts extends Table {
|
||||
IntColumn get id => integer().autoIncrement()();
|
||||
|
||||
TextColumn get name => text().withDefault(const Constant(''))();
|
||||
}
|
||||
|
||||
class Transactions extends Table {
|
||||
IntColumn get id => integer().autoIncrement()();
|
||||
|
||||
TextColumn get name => text().withDefault(const Constant(''))();
|
||||
|
||||
DateTimeColumn get date => dateTime().nullable()();
|
||||
|
||||
RealColumn get amount => real().withDefault(const Constant(0.0))();
|
||||
|
||||
IntColumn get accountId => integer().references(Accounts, #id)();
|
||||
|
||||
IntColumn get recurringTransactionId =>
|
||||
integer().nullable().references(RecurringTransactions, #id)();
|
||||
}
|
||||
|
||||
class RecurringTransactions extends Table {
|
||||
IntColumn get id => integer().autoIncrement()();
|
||||
|
||||
TextColumn get name => text().withDefault(const Constant(''))();
|
||||
|
||||
DateTimeColumn get startDate => dateTime().nullable()();
|
||||
|
||||
IntColumn get timeFrame => intEnum<TimeFrameEnum>()();
|
||||
|
||||
RealColumn get amount => real().withDefault(const Constant(0.0))();
|
||||
|
||||
IntColumn get accountId => integer().references(Accounts, #id)();
|
||||
}
|
||||
|
||||
@DriftDatabase(tables: [Accounts, Transactions, RecurringTransactions])
|
||||
class AppDatabase extends _$AppDatabase {
|
||||
AppDatabase() : super(_openConnection());
|
||||
|
||||
@override
|
||||
int get schemaVersion => 1;
|
||||
|
||||
static QueryExecutor _openConnection() {
|
||||
return driftDatabase(
|
||||
name: 'dragon_ledger',
|
||||
web: DriftWebOptions(
|
||||
sqlite3Wasm: Uri.parse('sqlite3.wasm'),
|
||||
driftWorker: Uri.parse('drift_worker.js'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user