The result of the read function.
Removes a document.
import { transaction, field, collection } from 'typesaurus'
type Counter = { count: number }
const counters = collection<Counter>('counters')
transaction(async ({ get, remove }) => {
const counter = await get('420')
if (counter === 420) await remove(counter.ref)
})
transaction(
({ get }) => get('420'),
({ data: counter, remove }) => {
console.log(counter.data.count)
return remove(counter.ref)
}
)
The collection to remove document in
The id of the documented to remove
Promise that resolves when the operation is complete.
The reference to the document to remove
Sets a document to the given data.
import { transaction, collection } from 'typesaurus'
type Counter = { count: number }
const counters = collection<Counter>('counters')
transaction(
({ get }) => get('420'),
({ data: counter, set }) =>
set(counter.ref, { count: counter.data.count + 1 })
)
the collection to set document in
the id of the document to set
the document data
Updates a document.
import { transaction, field, collection } from 'typesaurus'
type Counter = { count: number }
const counters = collection<Counter>('counters')
transaction(
({ get }) => get('420'),
({ data: counter, update }) =>
update(counter.ref, { count: counter.data.count + 1 })
//=> { __type__: 'doc', data: { count: 43 }, ... }
)
// ...or using field paths:
transaction(
({ get }) => get('420'),
({ data: counter, update }) =>
update(counter.ref, [field('count', counter.data.count + 1)])
)
the collection to update document in
the id of the document to update
the document data to update
A promise that resolves when operation is finished
the reference to the document to set
the document data to update
the collection to update document in
the id of the document to update
the document data to update
the reference to the document to set
the document data to update
Sets or updates a document with the given data.
import { transaction, collection } from 'typesaurus'
type Counter = { count: number }
const counters = collection<Counter>('counters')
transaction(
({ get }) => get('420'),
({ data: counter, upset }) =>
upset(counter.ref, { count: counter.data.count + 1 })
)
the reference to the document to set or update
the document data
the collection to set document in
the id of the document to set
the document data
Generated using TypeDoc
The transaction write API object. It unions a set of functions (set, update and remove) that are similar to regular set, update and remove with the only difference that the transaction counterparts will retry writes if the state of data received with get would change.