33 releases (21 breaking)

✓ Uses Rust 2018 edition

0.22.1 May 23, 2020
0.21.0 Mar 28, 2020
0.20.0 Nov 28, 2019
0.17.1 May 7, 2019
0.1.0 Jul 25, 2017

#9 in Database interfaces

Download history 4744/week @ 2020-02-09 5009/week @ 2020-02-16 4641/week @ 2020-02-23 4141/week @ 2020-03-01 3172/week @ 2020-03-08 3251/week @ 2020-03-15 3662/week @ 2020-03-22 3548/week @ 2020-03-29 3734/week @ 2020-04-05 3216/week @ 2020-04-12 2866/week @ 2020-04-19 2664/week @ 2020-04-26 2767/week @ 2020-05-03 2928/week @ 2020-05-10 2873/week @ 2020-05-17 2528/week @ 2020-05-24

14,407 downloads per month
Used in 50 crates (7 directly)

MIT/Apache

290KB
7K SLoC

Ruby HTML 7K SLoC // 0.1% comments PSL Assertion 11 SLoC // 0.2% comments

Crates.io Docs.rs Build Status

mysql_common

This crate is an implementation of basic MySql protocol primitives.

This crate:

  • defines basic MySql constants;
  • implements necessary functionality for MySql cached_sha2_password and mysql_native_password 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;
  • 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:

Type Notes
{i,u}8..{i,u}128, {i,u}size MySql 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).
f32 MySql 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)
f64 MySql float and double will be converted to f64, bytes will be parsed as f64.
bool MySql int {0, 1} or bytes {"0x30", "0x31"}
Vec<u8> MySql bytes
String MySql bytes parsed as utf8
Duration (std and time) MySql time or bytes parsed as MySql time string
time::OffsetDateTime MySql date or bytes parsed as MySql date string
time::PrimitiveDateTime MySql date or bytes parsed as MySql date string
time::Date MySql date or bytes parsed as MySql date string
time::Time MySql date or bytes parsed as MySql date 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::Uuid MySql bytes parsed using Uuid::from_slice
serde_json::Value MySql 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 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).

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~11MB
~219K SLoC