UPDATE Examples

Simple UPDATE

Simple updates can be executed directly on the litdb driver APIs which will update all properties of a data model:

contact = new Contact({ id:1, name:'John', email:'[email protected]' }) db.update(contact)

UPDATE Specific Properties

For updating specific properties of a data model, the onlyProps option can be used:

db.update(new Contact({ id:1, email:'[email protected]' }), { onlyProps:['email'] })

UPDATE Query Builder

When more flexibility is needed you can use $.update() to create an UPDATE query builder:

db.run($.update(Contact).set({ age:41, city:'Austin' }).where($.idEquals(1))) const { age, city, email } = { age:41, email:'[email protected]' } const q = $.update(Contact) if (age) q.set({ age }) if (city) q.set({ city }) if (email) q.set({ email }) db.run(q.where($.idEquals(1)))

UPDATE Expression

When the full flexibility of SQL is needed, you can execute a SQL fragment directly:

const { id, name, age } = { id:1, name:'John', age:27 } db.run`UPDATE Contact SET name=${name}, age=${age} WHERE id=${id}`