pub struct RowBuilder { /* private fields */ }Expand description
A builder for constructing a Row outside of a query.
This is primarily intended for unit tests that exercise functions taking a
Row or &[Row] without a live database connection. Obtain one via
Row::builder.
Each column call appends a column’s metadata together with its value, so
the column count and the value count can never drift out of sync. The row is
finished with build.
§Example
use tiberius::{ColumnData, ColumnType, Row};
let row = Row::builder()
.column("id", ColumnType::Int4, ColumnData::I32(Some(1)))
.column(
"name",
ColumnType::NVarchar,
ColumnData::String(Some("Alice".into())),
)
.column("age", ColumnType::Int4, ColumnData::I32(None))
.build();
assert_eq!(Some(1), row.get::<i32, _>("id"));
assert_eq!(Some("Alice"), row.get::<&str, _>(1));
assert_eq!(None, row.get::<i32, _>("age"));Implementations§
Source§impl RowBuilder
impl RowBuilder
Sourcepub fn column(
self,
name: impl Into<String>,
column_type: ColumnType,
value: ColumnData<'static>,
) -> Self
pub fn column( self, name: impl Into<String>, column_type: ColumnType, value: ColumnData<'static>, ) -> Self
Appends a column and its value to the row being built.
name is the column name used for by-name lookups, column_type is the
ColumnType reported by Column::column_type, and value holds the
cell’s ColumnData. Columns keep the order in which they are added.
column_type is stored as-is and is not checked against value: the
value accessors (Row::get/Row::try_get) dispatch on the
ColumnData variant alone, so a mismatched column_type only affects
what Column::column_type reports. Keeping the two consistent is the
caller’s responsibility.
Sourcepub fn result_index(self, result_index: usize) -> Self
pub fn result_index(self, result_index: usize) -> Self
Sets the result-set index reported by Row::result_index.
Defaults to 0 when not called.