Function libsql_client::de::from_row

source ·
pub fn from_row<'de, T: Deserialize<'de>>(row: &'de Row) -> Result<T>
Expand description

Deserialize from a Row into any type T that implements serde::Deserialize.

§Types

Structs must match their field name to the column name but the order does not matter. There is a limited set of Rust types which are supported and those are:

  • String
  • Vec
  • i64
  • f64
  • Option (where T is any of the above)
  • ()

§Example

use libsql_client::de;

#[derive(Debug, serde::Deserialize)]
struct User {
    name: String,
    email: String,
    age: i64,
}

let users = db
    .execute("SELECT * FROM users")
    .await?
    .rows
    .iter()
    .map(de::from_row)
    .collect::<Result<Vec<User>, _>>()?;

println!("Users: {:?}", users);