Skip to content

Commit 306ed97

Browse files
committed
Add i8, date, time, and datetime (chrono) in query! for MySQL and remove bool
1 parent 684068a commit 306ed97

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ uuid = [ "sqlx-core/uuid", "sqlx-macros/uuid" ]
4444
sqlx-core = { version = "=0.1.4", path = "sqlx-core" }
4545
sqlx-macros = { version = "0.1.1", path = "sqlx-macros", optional = true }
4646
proc-macro-hack = { version = "0.5.11", optional = true }
47-
hex = "0.4.0"
4847

4948
[dev-dependencies]
5049
anyhow = "1.0.26"
@@ -79,7 +78,7 @@ required-features = [ "mysql" ]
7978

8079
[[test]]
8180
name = "mysql-types-chrono"
82-
required-features = [ "mysql", "chrono" ]
81+
required-features = [ "mysql", "chrono", "macros" ]
8382

8483
[profile.release]
8584
lto = true

sqlx-macros/src/database/mysql.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
impl_database_ext! {
22
sqlx::MySql {
3-
bool,
43
String,
4+
// TODO: Add after the new type refactor
5+
// u8,
6+
// u16,
7+
// u32,
8+
// u64,
9+
i8,
510
i16,
611
i32,
712
i64,
813
f32,
9-
f64
14+
f64,
15+
16+
#[cfg(feature = "chrono")]
17+
sqlx::types::chrono::NaiveTime,
18+
19+
#[cfg(feature = "chrono")]
20+
sqlx::types::chrono::NaiveDate,
21+
22+
#[cfg(feature = "chrono")]
23+
sqlx::types::chrono::NaiveDateTime,
24+
25+
#[cfg(feature = "chrono")]
26+
sqlx::types::chrono::DateTime<sqlx::types::chrono::Utc>,
1027
},
1128
ParamChecking::Weak
1229
}

tests/mysql-types-chrono.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ async fn mysql_chrono_date() -> anyhow::Result<()> {
1111

1212
let value = NaiveDate::from_ymd(2019, 1, 2);
1313

14-
let row = sqlx::query("SELECT DATE '2019-01-02' = ?, ?")
15-
.bind(&value)
16-
.bind(&value)
17-
.fetch_one(&mut conn)
18-
.await?;
14+
let row = sqlx::query!(
15+
"SELECT (DATE '2019-01-02' = ?) as _1, CAST(? AS DATE) as _2",
16+
value,
17+
value
18+
)
19+
.fetch_one(&mut conn)
20+
.await?;
1921

20-
assert!(row.get::<bool, _>(0));
21-
assert_eq!(value, row.get(1));
22+
assert!(row._1 != 0);
23+
assert_eq!(value, row._2);
2224

2325
Ok(())
2426
}

0 commit comments

Comments
 (0)