Documentation
¶
Overview ¶
Package sqlrow turns the result of a SQL statement into action outputs for Orchard's database providers.
The database/sql providers (sqlite, mysql) share Query, which gives every SQL action the same output shape: the first returned row, or last_insert_id and rows_affected for a statement that returns no rows. ToCty is shared with the postgres provider, which uses pgx directly.
Index ¶
- func Arg(v cty.Value) (any, error)
- func ColumnValue(v any, dbType string) cty.Value
- func Params(attrs map[string]cty.Value, arg func(cty.Value) (any, error)) ([]any, error)
- func Query(ctx context.Context, conn *sql.Conn, query, statusQuery string, args ...any) (map[string]cty.Value, error)
- func ToCty(v any) cty.Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Arg ¶
Arg converts one parameter: null as NULL, strings and bools as themselves, whole numbers as int64 and other numbers as exact decimal text, and lists and objects as JSON text.
func ColumnValue ¶
ColumnValue converts one scanned value. Some drivers return numbers as text: MySQL's text protocol (queries without bind parameters) as []byte, and pgx's database/sql adapter returns NUMERIC as a string. Those are decoded by the column's declared type; everything else goes through ToCty.
func Params ¶
Params returns a query action's params attribute as driver arguments, converting each with arg. No params, null or an empty list returns nil, so the query runs as it would without them.
func Query ¶
func Query(ctx context.Context, conn *sql.Conn, query, statusQuery string, args ...any) (map[string]cty.Value, error)
Query runs query on conn, with args bound to its placeholders, and returns its outputs:
- If the statement returns columns (a SELECT, or a write with RETURNING), the first row keyed by column name. No rows → empty.
- Otherwise (a plain INSERT, UPDATE, DELETE or DDL), the last_insert_id and rows_affected that statusQuery reports. It runs on the same connection straight after the statement, and must select those two values as integers, in that order.
Only the first row is read. Callers' databases must apply a statement's writes before its first row is returned, which SQLite and MySQL both do.
func ToCty ¶
ToCty converts a Go value from a database driver into a cty.Value for the engine's eval context. Drivers return their native types (strings, sized ints, floats, bool, []byte, time.Time, nil); those map directly, times become RFC 3339 strings in UTC, and anything else falls back to its string form.
This is deliberately permissive rather than strict: a best-effort string conversion is a better failure mode during scenario development than a hard error on an unhandled type. Columns the scenario actually references surface decoding issues at expression-evaluation time, which is a more actionable place to see them.
Types ¶
This section is empty.