Skip to main content
Last updated

Database

create-table

table table:<{row}>  string

Create table TABLE.

pact
(create-table accounts)
pact
(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.

pact
(describe-module 'my-module)
pact
(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.

pact
(describe-table accounts)
pact
(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.

pact
(let* ((qry (lambda (k obj) true)) ;; select all rows  (f (lambda (k obj) [(at 'firstName obj), (at 'b obj)])) ) (fold-db people (qry) (f)))
pact
(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.

pact
(insert accounts id { "balance": 0.0, "note": "Created account." })
pact
(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.

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

keys

table table:<{row}>  [string]

Return all keys in TABLE.

pact
(keys accounts)
pact
(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.

pact
(read accounts id ['balance 'ccy])
pact
(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.

pact
(select people ['firstName,'lastName] (where 'name (= "Fatima")))(select people (where 'age (> 30)))?
pact
(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.

pact
(txids accounts 123849535)
pact
(txids accounts 123849535)

txlog

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

Return all updates to TABLE performed in transaction TXID.

pact
(txlog accounts 123485945)
pact
(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.

pact
(update accounts id { "balance": (+ bal amount), "change": amount, "note": "credit" })
pact
(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.

pact
(with-default-read accounts id { "balance": 0, "ccy": "USD" } { "balance":= bal, "ccy":= ccy }  (format "Balance for {} is {} {}" [id bal ccy]))
pact
(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.

pact
(with-read accounts id { "balance":= bal, "ccy":= ccy }  (format "Balance for {} is {} {}" [id bal ccy]))
pact
(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.

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