2023-07-06 17:18:41 +03:30
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:drift/drift.dart';
|
|
|
|
|
import 'package:drift/native.dart';
|
2023-09-06 21:03:43 +03:30
|
|
|
// import 'package:hiddify/data/local/dao/dao.dart';
|
|
|
|
|
import 'package:hiddify/data/local/dao/profiles_dao.dart'; // TODO https://github.com/simolus3/drift/issues/2589
|
2023-07-06 17:18:41 +03:30
|
|
|
import 'package:hiddify/data/local/tables.dart';
|
|
|
|
|
import 'package:hiddify/data/local/type_converters.dart';
|
2023-08-19 22:27:23 +03:30
|
|
|
import 'package:hiddify/services/files_editor_service.dart';
|
2023-07-06 17:18:41 +03:30
|
|
|
import 'package:path/path.dart' as p;
|
|
|
|
|
|
|
|
|
|
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 {
|
2023-08-19 22:27:23 +03:30
|
|
|
final dbDir = await FilesEditorService.getDatabaseDirectory();
|
|
|
|
|
final file = File(p.join(dbDir.path, 'db.sqlite'));
|
2023-07-06 17:18:41 +03:30
|
|
|
return NativeDatabase.createInBackground(file);
|
|
|
|
|
});
|
|
|
|
|
}
|