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 a concurrency error. 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. Invalidating the statement still invalidates them.

# 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 an iterator over the columns nothing else consumed, as values rather than as rows.

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

Implements: std.Index[Int | Str, Value], std.Unpack[{...Value, ...Sym: Value}]

Methods

(index) key

Reads a column by position or by name.

Parameters

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

Errors

Raises an index error when no column matches, and a type error when the key is neither an Int nor a Str.

Example

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