-
-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
delete only one registrer #291
Comments
final oldCount = await StoreDb.myCoolStore.count(_database);
final key = await StoreDb.myCoolStore.findKey(
_database,
finder: Finder(filter: Filter.equals('myCoolID', 'coolId')),
);
final wrongCounter = await StoreDb.myCoolStore.record(key).delete(_database);
final newCount = await StoreDb.myCoolStore.count(_database); By the way @alextekartik I encounter an issue while unit testing this single deletion on multiple objects, |
@flutter-painter Can you share your unit test so I can reproduce? RecordRef.delete return value is not specified (but in this case, I know it returns the key deleted). Why are you assigning it to a counter (wrongCounter). store.delete return the count of deleted items (newCount). |
Thanks for the answer, so it is normal for behaviour for record(key).delete. Here goes the unit test : class Shop {
final int id;
final String name;
const Shop({this.id, this.name});
Map<String, dynamic> toMap() {
return {'id': id, 'name': name};
}
factory Shop.fromMap(Map<String, dynamic> map) {
return Shop(id: map['id'] ?? 0, name: map['name'] ?? '');
}
String toJson() => json.encode(toMap());
factory Shop.fromJson(String source) => Shop.fromMap(json.decode(source));
}
Future main() async {
final _database = await databaseFactoryMemory.openDatabase(('test.db'));
final _dbStore = sembast.intMapStoreFactory.store('shops');
final Shop shop = Shop(id: 1, name: 'epi boujou');
final Shop shop2 = Shop(id: 2, name: 'tati');
final Shop shop3 = Shop(id: 3, name: 'toto');
group('test shops store', () {
test('create_shop', () async {
final created = await _dbStore.add(_database, shop.toMap());
final created2 = await _dbStore.add(_database, shop2.toMap());
final created3 = await _dbStore.add(_database, shop3.toMap());
print('key1 $created');
print('key2 $created2');
print('key3 $created3');
final count = await _dbStore.count(_database);
expect(count, 3);
});
test('delete_forever', () async {
final oldCount = await _dbStore.count(_database);
final dbCounter = await _dbStore.delete(_database,
finder: sembast.Finder(filter: sembast.Filter.equals('id', shop.id)));
final newCount = await _dbStore.count(_database);
print('oldCount $oldCount');
print('dbCounter $dbCounter');
print('newCount $newCount');
final oldCount2 = await _dbStore.count(_database);
final dbCounter2 = await _dbStore.delete(_database,
finder:
sembast.Finder(filter: sembast.Filter.equals('id', shop2.id)));
final newCount2 = await _dbStore.count(_database);
print('oldCount2 $oldCount2');
print('dbCounter2 $dbCounter2');
print('newCount2 $newCount2');
// expect(actual, matcher)
});
});
}
|
Hello,
I have created a database as follows
static savePreguntasDipositivo ( String questionType, Map <String, dynamic> question, Database db) async { var store = StoreRef.main (); await store.record (questionType) .put (db, question); }
My problem is that I don't know how to delete only one record that matches the String of the Map.
I know it does not have to be difficult but I have blocked myself and I do not know how to continue.
Thanks
The text was updated successfully, but these errors were encountered: