Liking cljdoc? Tell your friends :D

ebifriedrice.rsqlite

Reactive SQLite: register queries, receive recomputed results.

(def eng  (rsql/connect))                     ; in-memory
(def eng  (rsql/connect "file:app.db"))      ; or a file
(rsql/exec! eng "create table person (id integer primary key, name text, age int)")
(def adults (rsql/q! eng "select id, name from person where age >= ?" 18))
@adults
(rsql/exec! eng "insert into person values (1, 'Ann', 33)")
@adults                                     ; recomputed

Result atoms are plain Clojure atoms: deref reads, watch reacts, Reagent re-renders for free on both platforms. Writes go through the engine (exec!/transact!) - the posh contract; the preupdate hook feeds invalidation, recomputation runs off the writing thread, and only genuinely changed results are delivered.

The engine namespace documents the semantics (scheduling, DDL, rollback); this is the sugar layer over it, malli-specified. On the JVM the backend is the bundled org.sqlite.jni binding; on ClojureScript (later in the series) connect takes the consumer's initialized @sqlite.org/sqlite-wasm module.

Reactive SQLite: register queries, receive recomputed results.

    (def eng  (rsql/connect))                     ; in-memory
    (def eng  (rsql/connect "file:app.db"))      ; or a file
    (rsql/exec! eng "create table person (id integer primary key, name text, age int)")
    (def adults (rsql/q! eng "select id, name from person where age >= ?" 18))
    @adults
    (rsql/exec! eng "insert into person values (1, 'Ann', 33)")
    @adults                                     ; recomputed

Result atoms are plain Clojure atoms: deref reads, watch reacts,
Reagent re-renders for free on both platforms. Writes go through
the engine (exec!/transact!) - the posh contract; the preupdate
hook feeds invalidation, recomputation runs off the writing
thread, and only genuinely changed results are delivered.

The engine namespace documents the semantics (scheduling, DDL,
rollback); this is the sugar layer over it, malli-specified. On
the JVM the backend is the bundled org.sqlite.jni binding; on
ClojureScript (later in the series) connect takes the consumer's
initialized @sqlite.org/sqlite-wasm module.
raw docstring

close!clj/s

(close! eng)

Close the connection; the engine is unusable afterwards.

Close the connection; the engine is unusable afterwards.
sourceraw docstring

connectclj/s

(connect)
(connect uri-or-opts)
source

engine-schemaclj/s

source

exec!clj/s

(exec! eng sql & params)

Run one write statement; trailing arguments bind positionally. Recomputation of affected queries is scheduled off this thread - sync! forces it.

Run one write statement; trailing arguments bind positionally.
Recomputation of affected queries is scheduled off this thread -
sync! forces it.
sourceraw docstring

q!clj/s

(q! eng sql & params)

Register a query and run it once; returns its result atom. Params are the trailing arguments, one per ? in the sql.

Register a query and run it once; returns its result atom. Params
are the trailing arguments, one per ? in the sql.
sourceraw docstring

result-schemaclj/s

source

sync!clj/s

(sync! eng)

Flush pending recomputes synchronously - deterministic reads for tests.

Flush pending recomputes synchronously - deterministic reads for
tests.
sourceraw docstring

transact!clj/s

(transact! eng stmts)

Run [sql & params] vectors (or bare sql strings) as one transaction; recompute scheduled once after COMMIT.

Run [sql & params] vectors (or bare sql strings) as one
transaction; recompute scheduled once after COMMIT.
sourceraw docstring

unq!clj/s

(unq! eng result)

Retire a registered query's result atom.

Retire a registered query's result atom.
sourceraw docstring

uri-schemaclj/s

source

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