mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00

- Add connection_web.dart for IndexedDB via drift - Add connection_native.dart for sqlite3 - Remove direct platform-specific imports from database.dart - Enable web compilation without FFI dependencies
25 lines
957 B
Dart
25 lines
957 B
Dart
import 'dart:io';
|
|
import 'package:drift/drift.dart';
|
|
import 'package:drift/native.dart';
|
|
import 'package:path_provider/path_provider.dart';
|
|
import 'package:path/path.dart' as p;
|
|
import 'package:sqlite3/sqlite3.dart';
|
|
import 'package:sqlite3_flutter_libs/sqlite3_flutter_libs.dart';
|
|
|
|
DatabaseConnection connect() {
|
|
return DatabaseConnection.delayed(Future(() async {
|
|
if (Platform.isAndroid) {
|
|
await applyWorkaroundToOpenSqlite3OnOldAndroidVersions();
|
|
}
|
|
|
|
final cacheBase = (await getTemporaryDirectory()).path;
|
|
// Make sqlite3 pick a more suitable location for temporary files - the
|
|
// one from the system may be inaccessible due to sandboxing.
|
|
// We can't access /tmp on Android, which sqlite3 would try by default.
|
|
sqlite3.tempDirectory = cacheBase;
|
|
|
|
final appDocDir = await getApplicationDocumentsDirectory();
|
|
final dbPath = p.join(appDocDir.path, 'spotube.db');
|
|
return NativeDatabase(File(dbPath));
|
|
}));
|
|
} |