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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use super::{ResultSet, Transaction, DBIO};
use crate::ast::*;
pub trait GetRow {
fn get_result_row(&self) -> crate::Result<Vec<ParameterizedValue<'static>>>;
}
pub trait TakeRow {
fn take_result_row(&mut self) -> crate::Result<Vec<ParameterizedValue<'static>>>;
}
pub trait ToColumnNames {
fn to_column_names(&self) -> Vec<String>;
}
pub trait Queryable
where
Self: Sync,
{
fn execute<'a>(&'a self, q: Query<'a>) -> DBIO<'a, Option<Id>>;
fn query<'a>(&'a self, q: Query<'a>) -> DBIO<'a, ResultSet>;
fn query_raw<'a>(&'a self, sql: &'a str, params: &'a [ParameterizedValue<'a>]) -> DBIO<'a, ResultSet>;
fn execute_raw<'a>(&'a self, sql: &'a str, params: &'a [ParameterizedValue<'a>]) -> DBIO<'a, u64>;
fn raw_cmd<'a>(&'a self, cmd: &'a str) -> DBIO<'a, ()>;
fn select<'a>(&'a self, q: Select<'a>) -> DBIO<'a, ResultSet> {
self.query(q.into())
}
fn insert<'a>(&'a self, q: Insert<'a>) -> DBIO<'a, Option<Id>> {
self.execute(q.into())
}
fn update<'a>(&'a self, q: Update<'a>) -> DBIO<'a, ()> {
DBIO::new(async move {
self.execute(q.into()).await?;
Ok(())
})
}
fn delete<'a>(&'a self, q: Delete<'a>) -> DBIO<'a, ()> {
DBIO::new(async move {
self.execute(q.into()).await?;
Ok(())
})
}
}
pub trait TransactionCapable: Queryable
where
Self: Sized + Sync,
{
fn start_transaction(&self) -> DBIO<Transaction> {
DBIO::new(async move { Transaction::new(self).await })
}
}