Skip to main content

FromSql

Trait FromSql 

Source
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:

§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§

Source

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".

Implementations on Foreign Types§

Source§

impl FromSql for Bytes

Source§

impl FromSql for Date

Source§

impl FromSql for DateTime

Source§

impl FromSql for Decimal

Source§

impl FromSql for Decimal

Source§

impl FromSql for String

Source§

impl FromSql for Struct

Source§

impl FromSql for TimeOfDay

Source§

impl FromSql for Timestamp

Source§

impl FromSql for Value

Source§

impl FromSql for Vec<u8>

Source§

impl FromSql for bool

Source§

impl FromSql for f32

Source§

impl FromSql for f64

Source§

impl FromSql for i32

Source§

impl FromSql for i64

Source§

impl<T: FromSql> FromSql for Option<T>

Source§

impl<T: FromSql> FromSql for Vec<T>

Implementors§