Skip to content

Row

A single result row.

Yielded by iterating the result of Statement.query.

Row validity

A row is a window onto the statement's current step, not a copy of it, so only the most recently yielded row is valid; using an earlier one after the iterator advances raises ConcurrencyError. Reusing or closing the statement, or closing the connection, invalidates every row it yielded.

Spreading is the exception: [...stmt.query()] yields rows that own copies of their column values, so they survive the iterator advancing, though not the statement being reused or closed.

# Valid only within the body of each step
for row = stmt.query()
  echo $ str row["name"]

# Copies that outlive iteration
let all = [...stmt.query()]

Column types

A column value is converted from its SQLite type:

SQLite type Do type Notes
NULL nil
INTEGER (declared BOOLEAN) Bool Declared type must be BOOLEAN or BOOL (case-insensitive)
INTEGER Int
REAL Float
TEXT Str
BLOB Bin

Unpacking

A row unpacks by position, or by symbol naming the column. A ...rest term yields a read-only RowRest over the remaining columns. Unpacking leaves the row unchanged.

let id :name :age ...rest = row
for value = rest
  echo $ str value

Implements: Index[Int | Str, Value], Unpack[{...}, Rest: RowRest]

Methods

(index) key -> Value

Reads a column by position or by name.

Parameters

NameTypeDescription
key (Int | Str) Column position or name.

Errors

IndexError when no column matches.

Example

echo $ str row[0]
echo $ str row["name"]

(spread)() -> Spread[{...}]

Spreads the columns, by name where keys are allowed and by position otherwise.

(unpack)() -> Unpack[{...}, Rest: RowRest]

Destructures the row by position or by column name.