forked from SeaQL/sea-orm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexecute_unprepared_tests.rs
41 lines (34 loc) · 1004 Bytes
/
execute_unprepared_tests.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
pub mod common;
pub use common::{features::*, setup::*, TestContext};
use pretty_assertions::assert_eq;
use sea_orm::{entity::prelude::*, ConnectionTrait, DatabaseConnection};
#[sea_orm_macros::test]
#[cfg(any(
feature = "sqlx-mysql",
feature = "sqlx-sqlite",
feature = "sqlx-postgres"
))]
async fn main() -> Result<(), DbErr> {
let ctx = TestContext::new("execute_unprepared_tests").await;
create_tables(&ctx.db).await?;
execute_unprepared(&ctx.db).await?;
ctx.delete().await;
Ok(())
}
pub async fn execute_unprepared(db: &DatabaseConnection) -> Result<(), DbErr> {
use insert_default::*;
db.execute_unprepared(
[
"INSERT INTO insert_default VALUES (1), (2), (3), (4), (5)",
"DELETE FROM insert_default WHERE id % 2 = 0",
]
.join(";")
.as_str(),
)
.await?;
assert_eq!(
Entity::find().all(db).await?,
[Model { id: 1 }, Model { id: 3 }, Model { id: 5 }]
);
Ok(())
}