Comments (8)
It is not possible at the moment. But it could be implemented efficiently in a transaction (using a transaction is the key to make it fast, especially when the changes are commited) by finding records and updating them 1 by one.
The API does not support 'patching' a record neither to update a single field.
Let's keep this issue open as I think they both deserve solution that I need to think about. Thanks!
from sembast.dart.
If update is not available... how to update fields (even in a transaction) ?
Do I need to make a get -> to get the record, delete it, and ad it again ?
from sembast.dart.
As i said you cannot update a single field (I'm currently looking at that). You can update the whole record however using:
put({'macAddress': '00:11:22:33:44:55'}, key)
To update a single field for now, the solution is:
await db.transaction((txn) async {
// read
record = await txn.getRecord(key);
// update one field
record['macAddress'] = '00:11:22:33:44:55';
// write
await txn.putRecord(record);
});
from sembast.dart.
I have publish 1.10.0 that allows updating only some fields of a record, similarly to firestore.set. Some documentation here: https://github.com/tekartik/sembast.dart/blob/master/doc/writes.md#updating-fields
store.update({'macAddress': '00:11:22:33:44:55}, key);
Bulk update is not supported yet. You still have to query first (you can query keys only) then update each record one by one (which is very fast in a transaction)
from sembast.dart.
Using 1.10.0
I have made some tests to update a record field :
This code is working:
await store.update({'flushed': true}, 89);
This code is working:
await _db.transaction((txn) async {
var store = txn.getStore('beacons');
store.update({'flushed': true}, 148);
});
When I try to loop over multiple records it does not work:
await _db.transaction((txn) async {
var store=txn.getStore('beacons');
List<Future> futures = List();
recordsIds.forEach((key) => futures.add(store.update({'flushed': true}, key)));
await Future.wait(futures);
});
I get this error in the logs:
flutter: FINE: 2018-11-06 23:56:53.030405: txn 2 get null key 9
flutter: FINE: 2018-11-06 23:56:53.031026: txn 2 get null key 10
flutter: FINE: 2018-11-06 23:56:53.032141: txn 2 get null key 11
flutter: FINE: 2018-11-06 23:56:53.032805: txn 2 get null key 12
flutter: FINE: 2018-11-06 23:56:53.033639: txn 2 get null key 13
How to update multiple records in a transaction coming from a list of keys ?
from sembast.dart.
Thanks for the report. I could not reproduce the issue. I tried it here and it worked as expected:
sembast.dart/test/exp_test.dart
Lines 55 to 70 in 3ab915d
Do you have a unit test that you could easily extract?
from sembast.dart.
Sorry, it was an issue on my side.. I was using a key of type int for storing and requesting with a key of type String ...
It works now !!
from sembast.dart.
I added in 1.10.1 the utility function updateRecords
although it is only a few lines of code. See https://github.com/tekartik/sembast.dart/blob/master/doc/writes.md#bulk-update
from sembast.dart.
Related Issues (20)
- Consider adding async "Codec" for encryption HOT 2
- import dadabase HOT 8
- Filter.equals('clients.0.uid', uidClient)) does not work HOT 2
- Ordering by property of nested array object HOT 2
- Serialising object works fine, deserialising fails HOT 2
- How do I chain/make compound filters? HOT 3
- Issue using Sembast in Background Notification - Android HOT 6
- Deleted row in the .db file HOT 7
- Using sync to fetch data HOT 3
- Any database viewer is available to view the sembast db file HOT 1
- Export JsonEncodableCodec type HOT 4
- Copy db file on flutter web for upload / backup HOT 2
- Need a way to reload the database / detect that it was changed by an external process. HOT 4
- Error in mobile web browser HOT 2
- Sembast web limitation HOT 2
- how to rename a store? HOT 2
- Pagination not working HOT 2
- Store record with custom key HOT 1
- Ambiguity around null record value HOT 3
- null check on null value HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sembast.dart.