2026-02-14 13:06:23 +00:00
|
|
|
import 'package:drift/drift.dart';
|
|
|
|
|
import 'package:drift/native.dart';
|
|
|
|
|
import 'package:path/path.dart' as p;
|
|
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LazyDatabase openConnection() {
|
|
|
|
|
return LazyDatabase(() async {
|
|
|
|
|
// Determine the platform-specific database directory
|
|
|
|
|
Directory dbDirectory;
|
|
|
|
|
|
|
|
|
|
if (Platform.isLinux || Platform.isWindows || Platform.isMacOS) {
|
|
|
|
|
final appSupportDir = await getApplicationSupportDirectory();
|
|
|
|
|
dbDirectory = Directory(p.join(appSupportDir.path, 'd4rt_formulas'));
|
|
|
|
|
} else {
|
|
|
|
|
dbDirectory = await getApplicationDocumentsDirectory();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ensure the directory exists
|
|
|
|
|
await dbDirectory.create(recursive: true);
|
|
|
|
|
|
|
|
|
|
// Create the database file in the platform-specific directory
|
|
|
|
|
final file = File(p.join(dbDirectory.path, 'formulas.sqlite'));
|
2026-02-18 10:25:14 +00:00
|
|
|
print( "Database file path: ${file.path}");
|
2026-02-14 13:06:23 +00:00
|
|
|
return NativeDatabase.createInBackground(file);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|