[MySQL] Add fetch_optional, fix encode/decode for integers

This commit is contained in:
Ryan Leckey
2019-12-02 22:14:41 -08:00
parent 6925d5999c
commit bf4f65ea2f
7 changed files with 117 additions and 17 deletions

30
tests/mysql-types.rs Normal file
View File

@@ -0,0 +1,30 @@
use sqlx::{Connection, MariaDb, Row};
use std::env;
macro_rules! test {
($name:ident: $ty:ty: $($text:literal == $value:expr),+) => {
#[async_std::test]
async fn $name () -> sqlx::Result<()> {
let mut conn =
Connection::<MariaDb>::open(&env::var("DATABASE_URL").unwrap()).await?;
$(
let row = sqlx::query(&format!("SELECT {} = ?, ?", $text))
.bind($value)
.bind($value)
.fetch_one(&mut conn)
.await?;
assert_eq!(row.get::<i32>(0), 1);
assert!($value == row.get::<$ty>(1));
)+
Ok(())
}
}
}
test!(mysql_bool: bool: "false" == false, "true" == true);
test!(mysql_long: i32: "2141512" == 2141512_i32);