Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

sql.result

import sql.result

sql lifts part of this module out to its own top level; each name below is shown with the path that reaches it. Anything still spelled sql.result.* needs import sql.result.

What a statement hands back: the rows of a query, or the count of a statement that changed something.

Rows are dictionaries keyed by column name, which is what makes row.title read the way it does. Where that is not enough, because a join selected two columns of the same name or because position is what matters, columns and tuples() give the ordered view of the same result.

Classes

ResultSet

class sql.ResultSet

The rows a query returned, with the shape of the result beside them.

Iterating a result set walks its rows, so the common case needs nothing else:

for row in db.query('select id, title from posts') {
  echo '${row.id}: ${row.title}'
}
  • printable — has a @to_string(), so echo and print() show something useful
  • iterable — can be walked with for and iter

Fields

FieldTypeDescription
columnslist[dict]The result’s columns in order, each a dictionary with name and type.
rowslist[dict]The rows, each a dictionary keyed by column name.
commandThe engine’s description of what ran, such as 'SELECT 3', or nil for an engine that reports nothing.

Constructor

sql.ResultSet(columns, rows, command)

Parameters

  • columns (list) — Column descriptors.
  • rows (list) — Rows as lists of values, in column order.
  • command (string|nil) — The engine’s command tag.

ResultSet.length()

sql.ResultSet.length() -> number

How many rows the result holds.

Returns number

ResultSet.is_empty()

sql.ResultSet.is_empty() -> bool

Whether the result holds no rows at all.

Returns bool

ResultSet.first()

sql.ResultSet.first() -> dict|nil

The first row, or nil for an empty result.

Returns dict|nil

ResultSet.last()

sql.ResultSet.last() -> dict|nil

The last row, or nil for an empty result.

Returns dict|nil

ResultSet.column_names()

sql.ResultSet.column_names() -> list[string]

The names of the result’s columns, in order.

Returns list[string]

ResultSet.column()

sql.ResultSet.column(column) -> list

Every value of one column, in row order.

Parameters

  • column (string|number) — A column name, or its position.

Returns list

Raises QueryError if the result has no such column.

ResultSet.scalar()

sql.ResultSet.scalar(fallback) -> any

The first column of the first row, for a query written to return exactly one value.

var total = db.query('select count(*) from posts').scalar()

Parameters

  • fallback (any) — What to return for an empty result.

Returns any

ResultSet.tuples()

sql.ResultSet.tuples() -> list[list]

The rows as lists of values in column order, rather than as dictionaries.

This is the view that survives duplicate column names.

Returns list[list]

ResultSet.to_string()

sql.ResultSet.to_string()

ExecResult

class sql.ExecResult

What a statement that changed something reports.

  • printable — has a @to_string(), so echo and print() show something useful

Fields

FieldTypeDescription
rows_affectednumberHow many rows the statement inserted, updated or deleted.
last_insert_idThe id of the row just inserted, where the engine reports one.

Constructor

sql.ExecResult(rows_affected, last_insert_id)

Parameters

  • rows_affected (number)
  • last_insert_id (number|bigint|nil)

ExecResult.to_string()

sql.ExecResult.to_string()

2026, Richard Ore and Zuri contributors