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
42
use crate::{DbBackend, Statement};
use sea_query::{Value, Values};
#[derive(Debug, Clone, PartialEq)]
pub struct Transaction {
stmts: Vec<Statement>,
}
impl Transaction {
pub fn from_sql_and_values<I>(db_backend: DbBackend, sql: &str, values: I) -> Self
where
I: IntoIterator<Item = Value>,
{
Self::one(Statement::from_string_values_tuple(
db_backend,
(sql.to_string(), Values(values.into_iter().collect())),
))
}
pub fn one(stmt: Statement) -> Self {
Self { stmts: vec![stmt] }
}
pub fn many<I>(stmts: I) -> Self
where
I: IntoIterator<Item = Statement>,
{
Self {
stmts: stmts.into_iter().collect(),
}
}
pub fn wrap<I>(stmts: I) -> Vec<Self>
where
I: IntoIterator<Item = Statement>,
{
stmts.into_iter().map(Self::one).collect()
}
}