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 type | Mimer SQL type |
|---|---|
Option<T> where T: ToSql | NULL if None, otherwise the appropriate conversion for the type T and column |
| i32 | INTEGER, BIGINT or SMALLINT |
| i64 | INTEGER, BIGINT or SMALLINT |
| String | String datatypes1, CHARACTER LARGE OBJECT and NATIONAL CHARACTER LARGE OBJECT |
| f32 | REAL, DOUBLE PRECISION, BINARY(4)2 |
| (f32,f32) | BINARY(8)3 |
| f64 | REAL and DOUBLE PRECISION |
| bool | BOOLEAN |
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 type | Mimer SQL type |
|---|---|
| uuid::Uuid4 | BINARY, BINARY VARYING, BINARY LARGE OBJECT |
| chrono::NaiveDate | DATE |
| chrono::NaiveTime | TIME |
| chrono::NaiveDateTime | TIMESTAMP |
[geo::Point<i32>] | BINARY |
String datatypes include CHARACTER, CHARACTER VARYING, NATIONAL CHARACTER, NATIONAL CHARACTER VARYING, DATE, TIME, TIMESTAMP, DECIMAL and NUMERIC. ↩
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]. ↩
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. ↩
Converts into a 16 byte binary sequence. Mainly intended for BUILTIN.UUID. ↩