Trait mimerrust::types::ToSql

source ·
pub trait ToSql {
    // Required method
    fn to_sql(&self) -> MimerDatatype<'_>;
}
Expand description

Defines translation of datatypes from Rust to Mimer SQL.

The following table shows the datatype mappings from Rust to Mimer SQL implemented in this crate. Note that it is possible for a Rust type to be mapped to multiple Mimer SQL types. What type is used then depends on the column type.

Rust typeMimer SQL type
Option<T> where T: ToSqlNULL if None, otherwise the appropriate conversion for the type T and column
i32INTEGER, BIGINT or SMALLINT
i64INTEGER, BIGINT or SMALLINT
StringString datatypes1, CHARACTER LARGE OBJECT and NATIONAL CHARACTER LARGE OBJECT
f32REAL, DOUBLE PRECISION, BINARY(4)2
(f32,f32)BINARY(8)3
f64REAL and DOUBLE PRECISION
boolBOOLEAN
Vec<u8>/[u8; N]BINARY, BINARY VARYING, BINARY LARGE OBJECT

The ToSql trait is also implemented for a number of types from external crates, among which are uuid::Uuid and various types from the chrono crate.

Rust typeMimer SQL type
uuid::Uuid4BINARY, BINARY VARYING, BINARY LARGE OBJECT
chrono::NaiveDateDATE
chrono::NaiveTimeTIME
chrono::NaiveDateTimeTIMESTAMP
[geo::Point<i32>]BINARY

  1. String datatypes include CHARACTER, CHARACTER VARYING, NATIONAL CHARACTER, NATIONAL CHARACTER VARYING, DATE, TIME, TIMESTAMP, DECIMAL and NUMERIC

  2. Converts into an 4 byte binary sequence if column type is BUILTIN.GIS_LATITUDE or BUILTIN.GIS_LONGITUDE. Note that values of type BUILTIN.GIS_LATITUDE must be within the interval [-90,90], and values of type BUILTIN.GIS_LONGITUDE within [-180,180]. 

  3. Converts into an 8 byte binary sequence, where each f32 makes up 4 bytes. Mainly intended for BUILTIN.GIS_LOCATION. The location latitude and longitude must be within the interval [-90,90] and [-180,180] respectively. 

  4. Converts into a 16 byte binary sequence. Mainly intended for BUILTIN.UUID

Required Methods§

source

fn to_sql(&self) -> MimerDatatype<'_>

Implementations on Foreign Types§

source§

impl ToSql for &str

source§

fn to_sql(&self) -> MimerDatatype<'_>

source§

impl ToSql for (f32, f32)

source§

fn to_sql(&self) -> MimerDatatype<'_>

source§

impl ToSql for bool

source§

fn to_sql(&self) -> MimerDatatype<'_>

source§

impl ToSql for f32

source§

fn to_sql(&self) -> MimerDatatype<'_>

source§

impl ToSql for f64

source§

fn to_sql(&self) -> MimerDatatype<'_>

source§

impl ToSql for i32

source§

fn to_sql(&self) -> MimerDatatype<'_>

source§

impl ToSql for i64

source§

fn to_sql(&self) -> MimerDatatype<'_>

source§

impl ToSql for String

source§

fn to_sql(&self) -> MimerDatatype<'_>

source§

impl ToSql for Vec<u8>

source§

fn to_sql(&self) -> MimerDatatype<'_>

source§

impl ToSql for NaiveDate

source§

fn to_sql(&self) -> MimerDatatype<'_>

source§

impl ToSql for NaiveDateTime

source§

fn to_sql(&self) -> MimerDatatype<'_>

source§

impl ToSql for NaiveTime

source§

fn to_sql(&self) -> MimerDatatype<'_>

source§

impl ToSql for Uuid

source§

fn to_sql(&self) -> MimerDatatype<'_>

source§

impl ToSql for Point<i32>

source§

fn to_sql(&self) -> MimerDatatype<'_>

source§

impl<T> ToSql for Option<T>
where T: ToSql,

source§

fn to_sql(&self) -> MimerDatatype<'_>

source§

impl<const N: usize> ToSql for [u8; N]

source§

fn to_sql(&self) -> MimerDatatype<'_>

Implementors§