Crate mysql_common[][src]

Expand description

This crate is an implementation of basic MySql protocol primitives.

This crate:

  • defines basic MySql constants;
  • implements necessary functionality for MySql cached_sha2_password, mysql_native_password and legacy authentication plugins;
  • implements helper traits for MySql protocol IO;
  • implements support of named parameters for prepared statements;
  • implements parsers for a subset of MySql protocol packets (including binlog packets);
  • defines rust representation of MySql protocol value and row;
  • implements conversion between MySql values and rust types, between MySql rows and tuples of rust types.

Supported rust types

Crate offers conversion from/to MySql values for following types (please see MySql documentation on supported ranges for numeric types). Following table refers to MySql protocol types (see Value struct) and not to MySql column types. Please see MySql documentation for column and protocol type correspondence:

TypeNotes
{i,u}8..{i,u}128, {i,u}sizeMySql int/uint will be converted, bytes will be parsed.
⚠️ Note that range of {i,u}128 is greater than supported by MySql integer types but it’ll be serialized anyway (as decimal bytes string).
f32MySql float will be converted to f32, bytes will be parsed as f32.
⚠️ MySql double won’t be converted to f32 to avoid precision loss (see #17)
f64MySql float and double will be converted to f64, bytes will be parsed as f64.
boolMySql int {0, 1} or bytes {"0x30", "0x31"}
Vec<u8>MySql bytes
StringMySql bytes parsed as utf8
Duration (std and time)MySql time or bytes parsed as MySql time string
[time::PrimitiveDateTime] (v0.2.x)MySql date time or bytes parsed as MySql date time string (⚠️ lossy! microseconds are ignored)
[time::Date] (v0.2.x)MySql date or bytes parsed as MySql date string (⚠️ lossy! microseconds are ignored)
[time::Time] (v0.2.x)MySql time or bytes parsed as MySql time string (⚠️ lossy! microseconds are ignored)
[time::Duration] (v0.2.x)MySql time or bytes parsed as MySql time string
[time::PrimitiveDateTime] (v0.3.x)MySql date time or bytes parsed as MySql date time string (⚠️ lossy! microseconds are ignored)
[time::Date] (v0.3.x)MySql date or bytes parsed as MySql date string (⚠️ lossy! microseconds are ignored)
[time::Time] (v0.3.x)MySql time or bytes parsed as MySql time string (⚠️ lossy! microseconds are ignored)
[time::Duration] (v0.3.x)MySql time or bytes parsed as MySql time string
[chrono::NaiveTime]MySql date or bytes parsed as MySql date string
[chrono::NaiveDate]MySql date or bytes parsed as MySql date string
[chrono::NaiveDateTime]MySql date or bytes parsed as MySql date string
uuid::UuidMySql bytes parsed using Uuid::from_slice
serde_json::ValueMySql bytes parsed using serde_json::from_str
mysql_common::Deserialized<T : DeserializeOwned>MySql bytes parsed using serde_json::from_str
Option<T: FromValue>Must be used for nullable columns to avoid errors
[decimal::Decimal]MySql int, uint or bytes parsed using Decimal::from_str.
⚠️ Note that this type doesn’t support full range of MySql DECIMAL type.
[bigdecimal::BigDecimal] (v0.2.x)MySql int, uint, floats or bytes parsed using BigDecimal::parse_bytes.
⚠️ Note that range of this type is greater than supported by MySql DECIMAL type but it’ll be serialized anyway.
[bigdecimal::BigDecimal] (v0.3.x)MySql int, uint, floats or bytes parsed using BigDecimal::parse_bytes.
⚠️ Note that range of this type is greater than supported by MySql DECIMAL type but it’ll be serialized anyway.
num_bigint::{BigInt, BigUint}MySql int, uint or bytes parsed using _::parse_bytes.
⚠️ Note that range of this type is greater than supported by MySql integer types but it’ll be serialized anyway (as decimal bytes string).

Also crate provides from-row convertion for the following list of types (see FromRow trait):

TypeNotes
RowTrivial conversion for Row itself.
T: FromValueFor rows with a single column.
(T1: FromValue [, ..., T12: FromValue])Row to a tuple of arity 1-12.
[frunk::Hlist!] typesUsefull to overcome tuple arity limitation

Crate features

FeatureDescriptionDefault
bigdecimalEnables bigdecimal v0.2.x types support🔴
bigdecimal03Enables bigdecimal v0.3.x types support🟢
chronoEnables chrono types support🔴
rust_decimalEnables rust_decimal types support🟢
timeEnables time v0.2.x types support🔴
time03Enables time v0.3.x types support🟢
uuidEnables Uuid type support🟢
frunkEnables FromRow for frunk::Hlist! types🟢

Re-exports

pub use bigdecimal03;
pub use frunk;
pub use rust_decimal;
pub use time03;
pub use uuid;
pub use num_bigint;
pub use serde;
pub use serde_json;

Modules

Binlog-related structures and functions. This implementation assumes binlog version >= 4 (MySql >= 5.0.0).

Macros

This macro is a convenient way to pass named parameters to a statement.