pub trait FromSql: Sized {
// Required method
fn from_value(value: SqlValue) -> Result<Self, ConvertError>;
}Expand description
A trait for converting BigQuery value representations into Rust types.
The BigQuery client uses wkt::Value by default, but will support
Arrow record batches via the Storage Read API integration in the future.
Do not implement this trait directly.
This trait is not intended for manual implementation. New methods (such as
Arrow conversion methods) may be added in future versions, which would break
manual implementations. To deserialize custom structs, use #[derive(FromSql)]
or #[derive(FromRow)] instead.
Row::get() or Row::take()
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_value(value: SqlValue) -> Result<Self, ConvertError>
fn from_value(value: SqlValue) -> Result<Self, ConvertError>
Converts a BigQuery SqlValue into the implementing type.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".