TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/launchbadge/sqlx/llms.txt
Use this file to discover all available pages before exploring further.
Row trait is the primary interface for reading data out of a query result. Every database driver returns its own concrete row type (PgRow, MySqlRow, SqliteRow, AnyRow), but they all implement the same Row trait so application code can stay generic. Columns within a row are accessed either by position (usize) or by name (&str) through the ColumnIndex trait.
Row trait
The Row trait provides methods for decoding column values and inspecting row structure.
Value access
get::<T, I>(index) → T
get::<T, I>(index) → T
Decodes the value at Use this when you are certain the column exists and the type is correct. For fallible access, prefer
index into type T. Panics if the column does not exist or if the value cannot be decoded into T.try_get.try_get::<T, I>(index) → Result<T, Error>
try_get::<T, I>(index) → Result<T, Error>
Decodes the value at Unlike
index into type T, returning an Error instead of panicking on failure.get, try_get does not perform a compile-time type compatibility check; it attempts the decode unconditionally and surfaces mismatches as errors at runtime.get_unchecked::<T, I>(index) → T
get_unchecked::<T, I>(index) → T
Like
get, but skips the database-type compatibility check and blindly attempts to decode the raw value. Panics on decode failure. Prefer get unless you have a specific reason to bypass the check.try_get_unchecked::<T, I>(index) → Result<T, Error>
try_get_unchecked::<T, I>(index) → Result<T, Error>
Like
try_get, but skips the compatibility check. Returns an error on decode failure rather than panicking.Column introspection
| Method | Return type | Description |
|---|---|---|
columns() | &[DB::Column] | Returns a slice of all columns in the row. |
column(index) | &DB::Column | Returns the column at index. Panics if out of bounds. |
try_column(index) | Result<&DB::Column, Error> | Returns the column at index or a ColumnIndexOutOfBounds error. |
len() | usize | Returns the number of columns in the row. |
is_empty() | bool | Returns true if the row has no columns. |
Handling NULL values
SQLNULL maps to Rust’s Option<T>. Use Option<T> as the type parameter in get or try_get to handle nullable columns without an error.
ColumnIndex trait
The ColumnIndex trait is implemented by both usize (positional access) and &str (name-based access), giving you two ways to index into a row.
Name-based indexing performs a linear scan over the column list. For performance-critical hot paths with many columns, positional access by
usize is faster.Column trait
Every database driver’s column type implements the Column trait, which exposes metadata about a single column returned by a query.
| Method | Return type | Description |
|---|---|---|
name() | &str | The column name or alias. Unreliable for unaliased expressions. |
ordinal() | usize | Zero-based position of the column in the row. |
type_info() | &DB::TypeInfo | Database-level type information for the column. |
origin() | ColumnOrigin | Source table and original column name, if known. |
ColumnOrigin has three variants:
ColumnOrigin::Table(TableColumn)— the column comes from a known table; includestableandnamefields.ColumnOrigin::Expression— the column is computed from an expression or origin could not be determined.ColumnOrigin::Unknown— the driver does not provide origin information (the default).
Database row types
Each database driver provides a concrete row type that implementsRow.
PgRow
Returned by PostgreSQL queries. Requires the
postgres feature.MySqlRow
Returned by MySQL/MariaDB queries. Requires the
mysql feature.SqliteRow
Returned by SQLite queries. Requires the
sqlite or sqlite-unbundled feature.AnyRow
A type-erased row that works with any driver at runtime. Requires the
any feature. Not all TypeInfo detail is available.