mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-26 08:54:42 +01:00
Add missing db functions for web
This commit is contained in:
parent
d01fd33f62
commit
41d60c6051
1 changed files with 35 additions and 0 deletions
|
@ -1,6 +1,9 @@
|
|||
import 'package:drift/drift.dart';
|
||||
import 'package:drift/wasm.dart';
|
||||
import 'package:flutter/services.dart' show rootBundle;
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:nc_photos/debug_util.dart';
|
||||
import 'package:nc_photos/entity/sqlite_table.dart' as sql;
|
||||
import 'package:sqlite3/wasm.dart';
|
||||
|
||||
Future<Map<String, dynamic>> getSqliteConnectionArgs() async => {};
|
||||
|
@ -24,6 +27,7 @@ QueryExecutor openSqliteConnection() {
|
|||
return WasmDatabase(
|
||||
sqlite3: sqlite3,
|
||||
path: "/drift/nc-photos/app.db",
|
||||
fileSystem: fs,
|
||||
// logStatements: true,
|
||||
);
|
||||
});
|
||||
|
@ -32,3 +36,34 @@ QueryExecutor openSqliteConnection() {
|
|||
Future<void> applyWorkaroundToOpenSqlite3OnOldAndroidVersions() async {
|
||||
// not supported on web
|
||||
}
|
||||
|
||||
Future<CommonDatabase> openRawSqliteDbFromAsset(
|
||||
String assetRelativePath,
|
||||
String outputFilename, {
|
||||
bool isReadOnly = false,
|
||||
}) async {
|
||||
final response = await http.get(Uri.parse("sqlite3.wasm"));
|
||||
final fs = await IndexedDbFileSystem.open(dbName: "nc-photos");
|
||||
final sqlite3 = await WasmSqlite3.load(
|
||||
response.bodyBytes,
|
||||
SqliteEnvironment(fileSystem: fs),
|
||||
);
|
||||
|
||||
if (!fs.exists("/app-file/$outputFilename")) {
|
||||
// copy file from assets
|
||||
final blob = await rootBundle.load("assets/$assetRelativePath");
|
||||
final buffer = blob.buffer;
|
||||
fs.createFile("/app-file/$outputFilename");
|
||||
fs.write(
|
||||
"/app-file/$outputFilename",
|
||||
buffer.asUint8List(blob.offsetInBytes, blob.lengthInBytes),
|
||||
0,
|
||||
);
|
||||
await fs.flush();
|
||||
}
|
||||
return sqlite3.open("/app-file/$outputFilename");
|
||||
}
|
||||
|
||||
Future<dynamic> exportSqliteDb(sql.SqliteDb db) async {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue