mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-19 08:39:44 +00:00
macros: add proper test for sqlite using database file
This commit is contained in:
committed by
Ryan Leckey
parent
8328e07c97
commit
6cea7e2c1b
BIN
tests/fixtures/test-db.sqlite
vendored
Normal file
BIN
tests/fixtures/test-db.sqlite
vendored
Normal file
Binary file not shown.
@@ -3,13 +3,11 @@ use sqlx_test::new;
|
||||
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
|
||||
async fn macro_select_from_cte() -> anyhow::Result<()> {
|
||||
async fn macro_select() -> anyhow::Result<()> {
|
||||
let mut conn = new::<Sqlite>().await?;
|
||||
let account = sqlx::query!(
|
||||
"with accounts(id, name) as (values (1, 'Herp Derpinson')) select * from accounts"
|
||||
)
|
||||
.fetch_one(&mut conn)
|
||||
.await?;
|
||||
let account = sqlx::query!("select * from accounts")
|
||||
.fetch_one(&mut conn)
|
||||
.await?;
|
||||
|
||||
println!("{:?}", account);
|
||||
println!("{}: {}", account.id, account.name);
|
||||
@@ -19,14 +17,11 @@ async fn macro_select_from_cte() -> anyhow::Result<()> {
|
||||
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
|
||||
async fn macro_select_from_cte_bind() -> anyhow::Result<()> {
|
||||
async fn macro_select_bind() -> anyhow::Result<()> {
|
||||
let mut conn = new::<Sqlite>().await?;
|
||||
let account = sqlx::query!(
|
||||
"with accounts(id, name) as (select 1, 'Herp Derpinson') select * from accounts where id = ?",
|
||||
1i32
|
||||
)
|
||||
.fetch_one(&mut conn)
|
||||
.await?;
|
||||
let account = sqlx::query!("select * from accounts where id = ?", 1i32)
|
||||
.fetch_one(&mut conn)
|
||||
.await?;
|
||||
|
||||
println!("{:?}", account);
|
||||
println!("{}: {}", account.id, account.name);
|
||||
@@ -36,8 +31,8 @@ async fn macro_select_from_cte_bind() -> anyhow::Result<()> {
|
||||
|
||||
#[derive(Debug)]
|
||||
struct RawAccount {
|
||||
r#type: i32,
|
||||
name: Option<String>,
|
||||
id: i32,
|
||||
name: String,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
@@ -45,15 +40,12 @@ struct RawAccount {
|
||||
async fn test_query_as_raw() -> anyhow::Result<()> {
|
||||
let mut conn = new::<Sqlite>().await?;
|
||||
|
||||
let account = sqlx::query_as!(
|
||||
RawAccount,
|
||||
"SELECT * from (select 1 as type, cast(null as char) as name) accounts"
|
||||
)
|
||||
.fetch_one(&mut conn)
|
||||
.await?;
|
||||
let account = sqlx::query_as!(RawAccount, "SELECT * from accounts")
|
||||
.fetch_one(&mut conn)
|
||||
.await?;
|
||||
|
||||
assert_eq!(None, account.name);
|
||||
assert_eq!(1, account.r#type);
|
||||
assert_eq!(1, account.id);
|
||||
assert_eq!("Herp Derpinson", account.name);
|
||||
|
||||
println!("{:?}", account);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user