Skip to main content

Database

create-table

table table:<{row}>  string

Create table TABLE.

(create-table accounts)
(create-table accounts)

Top level only: this function will fail if used in module code.

describe-keyset

keyset string  object:*

Get metadata for KEYSET.

Top level only: this function will fail if used in module code.

describe-module

module string  object:*

Get metadata for MODULE. Returns an object with 'name', 'hash', 'blessed', 'code', and 'keyset' fields.

(describe-module 'my-module)
(describe-module 'my-module)

Top level only: this function will fail if used in module code.

describe-table

table table:<{row}>  object:*

Get metadata for TABLE. Returns an object with 'name', 'hash', 'blessed', 'code', and 'keyset' fields.

(describe-table accounts)
(describe-table accounts)

Top level only: this function will fail if used in module code.

fold-db

table table:<{row}> qry a:string b:object:<{row}> -> bool consumer a:string b:object:<{row}> -> <b>  [<b>]

Select rows from TABLE using QRY as a predicate with both key and value, and then accumulate results of the query in CONSUMER. Output is sorted by the ordering of keys.

(let* ((qry (lambda (k obj) true)) ;; select all rows  (f (lambda (k obj) [(at 'firstName obj), (at 'b obj)])) ) (fold-db people (qry) (f)))
(let* ((qry (lambda (k obj) true)) ;; select all rows  (f (lambda (k obj) [(at 'firstName obj), (at 'b obj)])) ) (fold-db people (qry) (f)))

insert

table table:<{row}> key string object object:<{row}>  string

Write entry in TABLE for KEY of OBJECT column data, failing if data already exists for KEY.

(insert accounts id { "balance": 0.0, "note": "Created account." })
(insert accounts id { "balance": 0.0, "note": "Created account." })

keylog

table table:<{row}> key string txid integer  [object:*]

Return updates to TABLE for a KEY in transactions at or after TXID, in a list of objects indexed by txid.

(keylog accounts "Alice" 123485945)
(keylog accounts "Alice" 123485945)

keys

table table:<{row}>  [string]

Return all keys in TABLE.

(keys accounts)
(keys accounts)

read

table table:<{row}> key string  object:<{row}>

table table:<{row}> key string columns [string]  object:<{row}>

Read row from TABLE for KEY, returning database record object, or just COLUMNS if specified.

(read accounts id ['balance 'ccy])
(read accounts id ['balance 'ccy])

select

table table:<{row}> where row:object:<{row}> -> bool  [object:<{row}>]

table table:<{row}> columns [string] where row:object:<{row}> -> bool  [object:<{row}>]

Select full rows or COLUMNS from table by applying WHERE to each row to get a boolean determining inclusion.

(select people ['firstName,'lastName] (where 'name (= "Fatima")))(select people (where 'age (> 30)))?
(select people ['firstName,'lastName] (where 'name (= "Fatima")))(select people (where 'age (> 30)))?

txids

table table:<{row}> txid integer  [integer]

Return all txid values greater than or equal to TXID in TABLE.

(txids accounts 123849535)
(txids accounts 123849535)

txlog

table table:<{row}> txid integer  [object:*]

Return all updates to TABLE performed in transaction TXID.

(txlog accounts 123485945)
(txlog accounts 123485945)

update

table table:<{row}> key string object object:~<{row}>  string

Write entry in TABLE for KEY of OBJECT column data, failing if data does not exist for KEY.

(update accounts id { "balance": (+ bal amount), "change": amount, "note": "credit" })
(update accounts id { "balance": (+ bal amount), "change": amount, "note": "credit" })

with-default-read

table table:<{row}> key string defaults object:~<{row}> bindings binding:~<{row}>  <a>

Special form to read row from TABLE for KEY and bind columns per BINDINGS over subsequent body statements. If row not found, read columns from DEFAULTS, an object with matching key names.

(with-default-read accounts id { "balance": 0, "ccy": "USD" } { "balance":= bal, "ccy":= ccy }  (format "Balance for {} is {} {}" [id bal ccy]))
(with-default-read accounts id { "balance": 0, "ccy": "USD" } { "balance":= bal, "ccy":= ccy }  (format "Balance for {} is {} {}" [id bal ccy]))

with-read

table table:<{row}> key string bindings binding:<{row}>  <a>

Special form to read row from TABLE for KEY and bind columns per BINDINGS over subsequent body statements.

(with-read accounts id { "balance":= bal, "ccy":= ccy }  (format "Balance for {} is {} {}" [id bal ccy]))
(with-read accounts id { "balance":= bal, "ccy":= ccy }  (format "Balance for {} is {} {}" [id bal ccy]))

write

table table:<{row}> key string object object:<{row}>  string

Write entry in TABLE for KEY of OBJECT column data.

(write accounts id { "balance": 100.0 })
(write accounts id { "balance": 100.0 })

Receive important developer updates