Skip to main content
Module

x/kvdex/mod.ts>AtomicBuilder

High-level abstraction layer for Deno KV 🦕📁
Go to Latest
class AtomicBuilder
import { AtomicBuilder } from "https://deno.land/x/kvdex@v0.19.4/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

new
AtomicBuilder(
kv: Deno.Kv,
schema: T1,
operations?: Operations,
)

Create a new AtomicBuilder for building and executing atomic operations in the KV store.

Type Parameters

T2 extends KvValue
T3 extends T2

Properties

private
collection: Collection<T2, T3, CollectionOptions<T2>>
private
kv: Deno.Kv
private
operations: Operations
private
schema: T1

Methods

add(value: T3, options?: AtomicSetOptions)

Add a new document to the KV store with a randomely generated id.

check(...atomicChecks: AtomicCheck<T2>[])

Check if documents have been changed since a specific versionstamp.

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.

Add data to the collection queue to be delivered to the queue listener via db.collection.listenQueue(). The data will only be received by queue listeners on the specified collection and topic. The method takes an optional options argument that can be used to set a delivery delay and topic.

max(id: KvId, value: T2 extends Deno.KvU64 ? bigint : never)

Sets the document value to the maximum of the existing and the given value.

max only works for documents of type Deno.KvU64 and will throw an error for documents of any other type.

min(id: KvId, value: T2 extends Deno.KvU64 ? bigint : never)

Sets the document value to the minimum of the existing and the given value.

min only works for documents of type Deno.KvU64 and will throw an error for documents of any other type.

mutate(...mutations: AtomicMutation<T2>[])

Specifies atomic mutations to be formed on documents.

select<TValue extends KvValue>(selector: CollectionSelector<T1, TValue>)

Select a new collection context.

set(
id: KvId | null,
value: T3,
options?: AtomicSetOptions,
)

Adds a new document to the KV store with the given id.

sum(id: KvId, value: T2 extends Deno.KvU64 ? bigint : never)

Adds the given value to the value of the document with the given id. Sum only works for documents of type Deno.KvU64 and will throw an error for documents of any other type.