Skip to content

Commit

Permalink
add suport for tz-aware datetimes in any
Browse files Browse the repository at this point in the history
  • Loading branch information
lovasoa committed Nov 2, 2024
1 parent 54b04ff commit f8de9be
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.6.34

- Add support for decoding `DateTime<FixedOffset>` in the `Any` driver

## 0.6.33

- Add support for decoding all numeric types as either f32 or f64 in mssql.
Expand Down
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ members = [

[package]
name = "sqlx-oldapi"
version = "0.6.33"
version = "0.6.34"
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/lovasoa/sqlx"
Expand Down Expand Up @@ -125,8 +125,8 @@ bstr = ["sqlx-core/bstr"]
git2 = ["sqlx-core/git2"]

[dependencies]
sqlx-core = { package = "sqlx-core-oldapi", version = "0.6.33", path = "sqlx-core", default-features = false }
sqlx-macros = { package = "sqlx-macros-oldapi", version = "0.6.33", path = "sqlx-macros", default-features = false, optional = true }
sqlx-core = { package = "sqlx-core-oldapi", version = "0.6.34", path = "sqlx-core", default-features = false }
sqlx-macros = { package = "sqlx-macros-oldapi", version = "0.6.34", path = "sqlx-macros", default-features = false, optional = true }

[dev-dependencies]
anyhow = "1.0.52"
Expand Down
2 changes: 1 addition & 1 deletion examples/postgres/axum-social-with-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
[dependencies]
# Primary crates
axum = { version = "0.5.13", features = ["macros"] }
sqlx = { package = "sqlx-oldapi", version = "0.6.33", path = "../../../", features = ["runtime-tokio-rustls", "postgres", "time", "uuid"] }
sqlx = { package = "sqlx-oldapi", version = "0.6.34", path = "../../../", features = ["runtime-tokio-rustls", "postgres", "time", "uuid"] }
tokio = { version = "1.20.1", features = ["rt-multi-thread", "macros"] }

# Important secondary crates
Expand Down
2 changes: 1 addition & 1 deletion sqlx-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sqlx-cli"
version = "0.6.33"
version = "0.6.34"
description = "Command-line utility for SQLx, the Rust SQL toolkit."
edition = "2021"
readme = "README.md"
Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sqlx-core-oldapi"
version = "0.6.33"
version = "0.6.34"
repository = "https://github.com/lovasoa/sqlx"
description = "Core of SQLx, the rust SQL toolkit. Not intended to be used directly."
license = "MIT OR Apache-2.0"
Expand Down Expand Up @@ -101,7 +101,7 @@ offline = ["serde", "either/serde"]
paste = "1.0.6"
ahash = "0.8.3"
atoi = "2.0.0"
sqlx-rt = { path = "../sqlx-rt", version = "0.6.33", package = "sqlx-rt-oldapi" }
sqlx-rt = { path = "../sqlx-rt", version = "0.6.34", package = "sqlx-rt-oldapi" }
base64 = { version = "0.22", default-features = false, optional = true, features = ["std"] }
bigdecimal_ = { version = "0.4.1", optional = true, package = "bigdecimal" }
rust_decimal = { version = "1.19.0", optional = true }
Expand Down
6 changes: 6 additions & 0 deletions sqlx-core/src/any/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ impl_any_type!(chrono::NaiveDateTime);
#[cfg(feature = "chrono")]
impl_any_type!(chrono::DateTime<chrono::offset::Utc>);
#[cfg(feature = "chrono")]
impl_any_type!(chrono::DateTime<chrono::offset::FixedOffset>);
#[cfg(feature = "chrono")]
impl_any_type!(chrono::DateTime<chrono::offset::Local>);

// Encode
Expand All @@ -96,6 +98,8 @@ impl_any_encode!(chrono::NaiveDateTime);
#[cfg(feature = "chrono")]
impl_any_encode!(chrono::DateTime<chrono::offset::Utc>);
#[cfg(feature = "chrono")]
impl_any_encode!(chrono::DateTime<chrono::offset::FixedOffset>);
#[cfg(feature = "chrono")]
impl_any_encode!(chrono::DateTime<chrono::offset::Local>);

// Decode
Expand All @@ -108,6 +112,8 @@ impl_any_decode!(chrono::NaiveDateTime);
#[cfg(feature = "chrono")]
impl_any_decode!(chrono::DateTime<chrono::offset::Utc>);
#[cfg(feature = "chrono")]
impl_any_decode!(chrono::DateTime<chrono::offset::FixedOffset>);
#[cfg(feature = "chrono")]
impl_any_decode!(chrono::DateTime<chrono::offset::Local>);

#[cfg(feature = "json")]
Expand Down
6 changes: 3 additions & 3 deletions sqlx-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sqlx-macros-oldapi"
version = "0.6.33"
version = "0.6.34"
repository = "https://github.com/lovasoa/sqlx"
description = "Macros for SQLx, the rust SQL toolkit. Not intended to be used directly."
license = "MIT OR Apache-2.0"
Expand Down Expand Up @@ -75,8 +75,8 @@ heck = { version = "0.5" }
either = "1.6.1"
once_cell = "1.9.0"
proc-macro2 = { version = "1.0.36", default-features = false }
sqlx-core = { package = "sqlx-core-oldapi", version = "0.6.33", default-features = false, features = ["any"], path = "../sqlx-core" }
sqlx-rt = { version = "0.6.33", default-features = false, path = "../sqlx-rt", package = "sqlx-rt-oldapi" }
sqlx-core = { package = "sqlx-core-oldapi", version = "0.6.34", default-features = false, features = ["any"], path = "../sqlx-core" }
sqlx-rt = { version = "0.6.34", default-features = false, path = "../sqlx-rt", package = "sqlx-rt-oldapi" }
serde = { version = "1.0.132", features = ["derive"], optional = true }
serde_json = { version = "1.0.73", optional = true }
sha2 = { version = "0.10.0", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion sqlx-rt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sqlx-rt-oldapi"
version = "0.6.33"
version = "0.6.34"
repository = "https://github.com/launchbadge/sqlx"
license = "MIT OR Apache-2.0"
description = "Runtime abstraction used by SQLx, the Rust SQL toolkit. Not intended to be used directly."
Expand Down
4 changes: 2 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
docker compose -f tests/docker-compose.yml run -d -p 5432:5432 --name postgres_16 postgres_16
docker compose -f tests/docker-compose.yml run -it -p 5432:5432 --name postgres_16 postgres_16
DATABASE_URL="postgres://postgres@localhost:5432/sqlx?sslmode=verify-ca&sslrootcert=./tests/certs/ca.crt&sslcert=./tests/certs/client.crt&sslkey=./tests/keys/client.key" cargo test --features any,postgres,macros,all-types,runtime-actix-rustls --

docker compose -f tests/docker-compose.yml run -d -p 1433:1433 --name mssql_2022 mssql_2022
docker compose -f tests/docker-compose.yml run -it -p 1433:1433 --name mssql_2022 mssql_2022
DATABASE_URL='mssql://sa:Password123!@localhost/sqlx' cargo test --features any,mssql,macros,all-types,runtime-actix-rustls --
23 changes: 23 additions & 0 deletions tests/any/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,29 @@ async fn it_has_chrono() -> anyhow::Result<()> {
Ok(())
}

#[cfg(feature = "chrono")]
#[sqlx_macros::test]
async fn it_has_chrono_fixed_offset() -> anyhow::Result<()> {
use sqlx_oldapi::types::chrono::{DateTime, FixedOffset};
assert_eq!(
DateTime::<FixedOffset>::parse_from_rfc3339("2020-01-02T12:00:00+02:00").unwrap(),
get_val::<DateTime<FixedOffset>>(
if cfg!(feature = "sqlite") {
"'2020-01-02 12:00:00+02:00'"
} else if cfg!(feature = "mssql") {
"CAST('2020-01-02 12:00:00+02:00' AS DATETIMEOFFSET)"
} else if cfg!(feature = "postgres") {
"'2020-01-02 12:00:00+02:00'::timestamptz"
} else {
eprintln!("DBMS not supported");
return Ok(())
}
)
.await?
);
Ok(())
}

#[cfg(feature = "bigdecimal")]
#[sqlx_macros::test]
async fn it_has_bigdecimal() -> anyhow::Result<()> {
Expand Down

0 comments on commit f8de9be

Please sign in to comment.