-
-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Use case:
If we assume a JSDB table initialized as
db.cars = [
{ make: "Mazda", model: "Miato", color: "red", year: 1992 },
{ make: "GMC", model:" Timmy", color: "black", year: 1987 },
{ make: "Ford", model: "F5", color": blue", year: 1987 }
]
I would like to be able to update data in the table, either by querying for row index/indices, like
let editRowIndex = db.cars.where('model').is('Miato').getFirstIndex()
// editRowIndex now equals 0
let manyRowIndices = db.cars.where('year').is(1987).getIndices()
// manyRowIndices now equals [1, 2]
or by having access to an update method, like
let result = db.cars.where('model').is('F5').getFirst().update({ model: 'F150' });
// result is true if data was successfully persisted after merging updated fields into db.cars[2]
let multiresult = db.cars.where('year').isLessThan(2000).get().update({ needsSmogTest: true });
// multiresult is true if all matching rows were successfully persisted
As an alternative to the second version, I'd be fine with having the update(newData) method hanging off the query pre-get (so, db.cars.where('model').is('F5').updateFirst(newData) and the like.
Thoughts?
Metadata
Metadata
Assignees
Labels
No labels