Skip to content

Commit

Permalink
Add i8, date, time, and datetime (chrono) in query! for MySQL and rem…
Browse files Browse the repository at this point in the history
…ove bool
  • Loading branch information
mehcode committed Jan 15, 2020
1 parent 684068a commit dcd3ed3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
7 changes: 0 additions & 7 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ uuid = [ "sqlx-core/uuid", "sqlx-macros/uuid" ]
sqlx-core = { version = "=0.1.4", path = "sqlx-core" }
sqlx-macros = { version = "0.1.1", path = "sqlx-macros", optional = true }
proc-macro-hack = { version = "0.5.11", optional = true }
hex = "0.4.0"

[dev-dependencies]
anyhow = "1.0.26"
Expand Down Expand Up @@ -79,7 +78,7 @@ required-features = [ "mysql" ]

[[test]]
name = "mysql-types-chrono"
required-features = [ "mysql", "chrono" ]
required-features = [ "mysql", "chrono", "macros" ]

[profile.release]
lto = true
21 changes: 19 additions & 2 deletions sqlx-macros/src/database/mysql.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
impl_database_ext! {
sqlx::MySql {
bool,
String,
// TODO: Add after the new type refactor
// u8,
// u16,
// u32,
// u64,
i8,
i16,
i32,
i64,
f32,
f64
f64,

#[cfg(feature = "chrono")]
sqlx::types::chrono::NaiveTime,

#[cfg(feature = "chrono")]
sqlx::types::chrono::NaiveDate,

#[cfg(feature = "chrono")]
sqlx::types::chrono::NaiveDateTime,

#[cfg(feature = "chrono")]
sqlx::types::chrono::DateTime<sqlx::types::chrono::Utc>,
},
ParamChecking::Weak
}
8 changes: 3 additions & 5 deletions tests/mysql-types-chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ async fn mysql_chrono_date() -> anyhow::Result<()> {

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

let row = sqlx::query("SELECT DATE '2019-01-02' = ?, ?")
.bind(&value)
.bind(&value)
let row = sqlx::query!("SELECT (DATE '2019-01-02' = ?) as _1, CAST(? AS DATE) as _2", value, value)
.fetch_one(&mut conn)
.await?;

assert!(row.get::<bool, _>(0));
assert_eq!(value, row.get(1));
assert!(row._1 != 0);
assert_eq!(value, row._2);

Ok(())
}
Expand Down

0 comments on commit dcd3ed3

Please sign in to comment.