diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index f6c3553e..df5d3290 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -39,25 +39,25 @@ jobs: # check w/deny warnings in sqlx-core: async-std - working-directory: sqlx-core - run: cargo rustc --no-default-features --features 'bigdecimal ipnetwork chrono time uuid postgres mysql tls runtime-async-std' -- -D warnings --emit=metadata + run: cargo rustc --no-default-features --features 'all-type postgres mysql tls runtime-async-std' -- -D warnings --emit=metadata # check w/deny warnings in sqlx-core: tokio # `cargo rustc -p sqlx-core` ignores `--no-default-features` and builds with `runtime-async-std` anyway # https://github.com/rust-lang/cargo/issues/5364 - working-directory: sqlx-core - run: cargo rustc --no-default-features --features 'bigdecimal ipnetwork chrono time uuid postgres mysql tls runtime-tokio' -- -D warnings --emit=metadata + run: cargo rustc --no-default-features --features 'all-type postgres mysql tls runtime-tokio' -- -D warnings --emit=metadata # check w/deny warnings: async-std - - run: cargo rustc --no-default-features --features 'bigdecimal ipnetwork chrono time uuid postgres mysql macros tls runtime-async-std' -- -D warnings --emit=metadata + - run: cargo rustc --no-default-features --features 'all-type postgres mysql macros tls runtime-async-std' -- -D warnings --emit=metadata # check w/deny warnings: tokio - - run: cargo rustc --no-default-features --features 'bigdecimal ipnetwork chrono time uuid postgres mysql macros tls runtime-tokio' -- -D warnings --emit=metadata + - run: cargo rustc --no-default-features --features 'all-type postgres mysql macros tls runtime-tokio' -- -D warnings --emit=metadata # unit test: async-std - - run: cargo test --manifest-path sqlx-core/Cargo.toml --no-default-features --features 'bigdecimal ipnetwork chrono time uuid postgres mysql tls runtime-async-std' + - run: cargo test --manifest-path sqlx-core/Cargo.toml --no-default-features --features 'all-type postgres mysql tls runtime-async-std' # unit test: tokio - - run: cargo test --manifest-path sqlx-core/Cargo.toml --no-default-features --features 'bigdecimal ipnetwork chrono time uuid postgres mysql tls runtime-tokio' + - run: cargo test --manifest-path sqlx-core/Cargo.toml --no-default-features --features 'all-type postgres mysql tls runtime-tokio' # integration test: sqlite + async-std - run: cargo test --no-default-features --features 'runtime-async-std sqlite macros tls' diff --git a/sqlx-core/src/mysql/types/chrono.rs b/sqlx-core/src/mysql/types/chrono.rs index 9e948071..41ab2700 100644 --- a/sqlx-core/src/mysql/types/chrono.rs +++ b/sqlx-core/src/mysql/types/chrono.rs @@ -260,15 +260,27 @@ fn test_encode_date_time() { fn test_decode_date_time() { // test values from https://dev.mysql.com/doc/internals/en/binary-protocol-value.html let buf = [11, 218, 7, 10, 17, 19, 27, 30, 1, 0, 0, 0]; - let date1 = >::decode(Some(MySqlData::Binary(&buf))).unwrap(); + let date1 = >::decode(MySqlValue::binary( + MySqlTypeInfo::default(), + &buf, + )) + .unwrap(); assert_eq!(date1.to_string(), "2010-10-17 19:27:30.000001"); let buf = [7, 218, 7, 10, 17, 19, 27, 30]; - let date2 = >::decode(Some(MySqlData::Binary(&buf))).unwrap(); + let date2 = >::decode(MySqlValue::binary( + MySqlTypeInfo::default(), + &buf, + )) + .unwrap(); assert_eq!(date2.to_string(), "2010-10-17 19:27:30"); let buf = [4, 218, 7, 10, 17]; - let date3 = >::decode(Some(MySqlData::Binary(&buf))).unwrap(); + let date3 = >::decode(MySqlValue::binary( + MySqlTypeInfo::default(), + &buf, + )) + .unwrap(); assert_eq!(date3.to_string(), "2010-10-17 00:00:00"); } @@ -283,6 +295,8 @@ fn test_encode_date() { #[test] fn test_decode_date() { let buf = [4, 218, 7, 10, 17]; - let date = >::decode(Some(MySqlData::Binary(&buf))).unwrap(); + let date = + >::decode(MySqlValue::binary(MySqlTypeInfo::default(), &buf)) + .unwrap(); assert_eq!(date.to_string(), "2010-10-17"); } diff --git a/sqlx-core/src/mysql/types/time.rs b/sqlx-core/src/mysql/types/time.rs index 4aa6dbce..949a8e86 100644 --- a/sqlx-core/src/mysql/types/time.rs +++ b/sqlx-core/src/mysql/types/time.rs @@ -283,18 +283,27 @@ fn test_encode_date_time() { fn test_decode_date_time() { // test values from https://dev.mysql.com/doc/internals/en/binary-protocol-value.html let buf = [11, 218, 7, 10, 17, 19, 27, 30, 1, 0, 0, 0]; - let date1 = - >::decode(Some(MySqlData::Binary(&buf))).unwrap(); + let date1 = >::decode(MySqlValue::binary( + MySqlTypeInfo::default(), + &buf, + )) + .unwrap(); assert_eq!(date1.to_string(), "2010-10-17 19:27:30.000001"); let buf = [7, 218, 7, 10, 17, 19, 27, 30]; - let date2 = - >::decode(Some(MySqlData::Binary(&buf))).unwrap(); + let date2 = >::decode(MySqlValue::binary( + MySqlTypeInfo::default(), + &buf, + )) + .unwrap(); assert_eq!(date2.to_string(), "2010-10-17 19:27:30"); let buf = [4, 218, 7, 10, 17]; - let date3 = - >::decode(Some(MySqlData::Binary(&buf))).unwrap(); + let date3 = >::decode(MySqlValue::binary( + MySqlTypeInfo::default(), + &buf, + )) + .unwrap(); assert_eq!(date3.to_string(), "2010-10-17 0:00"); } @@ -309,6 +318,7 @@ fn test_encode_date() { #[test] fn test_decode_date() { let buf = [4, 218, 7, 10, 17]; - let date = >::decode(Some(MySqlData::Binary(&buf))).unwrap(); + let date = >::decode(MySqlValue::binary(MySqlTypeInfo::default(), &buf)) + .unwrap(); assert_eq!(date, date!(2010 - 10 - 17)); } diff --git a/sqlx-core/src/postgres/types/chrono.rs b/sqlx-core/src/postgres/types/chrono.rs index 11d746de..237b2346 100644 --- a/sqlx-core/src/postgres/types/chrono.rs +++ b/sqlx-core/src/postgres/types/chrono.rs @@ -264,18 +264,18 @@ fn test_encode_time() { #[test] fn test_decode_time() { let buf = [0u8; 8]; - let time: NaiveTime = Decode::::decode(Some(PgData::Binary(&buf))).unwrap(); + let time: NaiveTime = Decode::::decode(PgValue::bytes(TypeId(0), &buf)).unwrap(); assert_eq!(time, NaiveTime::from_hms(0, 0, 0),); // half an hour let buf = (1_000_000i64 * 60 * 30).to_be_bytes(); - let time: NaiveTime = Decode::::decode(Some(PgData::Binary(&buf))).unwrap(); + let time: NaiveTime = Decode::::decode(PgValue::bytes(TypeId(0), &buf)).unwrap(); assert_eq!(time, NaiveTime::from_hms(0, 30, 0),); // 12:53:05.125305 let buf = (1_000_000i64 * 60 * 60 * 12 + 1_000_000i64 * 60 * 53 + 1_000_000i64 * 5 + 125305) .to_be_bytes(); - let time: NaiveTime = Decode::::decode(Some(PgData::Binary(&buf))).unwrap(); + let time: NaiveTime = Decode::::decode(PgValue::bytes(TypeId(0), &buf)).unwrap(); assert_eq!(time, NaiveTime::from_hms_micro(12, 53, 5, 125305),); } @@ -307,15 +307,15 @@ fn test_encode_datetime() { #[test] fn test_decode_datetime() { let buf = [0u8; 8]; - let date: NaiveDateTime = Decode::::decode(Some(PgData::Binary(&buf))).unwrap(); + let date: NaiveDateTime = Decode::::decode(PgValue::bytes(TypeId(0), &buf)).unwrap(); assert_eq!(date.to_string(), "2000-01-01 00:00:00"); let buf = 3_600_000_000i64.to_be_bytes(); - let date: NaiveDateTime = Decode::::decode(Some(PgData::Binary(&buf))).unwrap(); + let date: NaiveDateTime = Decode::::decode(PgValue::bytes(TypeId(0), &buf)).unwrap(); assert_eq!(date.to_string(), "2000-01-01 01:00:00"); let buf = 629_377_265_000_000i64.to_be_bytes(); - let date: NaiveDateTime = Decode::::decode(Some(PgData::Binary(&buf))).unwrap(); + let date: NaiveDateTime = Decode::::decode(PgValue::bytes(TypeId(0), &buf)).unwrap(); assert_eq!(date.to_string(), "2019-12-11 11:01:05"); } @@ -343,14 +343,14 @@ fn test_encode_date() { #[test] fn test_decode_date() { let buf = [0; 4]; - let date: NaiveDate = Decode::::decode(Some(PgData::Binary(&buf))).unwrap(); + let date: NaiveDate = Decode::::decode(PgValue::bytes(TypeId(0), &buf)).unwrap(); assert_eq!(date.to_string(), "2000-01-01"); let buf = 366i32.to_be_bytes(); - let date: NaiveDate = Decode::::decode(Some(PgData::Binary(&buf))).unwrap(); + let date: NaiveDate = Decode::::decode(PgValue::bytes(TypeId(0), &buf)).unwrap(); assert_eq!(date.to_string(), "2001-01-01"); let buf = 7284i32.to_be_bytes(); - let date: NaiveDate = Decode::::decode(Some(PgData::Binary(&buf))).unwrap(); + let date: NaiveDate = Decode::::decode(PgValue::bytes(TypeId(0), &buf)).unwrap(); assert_eq!(date.to_string(), "2019-12-11"); } diff --git a/sqlx-core/src/postgres/types/raw/array.rs b/sqlx-core/src/postgres/types/raw/array.rs index a5b329b4..ff85e720 100644 --- a/sqlx-core/src/postgres/types/raw/array.rs +++ b/sqlx-core/src/postgres/types/raw/array.rs @@ -171,7 +171,8 @@ where mod tests { use super::PgArrayDecoder; use super::PgArrayEncoder; - use crate::postgres::{PgData, PgValue, Postgres}; + use crate::postgres::protocol::TypeId; + use crate::postgres::{PgValue, Postgres}; const BUF_BINARY_I32: &[u8] = b"\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00\x02\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x04"; @@ -192,7 +193,7 @@ mod tests { #[test] fn it_decodes_text_i32() -> crate::Result { let s = "{1,152,-12412}"; - let mut decoder = PgArrayDecoder::::new(Some(PgData::Text(s)))?; + let mut decoder = PgArrayDecoder::::new(PgValue::str(TypeId(0), s))?; assert_eq!(decoder.decode()?, Some(1)); assert_eq!(decoder.decode()?, Some(152)); @@ -205,7 +206,7 @@ mod tests { #[test] fn it_decodes_text_str() -> crate::Result { let s = "{\"\",\"\\\"\"}"; - let mut decoder = PgArrayDecoder::::new(Some(PgData::Text(s)))?; + let mut decoder = PgArrayDecoder::::new(PgValue::str(TypeId(0), s))?; assert_eq!(decoder.decode()?, Some("".to_string())); assert_eq!(decoder.decode()?, Some("\"".to_string())); @@ -216,9 +217,9 @@ mod tests { #[test] fn it_decodes_binary_nulls() -> crate::Result { - let mut decoder = PgArrayDecoder::>::new(Some(PgData::Binary( - b"\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x10\x00\x00\x00\x04\x00\x00\x00\x01\xff\xff\xff\xff\x00\x00\x00\x01\x01\xff\xff\xff\xff\x00\x00\x00\x01\x00", 0, - )))?; + let mut decoder = PgArrayDecoder::>::new(PgValue::bytes(TypeId(0), + b"\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x10\x00\x00\x00\x04\x00\x00\x00\x01\xff\xff\xff\xff\x00\x00\x00\x01\x01\xff\xff\xff\xff\x00\x00\x00\x01\x00", + ))?; assert_eq!(decoder.decode()?, Some(None)); assert_eq!(decoder.decode()?, Some(Some(true))); @@ -230,7 +231,7 @@ mod tests { #[test] fn it_decodes_binary_i32() -> crate::Result { - let mut decoder = PgArrayDecoder::::new(Some(PgData::Binary(BUF_BINARY_I32, 0)))?; + let mut decoder = PgArrayDecoder::::new(PgValue::bytes(TypeId(0), BUF_BINARY_I32))?; let val_1 = decoder.decode()?; let val_2 = decoder.decode()?; diff --git a/sqlx-core/src/postgres/types/raw/record.rs b/sqlx-core/src/postgres/types/raw/record.rs index b10e257a..71da7c84 100644 --- a/sqlx-core/src/postgres/types/raw/record.rs +++ b/sqlx-core/src/postgres/types/raw/record.rs @@ -88,6 +88,8 @@ impl<'de> PgRecordDecoder<'de> { #[test] fn test_encode_field() { + use std::convert::TryInto; + let value = "Foo Bar"; let mut raw_encoded = Vec::new(); <&str as Encode>::encode(&value, &mut raw_encoded); @@ -111,6 +113,8 @@ fn test_encode_field() { #[test] fn test_decode_field() { + use crate::postgres::protocol::TypeId; + let value = "Foo Bar".to_string(); let mut buf = Vec::new(); @@ -118,7 +122,7 @@ fn test_decode_field() { encoder.encode(&value); let buf = buf.as_slice(); - let mut decoder = PgRecordDecoder::new(Some(PgData::Binary(buf, 0))).unwrap(); + let mut decoder = PgRecordDecoder::new(PgValue::bytes(TypeId(0), buf)).unwrap(); let value_decoded: String = decoder.decode().unwrap(); assert_eq!(value_decoded, value); diff --git a/sqlx-core/src/postgres/types/time.rs b/sqlx-core/src/postgres/types/time.rs index ecf5fbf8..ff50fae7 100644 --- a/sqlx-core/src/postgres/types/time.rs +++ b/sqlx-core/src/postgres/types/time.rs @@ -285,18 +285,18 @@ fn test_encode_time() { #[test] fn test_decode_time() { let buf = [0u8; 8]; - let time: Time = Decode::::decode(Some(PgData::Binary(&buf))).unwrap(); + let time: Time = Decode::::decode(PgValue::bytes(TypeId(0), &buf)).unwrap(); assert_eq!(time, time!(0:00)); // half an hour let buf = (1_000_000i64 * 60 * 30).to_be_bytes(); - let time: Time = Decode::::decode(Some(PgData::Binary(&buf))).unwrap(); + let time: Time = Decode::::decode(PgValue::bytes(TypeId(0), &buf)).unwrap(); assert_eq!(time, time!(0:30)); // 12:53:05.125305 let buf = (1_000_000i64 * 60 * 60 * 12 + 1_000_000i64 * 60 * 53 + 1_000_000i64 * 5 + 125305) .to_be_bytes(); - let time: Time = Decode::::decode(Some(PgData::Binary(&buf))).unwrap(); + let time: Time = Decode::::decode(PgValue::bytes(TypeId(0), &buf)).unwrap(); assert_eq!(time, time!(12:53:05.125305)); } @@ -325,21 +325,24 @@ fn test_encode_datetime() { #[test] fn test_decode_datetime() { let buf = [0u8; 8]; - let date: PrimitiveDateTime = Decode::::decode(Some(PgData::Binary(&buf))).unwrap(); + let date: PrimitiveDateTime = + Decode::::decode(PgValue::bytes(TypeId(0), &buf)).unwrap(); assert_eq!( date, PrimitiveDateTime::new(date!(2000 - 01 - 01), time!(00:00:00)) ); let buf = 3_600_000_000i64.to_be_bytes(); - let date: PrimitiveDateTime = Decode::::decode(Some(PgData::Binary(&buf))).unwrap(); + let date: PrimitiveDateTime = + Decode::::decode(PgValue::bytes(TypeId(0), &buf)).unwrap(); assert_eq!( date, PrimitiveDateTime::new(date!(2000 - 01 - 01), time!(01:00:00)) ); let buf = 629_377_265_000_000i64.to_be_bytes(); - let date: PrimitiveDateTime = Decode::::decode(Some(PgData::Binary(&buf))).unwrap(); + let date: PrimitiveDateTime = + Decode::::decode(PgValue::bytes(TypeId(0), &buf)).unwrap(); assert_eq!( date, PrimitiveDateTime::new(date!(2019 - 12 - 11), time!(11:01:05)) @@ -372,21 +375,21 @@ fn test_encode_offsetdatetime() { #[test] fn test_decode_offsetdatetime() { let buf = [0u8; 8]; - let date: OffsetDateTime = Decode::::decode(Some(PgData::Binary(&buf))).unwrap(); + let date: OffsetDateTime = Decode::::decode(PgValue::bytes(TypeId(0), &buf)).unwrap(); assert_eq!( date, PrimitiveDateTime::new(date!(2000 - 01 - 01), time!(00:00:00)).assume_utc() ); let buf = 3_600_000_000i64.to_be_bytes(); - let date: OffsetDateTime = Decode::::decode(Some(PgData::Binary(&buf))).unwrap(); + let date: OffsetDateTime = Decode::::decode(PgValue::bytes(TypeId(0), &buf)).unwrap(); assert_eq!( date, PrimitiveDateTime::new(date!(2000 - 01 - 01), time!(01:00:00)).assume_utc() ); let buf = 629_377_265_000_000i64.to_be_bytes(); - let date: OffsetDateTime = Decode::::decode(Some(PgData::Binary(&buf))).unwrap(); + let date: OffsetDateTime = Decode::::decode(PgValue::bytes(TypeId(0), &buf)).unwrap(); assert_eq!( date, PrimitiveDateTime::new(date!(2019 - 12 - 11), time!(11:01:05)).assume_utc() @@ -417,14 +420,14 @@ fn test_encode_date() { #[test] fn test_decode_date() { let buf = [0; 4]; - let date: Date = Decode::::decode(Some(PgData::Binary(&buf))).unwrap(); + let date: Date = Decode::::decode(PgValue::bytes(TypeId(0), &buf)).unwrap(); assert_eq!(date, date!(2000 - 01 - 01)); let buf = 366i32.to_be_bytes(); - let date: Date = Decode::::decode(Some(PgData::Binary(&buf))).unwrap(); + let date: Date = Decode::::decode(PgValue::bytes(TypeId(0), &buf)).unwrap(); assert_eq!(date, date!(2001 - 01 - 01)); let buf = 7284i32.to_be_bytes(); - let date: Date = Decode::::decode(Some(PgData::Binary(&buf))).unwrap(); + let date: Date = Decode::::decode(PgValue::bytes(TypeId(0), &buf)).unwrap(); assert_eq!(date, date!(2019 - 12 - 11)); }