Skip to content

Mutations

Insert one or more rows.

// Single insert
await db.users.insert({ id: '123', name: 'John', email: 'john@example.com' });
// Batch insert
await db.users.insert([
{ id: '1', name: 'Alice' },
{ id: '2', name: 'Bob' }
]);

Updates support interchangeable chaining - both patterns work:

await db.users.where({ id: '123' }).update({ name: 'New Name' });
await db.users.update({ name: 'New Name' }).where({ id: '123' });

Update all rows matching the where clause.

await db.users.where({ status: false }).updateMany({
deleted_at: new Date().toISOString()
});
  • update() - Fetches first matching row, updates by id if present
  • updateMany() - Updates all matching rows directly

Deletes also support interchangeable chaining:

await db.users.delete({ id: '123' });
await db.users.where({ id: '123' }).delete();

Safety: Chainable delete() requires a where clause and will fail without one.

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-serialized
await db.settings.insert({
id: '1',
preferences: { theme: 'dark', notifications: true }
});
// Reading - auto-deserialized
const result = await db.settings.first();
console.log(result.data.preferences.theme); // 'dark'