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))(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}.(close {:keys [channel]})Shut the client's channel down.
Shut the client's channel down.
(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).
(count-records client collection & {:keys [filter]})Count all live records, or those matching :filter.
Count all live records, or those matching :filter.
(create-collection client name)(create-collection client name default-ttl-seconds)(find-page client collection & {:as opts})Fetch one keyset page (N3): {:records [...] :next-page-token "..."}.
Fetch one keyset page (N3): {:records [...] :next-page-token "..."}.
(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.(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.
(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).
(insert-keyed client collection key data)Keyed insert under key; throws :already-exists if taken.
Keyed insert under `key`; throws :already-exists if taken.
(insert-many client
collection
records
&
{:keys [ttl-seconds] :or {ttl-seconds 0}})(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.
(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.
(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.(update-record client
collection
id
data
&
{:keys [ttl-seconds] :or {ttl-seconds 0}})(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.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |