Starts the execution of the operations in the batch.
A promise that resolves when the operations are finished
Removes a document.
import { batch, collection } from 'typesaurus'
type Counter = { count: number }
const counters = collection<Counter>('counters')
const { remove, commit } = batch()
for (let count = 0; count < 500; count++) {
remove(counters, count.toString())
}
commit()
The collection to remove document in
The id of the documented to remove
A promise that resolves when the operation is complete
The reference to the document to remove
Sets a document to the given data.
import { batch, collection } from 'typesaurus'
type Counter = { count: number }
const counters = collection<Counter>('counters')
const { set, commit } = batch()
for (let count = 0; count < 500; count++) {
set(counters, count.toString(), { count })
}
commit()
The collection to set document in
The id of the document to set
The document data
Updates a document.
import { batch, field, collection } from 'typesaurus'
type Counter = { count: number, meta: { updatedAt: number } }
const counters = collection<Counter>('counters')
const { update, commit } = batch()
for (let count = 0; count < 500; count++) {
update(counters, count.toString(), { count: count + 1 })
// or using field paths:
update(counters, count.toString(), [
field('count', count + 1),
field(['meta', 'updatedAt'], Date.now())
])
}
commit()
The collection to update document in
The id of the document to update
The document data to update
void
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 { batch, collection } from 'typesaurus'
type Counter = { count: number }
const counters = collection<Counter>('counters')
const { upset, commit } = batch()
for (let count = 0; count < 500; count++) {
upset(counters, count.toString(), { count })
}
commit()
The reference to the document to set or update
The document data
The collection to set or update document in
The id of the document to set or update
The document data
Generated using TypeDoc
The batch API object. It unions a set of functions (set, update, remove) that are similar to regular set, update and remove with the only difference that the batch counterparts do not return a promise and perform operations only when commit function is called.