Types
One column value in a SQL row, in the driver's own type space.
PgArray is an internal marker std.sql.pg_array returns; it stays an ordinary variant so the value survives query construction on every backend.
use std.sql
use std.sql.SqlValue
fn main() {
let query = sql
.select("videos", ["id", "title"])
.where(sql.and([
sql.gte("year", SqlValue.Int(2020)),
sql.ilike("title", SqlValue.Text("%moon%")),
]))
.order_by("year", "desc", "last")
.limit(20)
.offset(0)
let insert = sql
.insert_into("videos", ["title", "year"])
.values([SqlValue.Text("moon"), SqlValue.Int(2026)])
.returning(["id"])
.on_conflict_do_nothing(["title"])
println([query, insert].len())
println(sql.pg_array([SqlValue.Int(1), SqlValue.Int(2)]))
}PostgreSQL result-column metadata.
name: string | |
|---|---|
type_oid: int | |
type_name: string |
A bounded PostgreSQL NoticeResponse captured during an operation.
severity: string | |
|---|---|
code: string | |
message: string |
A PostgreSQL LISTEN/NOTIFY message captured during an operation.
pid: int | |
|---|---|
channel: string | |
payload: string |
Opt-in redacted SQL driver and pool counters.
operations: int | |
|---|---|
failures: int | |
rows: int | |
duration_ms: int | |
pool_waits: int | |
pool_wait_ms: int | |
pool_timeouts: int | |
connections: int | |
in_use: int |
A redacted SQL operation trace; SQL text and parameter values are never retained.
operation: string | |
|---|---|
duration_ms: int | |
rows: int | |
failed: bool |
Bounded PostgreSQL pool configuration.
use std.sql
use std.sql.SqlPoolOptions
use std.sql.SqlValue
async fn main() {
let pool = (await sql.pool(
"postgres://moon@127.0.0.1/app",
SqlPoolOptions {
min_connections: 1,
max_connections: 8,
acquire_timeout_ms: 2_000,
connect_timeout_ms: 2_000,
idle_timeout_ms: 30_000,
max_lifetime_ms: 300_000,
validation_interval_ms: 10_000,
prepared_cache_size: 32,
},
)).unwrap()
let result = (await pool.execute(
sql.raw("select $1::text as name", [SqlValue.Text("moon")]),
)).unwrap()
println(result.rows[0].require_text("name"))
println(pool.metrics().operations)
(await pool.close()).unwrap()
}min_connections: int | |
|---|---|
max_connections: int | |
acquire_timeout_ms: int | |
connect_timeout_ms: int | |
idle_timeout_ms: int | |
max_lifetime_ms: int | |
validation_interval_ms: int | |
prepared_cache_size: int |
PostgreSQL transaction mode.
isolation: string | |
|---|---|
read_only: bool | |
deferrable: bool |
An exclusive PostgreSQL connection handle.
An opaque handle: only std.sql can produce one, and its contents are not reachable from moon source.
use std.sql
use std.sql.SqlConnection
use std.sql.SqlTransactionOptions
use std.sql.SqlValue
async fn inspect(connection: SqlConnection) -> Result<int, Error> {
let rows = await connection.query(
sql.raw("select id, name from videos", []),
)?
let mut reading = true
while reading {
match await rows.next()? {
some(row) => println(row.require_text("name")?),
none => { reading = false },
}
}
await rows.close()?
let transaction = await connection.begin(
SqlTransactionOptions {
isolation: "serializable",
read_only: false,
deferrable: false,
},
)?
await transaction.execute(sql.raw("select $1", [SqlValue.Int(1)]))?
await transaction.commit()?
ok(0)
}
fn main() {}_handle: NativeHandle | The native resource. |
|---|
A bounded FIFO PostgreSQL connection pool.
An opaque handle: only std.sql can produce one, and its contents are not reachable from moon source.
_handle: NativeHandle | The native resource. |
|---|
A single-pass SQL row stream.
An opaque handle: only std.sql can produce one, and its contents are not reachable from moon source.
_handle: NativeHandle | The native resource. |
|---|
A transaction owning one physical connection.
An opaque handle: only std.sql can produce one, and its contents are not reachable from moon source.
_handle: NativeHandle | The native resource. |
|---|
A prepared-statement handle.
An opaque handle: only std.sql can produce one, and its contents are not reachable from moon source.
_handle: NativeHandle | The native resource. |
|---|
An immutable parameterized SQL query.
An opaque handle: only std.sql can produce one, and its contents are not reachable from moon source.
_handle: NativeHandle | The native resource. |
|---|
An immutable parameterized SQL expression.
An opaque handle: only std.sql can produce one, and its contents are not reachable from moon source.
_handle: NativeHandle | The native resource. |
|---|
A PostgreSQL COPY FROM STDIN stream.
An opaque handle: only std.sql can produce one, and its contents are not reachable from moon source.
_handle: NativeHandle | The native resource. |
|---|
A PostgreSQL COPY TO STDOUT stream.
An opaque handle: only std.sql can produce one, and its contents are not reachable from moon source.
_handle: NativeHandle | The native resource. |
|---|
Type-level capability accepted by ORM operations; runtime values are a SQL connection, pool, or transaction.
Deliberately field-less: a type-level capability, never a runtime value of its own — an executor argument is always one of the three wrappers above.
Exact decimal text wrapper used by explicit SQL/ORM codecs.
value: string |
|---|
Canonical UUID text wrapper used by explicit SQL/ORM codecs.
value: string |
|---|
A registered SQL column map from sql.codec<T>.
_type: string | The runtime name of the type the codec was declared for. |
|---|