import { AtomicBuilder } from "https://deno.land/x/kvdex@v0.3.2/mod.ts";
Builder object for creating and executing atomic operations in the KV store.
Handles a single collection context at a time, with the option of selecting a new collection context during build.
Constructors
Properties
private
collection: Collection<TValue>private
kv: Deno.Kvprivate
operations: Operationsprivate
schema: TSchemaMethods
Add a new document to the KV store with a randomely generated id.
Example:
db
.atomic(schema => schema.users)
.add({
username: "user1",
age: 32
})
check(...atomicChecks: AtomicCheck<TValue>[])
Check if documents have been changed since a specific versionstamp.
Example:
db
.atomic(schema => schema.users)
.check({
id: "user1",
versionstamp: null // Check that document does not already exist
})
commit(): Promise<Deno.KvCommitResult | Deno.KvCommitError>
Executes the built atomic operation. Will always fail if trying to delete and add/set to the same indexable collection in the same operation.
Deletes a document from the KV store with the given id.
Example:
db
.atomic(schema => schema.users)
.delete("user1")
mutate(...mutations: AtomicMutation<TValue>[])
Specifies atomic mutations to be formed on documents.
Example:
db
.atomic(schema => schema.u64s)
.mutate(
{
type: "delete",
id: "num1"
},
{
type: "set",
id: "num2",
value: new Deno.KvU64(200n)
}
)
select<TValue extends KvValue>(selector: CollectionSelector<TSchema, TValue>)
Select a new collection context.
Example:
operation.select(schema => schema.users)
Adds a new document to the KV store with the given id.
Example:
db
.atomic(schema => schema.users)
.set("user1", {
username: "user1",
age: 32
})