Liking cljdoc? Tell your friends :D

scriva.client

Idiomatic Clojure client for ScrivaDB.

Functions take and return plain Clojure maps; streaming RPCs (find, watch, aggregate, snapshot) return lazy seqs. Every call carries the x-api-key gRPC metadata automatically.

(require '[scriva.client :as scriva])
(let [db (scriva/connect {:host "localhost" :port 5433 :api-key "dev-key"})]
  (scriva/create-collection db "users")
  (let [id (scriva/insert db "users" {"name" "Alice" "age" 30})]
    (println (get-in (scriva/find-by-id db "users" id) [:data "name"])))
  (scriva/close db))
Idiomatic Clojure client for ScrivaDB.

Functions take and return plain Clojure maps; streaming RPCs (find, watch,
aggregate, snapshot) return lazy seqs. Every call carries the `x-api-key`
gRPC metadata automatically.

    (require '[scriva.client :as scriva])
    (let [db (scriva/connect {:host "localhost" :port 5433 :api-key "dev-key"})]
      (scriva/create-collection db "users")
      (let [id (scriva/insert db "users" {"name" "Alice" "age" 30})]
        (println (get-in (scriva/find-by-id db "users" id) [:data "name"])))
      (scriva/close db))
raw docstring

aggregateclj

(aggregate client
           collection
           &
           {:keys [aggregations field group-by filter]
            :or {aggregations [] field "" group-by ""}})

Compute count + numeric aggregations. Opts: :aggregations (seq of :count/:sum/:avg/:min/:max) :field :group-by :filter. Returns a seq of {:group :count :numeric :sum :avg :min :max}.

Compute count + numeric aggregations. Opts: :aggregations (seq of
:count/:sum/:avg/:min/:max) :field :group-by :filter. Returns a seq of
{:group :count :numeric :sum :avg :min :max}.
sourceraw docstring

begin-txclj

(begin-tx client collection)
source

closeclj

(close {:keys [channel]})

Shut the client's channel down.

Shut the client's channel down.
sourceraw docstring

commit-txclj

(commit-tx client tx-id)
source

compactclj

(compact client collection)
source

connectclj

(connect {:keys [host port api-key tls-ca-cert channel]})

Open a client. Opts: :host :port :api-key, optional :tls-ca-cert (path to a PEM CA cert; plaintext when omitted). A prebuilt :channel may be supplied instead of host/port (used by tests).

Open a client. Opts: :host :port :api-key, optional :tls-ca-cert (path to a
PEM CA cert; plaintext when omitted). A prebuilt :channel may be supplied
instead of host/port (used by tests).
sourceraw docstring

count-recordsclj

(count-records client collection & {:keys [filter]})

Count all live records, or those matching :filter.

Count all live records, or those matching :filter.
sourceraw docstring

create-collectionclj

(create-collection client name)
(create-collection client name default-ttl-seconds)
source

deleteclj

(delete client collection id)
source

delete-by-keyclj

(delete-by-key client collection key)
source

drop-collectionclj

(drop-collection client name)
source

drop-indexclj

(drop-index client collection field)
source

ensure-indexclj

(ensure-index client collection field)
source

find-by-idclj

(find-by-id client collection id & {:keys [fields]})
source

find-by-keyclj

(find-by-key client collection key & {:keys [fields]})
source

find-pageclj

(find-page client collection & {:as opts})

Fetch one keyset page (N3): {:records [...] :next-page-token "..."}.

Fetch one keyset page (N3): {:records [...] :next-page-token "..."}.
sourceraw docstring

find-recordsclj

(find-records client collection & {:as opts})

Stream matching records as a lazy seq of record maps. Opts: :filter :limit :offset :order-by (seq of {:field :desc}) :fields :page-token.

Stream matching records as a lazy seq of record maps. Opts: :filter :limit
:offset :order-by (seq of {:field :desc}) :fields :page-token.
sourceraw docstring

group-by-fieldclj

(group-by-field client collection field aggregations metric & {:keys [filter]})

Group live records by field and aggregate metric per group.

Group live records by `field` and aggregate `metric` per group.
sourceraw docstring

insertclj

(insert client
        collection
        data
        &
        {:keys [ttl-seconds key] :or {ttl-seconds 0 key ""}})

Insert one record. Opts: :ttl-seconds, :key (caller-supplied primary key).

Insert one record. Opts: :ttl-seconds, :key (caller-supplied primary key).
sourceraw docstring

insert-keyedclj

(insert-keyed client collection key data)

Keyed insert under key; throws :already-exists if taken.

Keyed insert under `key`; throws :already-exists if taken.
sourceraw docstring

insert-manyclj

(insert-many client
             collection
             records
             &
             {:keys [ttl-seconds] :or {ttl-seconds 0}})
source

list-collectionsclj

(list-collections client)
source

list-indexesclj

(list-indexes client collection)
source

rollback-txclj

(rollback-tx client tx-id)
source

snapshotclj

(snapshot client)

Lazily stream the gzip-tar snapshot archive as a seq of byte arrays.

Lazily stream the gzip-tar snapshot archive as a seq of byte arrays.
sourceraw docstring

snapshot-to-fileclj

(snapshot-to-file client path)

Stream a whole-database snapshot straight to path; returns bytes written.

Stream a whole-database snapshot straight to `path`; returns bytes written.
sourceraw docstring

statsclj

(stats client collection)
source

update-by-keyclj

(update-by-key client collection key data)
source

update-if-revclj

(update-if-rev client collection key expected-rev data)

Compare-and-swap on key, conditional on expected-rev. Returns {:swapped bool :record {...}|nil}; a stale rev (or missing key) is a no-op.

Compare-and-swap on `key`, conditional on `expected-rev`. Returns
{:swapped bool :record {...}|nil}; a stale rev (or missing key) is a no-op.
sourceraw docstring

update-recordclj

(update-record client
               collection
               id
               data
               &
               {:keys [ttl-seconds] :or {ttl-seconds 0}})
source

upsertclj

(upsert client collection key data)
source

watchclj

(watch client collection & {:keys [filter]})

Subscribe to change events on collection as a lazy seq of event maps. The seq blocks until the next event and runs until the stream ends. Opts: :filter.

Subscribe to change events on `collection` as a lazy seq of event maps.
The seq blocks until the next event and runs until the stream ends. Opts: :filter.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close