Trait mimerrust::types::FromSql

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

source

fn from_sql(value: MimerDatatype<'_>) -> Result<Self, i32>

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl FromSql for (f32, f32)

source§

fn from_sql(value: MimerDatatype<'_>) -> Result<Self, i32>

source§

impl FromSql for bool

source§

fn from_sql(value: MimerDatatype<'_>) -> Result<Self, i32>

source§

impl FromSql for f32

source§

fn from_sql(value: MimerDatatype<'_>) -> Result<Self, i32>

source§

impl FromSql for f64

source§

fn from_sql(value: MimerDatatype<'_>) -> Result<Self, i32>

source§

impl FromSql for i32

source§

fn from_sql(value: MimerDatatype<'_>) -> Result<Self, i32>

source§

impl FromSql for i64

source§

fn from_sql(value: MimerDatatype<'_>) -> Result<Self, i32>

source§

impl FromSql for String

source§

fn from_sql(value: MimerDatatype<'_>) -> Result<Self, i32>

source§

impl FromSql for Vec<u8>

source§

fn from_sql(value: MimerDatatype<'_>) -> Result<Self, i32>

source§

impl FromSql for NaiveDate

source§

fn from_sql(value: MimerDatatype<'_>) -> Result<Self, i32>

source§

impl FromSql for NaiveDateTime

source§

fn from_sql(value: MimerDatatype<'_>) -> Result<Self, i32>

source§

impl FromSql for NaiveTime

source§

fn from_sql(value: MimerDatatype<'_>) -> Result<Self, i32>

source§

impl FromSql for Uuid

source§

fn from_sql(value: MimerDatatype<'_>) -> Result<Self, i32>

source§

impl FromSql for Point<i32>

source§

fn from_sql(value: MimerDatatype<'_>) -> Result<Self, i32>

Implementors§