Sets a document to the given data or updates if it exists.
import { upset, update, get, collection } from 'typesaurus'
type User = { name: string, deleted?: boolean }
const users = collection<User>('users')
const userId = '00sHm46UWKObv2W7XK9e'
await upset(users, userId, { name: 'Sasha' })
await update(users, userId, { deleted: true })
await upset(users, userId, { name: 'Sasha Koss' })
console.log(await get(users, userId))
//=> { name: 'Sasha Koss', deleted: true }
the reference to the document to set or update
the document data
Sets a document to the given data or updates if it exists.
import { upset, update, get, collection } from 'typesaurus'
type User = { name: string, deleted?: boolean }
const users = collection<User>('users')
const userId = '00sHm46UWKObv2W7XK9e'
await upset(users, userId, { name: 'Sasha' })
await update(users, userId, { deleted: true })
await upset(users, userId, { name: 'Sasha Koss' })
console.log(await get(users, userId))
//=> { name: 'Sasha Koss', deleted: true }
the collection to set or update
the id of the document to set or update
the document data
Generated using TypeDoc
Type of the data passed to the merge function. It extends the model making field values optional and allow to set value object.