Skip to main content

with-read

Use with-read to read a row from a specified table for a given key and bind columns according to provided bindings over subsequent body statements.

Basic syntax

To read a row from a table and bind columns according to provided bindings, use the following syntax:

(with-read table key bindings)

Arguments

Use the following arguments to specify the table, key, bindings, and body for execution using the with-read Pact special form.

ArgumentTypeDescription
tabletable: <{row}>Specifies the table from which to read the row.
keystringSpecifies the key for which to read the row.
bindingsbinding: <{row}>Specifies the bindings for columns to be bound.
bodyanySpecifies the subsequent body statements to be executed.

Return value

The with-read is a special form returns the result of executing the provided body statements.

Examples

The following example demonstrates how to use the with-read function to read a row from the accounts table for the specified key and bind the balance and currency columns for further processing:

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