From db543f8391ac7bb98c6f372f2ba17682e7797397 Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Sat, 21 Mar 2020 02:34:21 -0700 Subject: [PATCH] clean up Time impl, impl for text modes --- Cargo.lock | 131 +++++++++++++++++ Cargo.toml | 1 + sqlx-core/src/mysql/types/time.rs | 129 ++++++++++++----- sqlx-core/src/postgres/protocol/message.rs | 2 +- sqlx-core/src/postgres/types/time.rs | 159 ++++++++++++++++----- tests/mysql-types-chrono.rs | 88 ------------ tests/mysql-types-time.rs | 92 ------------ tests/mysql-types.rs | 40 +++++- tests/postgres-types-chrono.rs | 91 ------------ tests/postgres-types-time.rs | 109 -------------- tests/postgres-types.rs | 39 +++++ 11 files changed, 424 insertions(+), 457 deletions(-) delete mode 100644 tests/mysql-types-chrono.rs delete mode 100644 tests/mysql-types-time.rs delete mode 100644 tests/postgres-types-chrono.rs delete mode 100644 tests/postgres-types-time.rs diff --git a/Cargo.lock b/Cargo.lock index 2a6758ba..0ff4b30c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -162,6 +162,12 @@ dependencies = [ "libc", ] +[[package]] +name = "base-x" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b20b618342cf9891c292c4f5ac2cde7287cc5c87e87e9c769d617793607dec1" + [[package]] name = "base64" version = "0.10.1" @@ -246,6 +252,12 @@ dependencies = [ "slab", ] +[[package]] +name = "bumpalo" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f359dc14ff8911330a51ef78022d376f25ed00248912803b58f00cb1c27f742" + [[package]] name = "byte-tools" version = "0.3.1" @@ -436,6 +448,12 @@ dependencies = [ "generic-array", ] +[[package]] +name = "discard" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" + [[package]] name = "dotenv" version = "0.15.0" @@ -1586,6 +1604,12 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "sha1" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" + [[package]] name = "sha2" version = "0.8.1" @@ -1672,6 +1696,7 @@ dependencies = [ "sqlx-core 0.3.0-alpha.1", "sqlx-macros 0.3.0-alpha.1", "sqlx-test", + "time 0.2.9", "tokio 0.2.13", "trybuild", ] @@ -1821,6 +1846,55 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4edf667ea8f60afc06d6aeec079d20d5800351109addec1faea678a8663da4e1" +[[package]] +name = "stdweb" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" +dependencies = [ + "discard", + "rustc_version", + "stdweb-derive", + "stdweb-internal-macros", + "stdweb-internal-runtime", + "wasm-bindgen", +] + +[[package]] +name = "stdweb-derive" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "serde_derive", + "syn", +] + +[[package]] +name = "stdweb-internal-macros" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" +dependencies = [ + "base-x", + "proc-macro2", + "quote", + "serde", + "serde_derive", + "serde_json", + "sha1", + "syn", +] + +[[package]] +name = "stdweb-internal-runtime" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" + [[package]] name = "string" version = "0.2.1" @@ -1987,9 +2061,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6329a7835505d46f5f3a9a2c237f8d6bf5ca6f0015decb3698ba57fcdbb609ba" dependencies = [ "cfg-if", + "libc", "rustversion", "standback", + "stdweb", "time-macros", + "winapi 0.3.8", ] [[package]] @@ -2322,6 +2399,60 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +[[package]] +name = "wasm-bindgen" +version = "0.2.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3557c397ab5a8e347d434782bcd31fc1483d927a6826804cec05cc792ee2519d" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0da9c9a19850d3af6df1cb9574970b566d617ecfaf36eb0b706b6f3ef9bd2f8" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f6fde1d36e75a714b5fe0cffbb78978f222ea6baebb726af13c78869fdb4205" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25bda4168030a6412ea8a047e27238cadf56f0e53516e1e83fec0a8b7c786f6d" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc9f36ad51f25b0219a3d4d13b90eb44cd075dff8b6280cca015775d7acaddd8" + [[package]] name = "winapi" version = "0.2.8" diff --git a/Cargo.toml b/Cargo.toml index 9e75242e..2d638e51 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,6 +59,7 @@ sqlx-macros = { version = "0.3.0-alpha.1", path = "sqlx-macros", default-feature [dev-dependencies] anyhow = "1.0.26" +time_ = { version = "0.2.9", package = "time" } futures = "0.3.4" env_logger = "0.7.1" async-std = { version = "1.5.0", features = [ "attributes" ] } diff --git a/sqlx-core/src/mysql/types/time.rs b/sqlx-core/src/mysql/types/time.rs index eee0c7a0..cf7a4c03 100644 --- a/sqlx-core/src/mysql/types/time.rs +++ b/sqlx-core/src/mysql/types/time.rs @@ -1,17 +1,19 @@ +use std::borrow::Cow; use std::convert::TryFrom; +use std::convert::TryInto; use byteorder::{ByteOrder, LittleEndian}; use time::{Date, OffsetDateTime, PrimitiveDateTime, Time, UtcOffset}; -use crate::decode::{Decode, DecodeError}; +use crate::decode::Decode; use crate::encode::Encode; use crate::io::{Buf, BufMut}; use crate::mysql::protocol::TypeId; use crate::mysql::types::MySqlTypeInfo; -use crate::mysql::MySql; -use crate::types::HasSqlType; +use crate::mysql::{MySql, MySqlValue}; +use crate::types::Type; -impl HasSqlType for MySql { +impl Type for OffsetDateTime { fn type_info() -> MySqlTypeInfo { MySqlTypeInfo::new(TypeId::TIMESTAMP) } @@ -26,15 +28,15 @@ impl Encode for OffsetDateTime { } } -impl Decode for OffsetDateTime { - fn decode(buf: &[u8]) -> Result { - let primitive: PrimitiveDateTime = Decode::::decode(buf)?; +impl<'de> Decode<'de, MySql> for OffsetDateTime { + fn decode(value: Option>) -> crate::Result { + let primitive: PrimitiveDateTime = Decode::::decode(value)?; Ok(primitive.assume_utc()) } } -impl HasSqlType