Mutations
Insert
Section titled “Insert”insert(values)
Section titled “insert(values)”Insert one or more rows.
// Single insertawait db.users.insert({ id: '123', name: 'John', email: 'john@example.com' });
// Batch insertawait db.users.insert([ { id: '1', name: 'Alice' }, { id: '2', name: 'Bob' }]);Update
Section titled “Update”Updates support interchangeable chaining - both patterns work:
Where First
Section titled “Where First”await db.users.where({ id: '123' }).update({ name: 'New Name' });Update First
Section titled “Update First”await db.users.update({ name: 'New Name' }).where({ id: '123' });updateMany(values)
Section titled “updateMany(values)”Update all rows matching the where clause.
await db.users.where({ status: false }).updateMany({ deleted_at: new Date().toISOString()});Single vs Many
Section titled “Single vs Many”update()- Fetches first matching row, updates byidif presentupdateMany()- Updates all matching rows directly
Delete
Section titled “Delete”Deletes also support interchangeable chaining:
With Where Object
Section titled “With Where Object”await db.users.delete({ id: '123' });Chainable
Section titled “Chainable”await db.users.where({ id: '123' }).delete();Safety: Chainable delete() requires a where clause and will fail without one.
JSON Columns
Section titled “JSON Columns”JSON columns are automatically serialized on insert/update and deserialized on read:
// Schema definition{ name: 'settings', columns: [ { name: 'id', type: 'text', primaryKey: true }, { name: 'preferences', type: 'json' } ]}
// Usage - objects are auto-serializedawait db.settings.insert({ id: '1', preferences: { theme: 'dark', notifications: true }});
// Reading - auto-deserializedconst result = await db.settings.first();console.log(result.data.preferences.theme); // 'dark'