Skip to content

Commit 8c3e0c0

Browse files
committed
fix compilation without the all-types feature
1 parent cbe072f commit 8c3e0c0

File tree

3 files changed

+64
-51
lines changed

3 files changed

+64
-51
lines changed

.github/workflows/sqlx.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,23 @@ jobs:
2828
cargo check
2929
--manifest-path sqlx-core/Cargo.toml
3030
--no-default-features
31+
--all-targets
3132
--features offline,all-databases,all-types,migrate,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
3233
env:
3334
RUSTFLAGS: -D warnings
3435

3536
- run:
3637
cargo check
3738
--no-default-features
39+
--all-targets
3840
--features offline,all-databases,all-types,migrate,runtime-${{ matrix.runtime }}-${{ matrix.tls }},macros
3941

42+
- run:
43+
cargo check
44+
--no-default-features
45+
--all-targets
46+
--features offline,all-databases,migrate,runtime-${{ matrix.runtime }}-${{ matrix.tls }},macros
47+
4048
test:
4149
name: Unit Test
4250
runs-on: ubuntu-22.04

test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
docker compose -f tests/docker-compose.yml run -it -p 5432:5432 --name postgres_16 postgres_16
33
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 --
44

5-
docker compose -f tests/docker-compose.yml run -it -p 1433:1433 --name mssql_2022 mssql_2022
5+
docker compose -f tests/docker-compose.yml run -it -p 1433:1433 --rm --name mssql_2022 mssql_2022
66
DATABASE_URL='mssql://sa:Password123!@localhost/sqlx' cargo test --features any,mssql,macros,all-types,runtime-actix-rustls --
77

88
docker compose -f tests/docker-compose.yml run -it -p 3306:3306 --name mysql_8 mysql_8
99
DATABASE_URL='mysql://root:password@localhost/sqlx' cargo test --features any,mysql,macros,all-types,runtime-actix-rustls --
1010

11-
DATABASE_URL='sqlite://./tests/sqlite/sqlite.db' cargo test --features any,sqlite,macros,all-types,runtime-actix-rustls --
11+
DATABASE_URL='sqlite://./tests/sqlite/sqlite.db' cargo test --features any,sqlite,macros,all-types,runtime-actix-rustls --

tests/mssql/macros.rs

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,69 +20,74 @@ async fn test_query_simple() -> anyhow::Result<()> {
2020
Ok(())
2121
}
2222

23-
#[sqlx_macros::test]
24-
async fn test_query_datetime() -> anyhow::Result<()> {
25-
let mut conn = new::<Mssql>().await?;
23+
#[cfg(feature = "chrono")]
24+
mod macro_chrono {
25+
use super::*;
2626

27-
// Define the expected NaiveDateTime value
28-
let expected_naive_dt = sqlx_oldapi::types::chrono::NaiveDate::from_ymd_opt(2024, 7, 15)
29-
.expect("Invalid date")
30-
.and_hms_milli_opt(10, 30, 0, 123)
31-
.expect("Invalid time");
27+
#[sqlx_macros::test]
28+
async fn test_query_datetime() -> anyhow::Result<()> {
29+
let mut conn = new::<Mssql>().await?;
3230

33-
// Use DATETIME2(3) for precise millisecond storage in MSSQL.
34-
// The query! macro requires a string literal.
35-
let record =
36-
sqlx_oldapi::query!("SELECT CAST('2024-07-15 10:30:00.123' AS DATETIME2(3)) as dt")
37-
.fetch_one(&mut conn)
38-
.await?;
31+
// Define the expected NaiveDateTime value
32+
let expected_naive_dt = sqlx_oldapi::types::chrono::NaiveDate::from_ymd_opt(2024, 7, 15)
33+
.expect("Invalid date")
34+
.and_hms_milli_opt(10, 30, 0, 123)
35+
.expect("Invalid time");
3936

40-
assert_eq!(record.dt, Some(expected_naive_dt));
37+
// Use DATETIME2(3) for precise millisecond storage in MSSQL.
38+
// The query! macro requires a string literal.
39+
let record =
40+
sqlx_oldapi::query!("SELECT CAST('2024-07-15 10:30:00.123' AS DATETIME2(3)) as dt")
41+
.fetch_one(&mut conn)
42+
.await?;
4143

42-
Ok(())
43-
}
44+
assert_eq!(record.dt, Some(expected_naive_dt));
4445

45-
#[derive(sqlx_oldapi::FromRow, Debug, Clone, PartialEq)]
46-
pub struct LogNotificationConfig {
47-
pub id: i32,
48-
pub config_key: String,
49-
pub config_value: String,
50-
pub created_on: Option<sqlx_oldapi::types::chrono::NaiveDateTime>,
51-
pub last_updated: Option<sqlx_oldapi::types::chrono::NaiveDateTime>,
52-
}
46+
Ok(())
47+
}
5348

54-
#[sqlx_macros::test]
55-
async fn test_query_as_from_issue() -> anyhow::Result<()> {
56-
let mut conn = new::<Mssql>().await?;
49+
#[derive(sqlx_oldapi::FromRow, Debug, Clone, PartialEq)]
50+
pub struct LogNotificationConfig {
51+
pub id: i32,
52+
pub config_key: String,
53+
pub config_value: String,
54+
pub created_on: Option<sqlx_oldapi::types::chrono::NaiveDateTime>,
55+
pub last_updated: Option<sqlx_oldapi::types::chrono::NaiveDateTime>,
56+
}
5757

58-
let expected_created_on = sqlx_oldapi::types::chrono::NaiveDate::from_ymd_opt(2023, 1, 1)
59-
.unwrap()
60-
.and_hms_milli_opt(10, 0, 0, 0)
61-
.unwrap();
62-
let expected_last_updated = sqlx_oldapi::types::chrono::NaiveDate::from_ymd_opt(2023, 1, 2)
63-
.unwrap()
64-
.and_hms_milli_opt(11, 30, 0, 500)
65-
.unwrap();
66-
67-
let result = sqlx_oldapi::query_as!(
68-
LogNotificationConfig,
69-
r#"
58+
#[sqlx_macros::test]
59+
async fn test_query_as_from_issue() -> anyhow::Result<()> {
60+
let mut conn = new::<Mssql>().await?;
61+
62+
let expected_created_on = sqlx_oldapi::types::chrono::NaiveDate::from_ymd_opt(2023, 1, 1)
63+
.unwrap()
64+
.and_hms_milli_opt(10, 0, 0, 0)
65+
.unwrap();
66+
let expected_last_updated = sqlx_oldapi::types::chrono::NaiveDate::from_ymd_opt(2023, 1, 2)
67+
.unwrap()
68+
.and_hms_milli_opt(11, 30, 0, 500)
69+
.unwrap();
70+
71+
let result = sqlx_oldapi::query_as!(
72+
LogNotificationConfig,
73+
r#"
7074
SELECT
7175
1 AS id,
7276
'test_key' AS config_key,
7377
'test_value' AS config_value,
7478
CAST('2023-01-01 10:00:00.000' AS DATETIME2(3)) AS created_on,
7579
CAST('2023-01-02 11:30:00.500' AS DATETIME2(3)) AS last_updated
7680
"#
77-
)
78-
.fetch_one(&mut conn)
79-
.await?;
81+
)
82+
.fetch_one(&mut conn)
83+
.await?;
8084

81-
assert_eq!(result.id, 1);
82-
assert_eq!(result.config_key, "test_key");
83-
assert_eq!(result.config_value, "test_value");
84-
assert_eq!(result.created_on, Some(expected_created_on));
85-
assert_eq!(result.last_updated, Some(expected_last_updated));
85+
assert_eq!(result.id, 1);
86+
assert_eq!(result.config_key, "test_key");
87+
assert_eq!(result.config_value, "test_value");
88+
assert_eq!(result.created_on, Some(expected_created_on));
89+
assert_eq!(result.last_updated, Some(expected_last_updated));
8690

87-
Ok(())
91+
Ok(())
92+
}
8893
}

0 commit comments

Comments
 (0)