30 lines
885 B
Dart
30 lines
885 B
Dart
|
|
import 'dart:io';
|
||
|
|
|
||
|
|
import 'package:drift/drift.dart';
|
||
|
|
import 'package:drift/native.dart';
|
||
|
|
import 'package:hiddify/data/local/dao/dao.dart';
|
||
|
|
import 'package:hiddify/data/local/tables.dart';
|
||
|
|
import 'package:hiddify/data/local/type_converters.dart';
|
||
|
|
import 'package:path/path.dart' as p;
|
||
|
|
import 'package:path_provider/path_provider.dart';
|
||
|
|
|
||
|
|
part 'database.g.dart';
|
||
|
|
|
||
|
|
@DriftDatabase(tables: [ProfileEntries], daos: [ProfilesDao])
|
||
|
|
class AppDatabase extends _$AppDatabase {
|
||
|
|
AppDatabase({required QueryExecutor connection}) : super(connection);
|
||
|
|
|
||
|
|
AppDatabase.connect() : super(_openConnection());
|
||
|
|
|
||
|
|
@override
|
||
|
|
int get schemaVersion => 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
LazyDatabase _openConnection() {
|
||
|
|
return LazyDatabase(() async {
|
||
|
|
final dbFolder = await getApplicationDocumentsDirectory();
|
||
|
|
final file = File(p.join(dbFolder.path, 'db.sqlite'));
|
||
|
|
return NativeDatabase.createInBackground(file);
|
||
|
|
});
|
||
|
|
}
|