AppDBDocsOpen console

Documentation DBL guide

Built-in operations

Look up a DBL call by name, including its arguments, return type and behavior on missing or invalid input.

Text and bytes

The text, bytes and input operations use a dot. Calls in the time, uuid and auth namespaces use ::. A trailing ? in a result type means the call can return null.

CallReturnsBehavior
text.byte_length(value)UInt8UTF-8 byte count. For example, text.byte_length("é") returns 2.
bytes.length(value)UInt8Number of bytes in a Bytes value.
text.concat(left, right)TextConcatenate two text values in argument order.
text.contains(value, needle)BoolExact substring test. The empty string occurs in every string.
text.strip_prefix(value, prefix)Text?Remove the exact prefix. Returns the entire input for an empty prefix and null for a mismatch.
text.slice_bytes(value, start, end)Text?Slice from start inclusive to end exclusive. Both offsets are UInt8. Returns null for reversed ranges, out-of-bounds offsets or an offset inside a UTF-8 scalar.
text.ascii_lowercase(value)TextFold ASCII A–Z to a–z. Other characters keep their original spelling.
text.ascii_allowed(value, alphabet)BoolTrue when every byte in the value is ASCII and appears in the alphabet. The empty value passes.
text.trim_ascii(value)TextTrim spaces and ASCII whitespace bytes 0x09 through 0x0D from both ends.
text.split_once(value, separator)(Text, Text)?Return the text before and after the first literal separator. Returns null when it is absent.
text.split(value, separator)Iterator<Text>Yield fields at non-overlapping literal matches, including leading, adjacent and trailing empty fields. An empty separator splits at Unicode scalar boundaries.
text.split_ascii_whitespace(value)Iterator<Text>Yield nonempty runs separated by ASCII whitespace.
text.join(parts, separator)TextPlace the separator between elements. Accepts a text list, including bounded or readonly lists, or the remaining elements of a text iterator. Empty input yields an empty string.

For example, text.slice_bytes("café", 3, 5) yields "é". Moving the end to 4 splits its two-byte encoding and yields null. Split iterators are single-pass. Consuming one with text.join carries the scan effect. Joining a list is pure.

Numeric parsing

All parsers take a complete Text value. Whitespace, grouping separators and trailing characters make the result null. Integer widths use bytes. A leading plus sign and leading zeroes are accepted. Signed types also accept a minus sign.

CallReturnsBehavior
text.parse_int1(value)Int1?8-bit signed integer, from -128 through 127.
text.parse_int2(value)Int2?16-bit signed integer, from -32,768 through 32,767.
text.parse_int4(value)Int4?32-bit signed integer, from -2,147,483,648 through 2,147,483,647.
text.parse_int8(value)Int8?64-bit signed integer, from -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807.
text.parse_uint1(value)UInt1?8-bit unsigned integer, from 0 through 255.
text.parse_uint2(value)UInt2?16-bit unsigned integer, from 0 through 65,535.
text.parse_uint4(value)UInt4?32-bit unsigned integer, from 0 through 4,294,967,295.
text.parse_uint8(value)UInt8?64-bit unsigned integer, from 0 through 18,446,744,073,709,551,615.
text.parse_long(value)Long?Signed arbitrary-precision integer.
text.parse_ulong(value)ULong?Unsigned arbitrary-precision integer.
text.parse_float4(value)Float4?Round directly to 32-bit binary floating point.
text.parse_float8(value)Float8?Round directly to 64-bit binary floating point.
text.parse_decimal(value)Decimal?Parse an exact coefficient and a per-value scale.
text.parse_decimal(value, scale)Decimal<scale>?Convert exactly to the given scale. The scale must be a signed 32-bit integer literal and may be negative. A value requiring rounding yields null.

Floating-point and decimal inputs may include a decimal point and an e or E exponent. A written decimal point needs digits on both sides. Floats accept Infinity, +Infinity and -Infinity. NaN, numeric overflow and nonzero inputs rounded to zero yield null. text.parse_decimal("12.300", 2) yields 12.30. At the same scale, "12.301" yields null.

Lists, sets and maps

E stands for an element type, K a map key type, and V a map value type. Methods that mutate a collection require an editable receiver. Collection size bounds still apply. A local collection edit alone makes no database write.

CallReturnsBehavior
value.copy()Editable valueMake an independent editable value from a deeply readonly result. Nominal types and collection bounds are preserved.
list.lengthUInt8Element count. Read as a property.
list.get(index) or list[index]E?Read the zero-based UInt8 offset. A missing slot and a stored null both read as null.
list[index] = value()Replace an existing slot. An out-of-range index fails the invocation with ListIndexOutOfBounds.
list.append(value)()Append an element to the end.
list.sort()()Stable ascending sort using the default order on supported nonnullable scalars and tuples of nonnullable scalar fields. Tuples compare lexicographically.
list.sort(less)()Stable sort with a named pure comparator taking two elements and returning Bool. Return true when the first belongs earlier. The comparator must define a strict weak ordering and require no permissions.
set.length or map.lengthUInt8Member count for a set or entry count for a map.
set.contains(value)BoolTest membership.
set.insert(value)()Add a member. Inserting an existing member leaves the set unchanged.
set.remove(value)BoolRemove a member. True when it was present.
map.contains_key(key)BoolTest key presence, including for a key whose stored value is null.
map.get(key)V?Null for a missing key. Only allowed on maps with nonnullable values.
map.require(key)VRead the stored value, including a stored null for nullable V. A missing key fails the invocation.
map.insert(key, value)()Insert a new entry or replace the existing value for this key.
map.remove(key)BoolRemove the entry. True when its key was present.

For a Map<Text, Text?>, use map.contains_key(key) followed by map.require(key) to distinguish a missing key from a present null. See types and values for collection literals and bounds.

Input, time and UUIDs

CallReturnsBehavior
input.require(condition)()Accept a Bool. False aborts the invocation with an invalid-arguments error.
time::unix_seconds()UInt8Current Unix time in whole seconds on the writer.
uuid::v4()TextA random version-4 UUID in canonical lowercase text form.

The clock and UUID generator are nondeterministic. A transaction retry may read a later time or generate a different UUID. They cannot be used where a deterministic schema expression is required.

Table and index reads

T is a table name and idx is a declared index. A primary key with one field takes a scalar. For a compound primary key, pass a tuple in declaration order.

CallReturnsBehavior
T.get(key)Readonly<T>?Return the row visible in this transaction or null for a missing key.
T.require(key)Readonly<T>Return the row or fail the invocation if it is missing.
T.idx.is_ready()BoolTest whether the named index is ready in this transaction’s snapshot.
T.idx.scan(…)Iterator<Readonly<Tuple>>Stream tuples of the index’s declared stored fields. An empty projection yields unit for each match. Scanning requires a ready index.

All scan options are named and optional. prefix fixes leading key components. start and end constrain the following components with explicit inclusive or exclusive endpoints. direction is forward (the default) or reverse. limit caps entries using a UInt8. For full-key pagination, ordering and examples, see queries and indexes.

Table writes

Call table mutations from a write fn. Each row write must satisfy the table’s checks, unique constraints and foreign keys. A failure rolls back the entire invocation. The options and result types below apply to the committed attempt.

CallReturnsBehavior
T.insert(row)WriteResultInsert one row. An existing primary key is an error. Generated tables specialize the result as described below.
T.insertMany(rows)WriteResultInsert a list of rows in input order. A duplicate fails the batch.
T.update(key, patch)WriteResultPatch an existing row. A missing target fails.
T.updateMany(keys, patch)WriteResultProcess input keys in order. Skip missing targets and count them. Repeated keys can update the same row repeatedly.
T.delete(key)WriteResultDelete one existing row. A missing target fails.
T.deleteMany(keys)WriteResultDelete in input order. Count missing keys, including a repeated key after a prior successful delete.
T.upsert(key, branches)WriteResultLook up the primary key, then evaluate the create or update branch. Requires a table with an application-supplied primary key.
T.idx.upsert(keyTuple, branches)WriteResult or InsertResult<T>Look up the complete declared key of a ready unique index. Use a tuple even for one component. A match preserves the row’s primary key. A newly created row must emit the requested index key.

A patch is a record literal or a pure closure over the pre-update row. Omitted fields are preserved. Primary-key assignments and overlapping paths are rejected. An upsert takes a literal with create and update fields. Only the selected branch runs. See functions and transactions for working mutation examples.

Mutation results

Every write summary includes five UInt8 counts. inserted counts successful creates, matched counts updates that found a row, changed counts matched updates that changed logical values, deleted counts deletions, and missing counts skipped bulk update or delete targets. An update that writes the existing values reports one match and zero changes.

Supply the optional trailing literal returning: true to include deeply readonly records. Omitting it or using returning: false gives the default result. The checker rejects dynamic flag expressions. Write summaries are execution values and cannot be stored in table fields.

OperationDefault resultWith returning enabled
Single write, ordinary tableWriteResultWriteResult<T> adds .record. Deletes return the pre-deletion row.
Bulk write, ordinary tableWriteResultWriteResult<List<T>> adds .records in successful input order. Missing targets are omitted.
Generated-table insert or unique-index upsertInsertResult<T> adds .id and .key.InsertResult<T, T> also adds .record.
Generated-table insertManyInsertManyResult<T> adds .ids and .keys.InsertManyResult<T, List<T>> also adds .records.

On a generated table, omit the generated ID from direct creation literals. Bulk creation takes an inline list of literals. The returned key contains the full primary key, including any application-supplied components. Updates and deletes on generated tables keep their ordinary write summaries.

Identity and tokens

The declared return type AuthToken<C, R> fixes the claims record and role for an issuer. ttl, user and ceiling use UInt8. TTL is a positive duration in seconds. A ceiling is an absolute Unix timestamp in seconds.

CallReturnsBehavior
auth::subject()AuthSubjectThe effective database user, registered app user or guest for this call.
auth::claims<C>()C?Verified claims of the exact qualified record type when present.
auth::session_expires()UInt8Expiry of the verified bearer in Unix seconds. Fails without a verified bearer.
auth::issue_token(claims, ttl)AuthToken<C, R>Mint a fresh guest identity. Requires db::mint_guest_tokens.
auth::issue_token(claims, ttl, user)AuthToken<C, R>Mint for a registered user holding the exact role R. Requires db::mint_app_tokens.
auth::issue_token(claims, ttl, user, ceiling)AuthToken<C, R>Registered issuance capped at the earlier of now plus TTL and the given ceiling.
auth::grant_app_role(user, role)()Grant the qualified role name (Text) to a registered user within a write transaction. Requires db::manage_app_roles.

See identity and permissions for complete issuer functions, CLI grants and revocation, forwarding a bearer from a backend, and browser sessions.