You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! Very cool project. I like the idea of using one storage API across flutter platforms.
I am probably doing something silly, but in trying this out I am seeing unexpected sqflite UNIQUE constraint violation errors in my onUpgradeNeeded implementation. I can upload a whole sample project if it would be helpful. In the sample project, I see the error in the XCode debug area but not in the Flutter Debug Console for some reason. In my real project, I get a bigger stack trace. In each case, I am using the latest versions from pub.dev.
import 'dart:async';
import 'package:flutter/widgets.dart';
import 'package:idb_repro/storage/idb/idb.dart';
import 'package:idb_sqflite/idb_sqflite.dart';
abstract class DatabaseService<DBID> {
IdbFactory get idbFactory;
Future<Database> open(DBID dbid) async => await idbFactory.open(dbName(dbid),
version: version, onUpgradeNeeded: onUpgradeNeeded, onBlocked: onBlocked);
void onBlocked(Event event) {}
FutureOr<void> onUpgradeNeeded(VersionChangeEvent event);
String dbName(DBID dbid);
int get version;
}
Future<IdbFactory>? _idbFactory;
Future<IdbFactory> globalIdbFactory() {
WidgetsFlutterBinding.ensureInitialized();
_idbFactory ??= getIdbFactory(pathHint: "idb_repro");
return _idbFactory!;
}
const String kUsersStore = 'users';
class ExampleDatabaseService extends DatabaseService<String> {
@override
final IdbFactory idbFactory;
ExampleDatabaseService({required this.idbFactory});
@override
String dbName(String dbid) => 'user:{dbid}';
@override
int get version => 2;
@override
FutureOr<void> onUpgradeNeeded(VersionChangeEvent event) async {
final db = event.database;
final existing = Set.from(db.objectStoreNames);
if (event.oldVersion < 1) {
// I have seen cases where event.oldVersion is 0 but when we run this code, the db already has the store and version set to the `version` param.
if (existing.contains(kUsersStore)) {
print("Unexpectedly found $kUsersStore");
} else {
db.createObjectStore(kUsersStore);
}
}
// I've seen the error occur here as well:
// if (event.oldVersion < 2) {
// final futures = <Future<void>>[];
// for (var storeName in [kUsersStore]) {
// futures.add(event.transaction.objectStore(storeName).clear());
// }
//
// in checkStore from this await:
// await Future.wait(futures);
// }
}
}
example code:
final dbFactory = await globalIdbFactory();
final dbService = ExampleDatabaseService(idbFactory: dbFactory);
final db1 = await dbService.open('user1');
The text was updated successfully, but these errors were encountered:
Hi! Very cool project. I like the idea of using one storage API across flutter platforms.
I am probably doing something silly, but in trying this out I am seeing unexpected sqflite UNIQUE constraint violation errors in my
onUpgradeNeeded
implementation. I can upload a whole sample project if it would be helpful. In the sample project, I see the error in the XCode debug area but not in the Flutter Debug Console for some reason. In my real project, I get a bigger stack trace. In each case, I am using the latest versions from pub.dev.Example error:
Another example error (from main project, not the code extracted below)
Another one also from main project, with a couple details elided:
The below code is extracted from my project where I first saw the bug.
sqflite_io.dart:
idb_io.dart:
"database_service.dart"
example code:
The text was updated successfully, but these errors were encountered: