pub trait FromSql: Sized {
// Required method
fn from_sql(value: MimerDatatype<'_>) -> Result<Self, i32>;
}Expand description
Defines translation of datatypes from Mimer SQL to Rust.
Multiple translations are possible for a single Mimer SQL type, depending on the column type. For instance, a DATE column can be translated to a chrono::NaiveDate or a String. An example of this follows below:
use chrono::NaiveDate;
let mut conn = Connection::open(db, ident, pass).unwrap();
conn.execute_statement("CREATE TABLE date_table (column1 DATE)").unwrap();
let stmnt = conn.prepare("INSERT INTO date_table (column1) VALUES(:param)", CursorMode::Forward).unwrap();
let date: NaiveDate = NaiveDate::from_ymd_opt(2024, 7, 09).unwrap();
stmnt.execute_bind(&[&date]).unwrap();
let stmnt = conn.prepare("SELECT * FROM date_table", CursorMode::Forward).unwrap();
let mut cursor = stmnt.open_cursor().unwrap();
let row = cursor.next_row().unwrap().unwrap();
let fetched_date = row.get::<chrono::NaiveDate>(1).unwrap().unwrap();
let fetched_string = row.get::<String>(1).unwrap().unwrap();
assert_eq!(fetched_string, fetched_date.to_string());Required Methods§
fn from_sql(value: MimerDatatype<'_>) -> Result<Self, i32>
Object Safety§
This trait is not object safe.