pub trait FromSql: Sized {
// Required method
fn from_sql(value: Value) -> Result<Self, ConvertError>;
}Expand description
A trait for converting BigQuery wkt::Value representations into Rust
types.
Row::get() and
Row::try_get() use this trait to convert cell
values, and the FromRow derive macro uses it for field
deserialization.
§Supported Types
Built-in implementations include:
- Numbers:
i32,i64,f32,f64,Decimal - Text & Bytes:
String,Vec<u8>(decoded from base64),Bytes - Dates & Times:
Timestamp,Date,TimeOfDay,DateTime - Intervals:
Interval - Collections:
Option<T>(forNULL),Vec<T>(for repeated fields),Range<T>(forRANGEtypes) - Raw JSON:
Value,Struct
§Example
let mut rows = client
.query("SELECT 12345 AS integer_col, 'foo' AS string_col")
.until_done()
.await?
.read();
while let Some(row) = rows.next().await.transpose()? {
let num: i64 = row.get("integer_col");
let txt: String = row.get("string_col");
println!("{txt}: {num}");
}Required Methods§
Sourcefn from_sql(value: Value) -> Result<Self, ConvertError>
fn from_sql(value: Value) -> Result<Self, ConvertError>
Converts a BigQuery wkt::Value into the implementing type.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".