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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
use std::{
collections::{HashMap, HashSet},
sync::RwLockReadGuard,
};
use toql::{error::ToqlError, alias_format::AliasFormat, prelude::{Cache, Context, SqlArg}, table_mapper_registry::TableMapperRegistry};
use crate::{queryable::Queryable, backend::MySqlAsyncBackend};
pub use mysql_async;
pub use mysql_common::chrono;
#[macro_use]
pub mod access;
pub mod sql_arg;
pub mod error;
pub mod result;
pub mod row;
pub mod backend;
pub mod prelude;
pub mod toql_api;
pub mod queryable;
#[cfg(test)]
mod test;
pub struct MySqlAsync<'a, C>
where
C: Queryable + Send,
{
backend: MySqlAsyncBackend<'a, C>,
}
impl<'a, C> MySqlAsync<'a, C>
where
C: Queryable + Send,
{
pub fn from(conn: C, cache: &'a Cache) -> MySqlAsync<'a, C> {
Self::with_context(conn, cache, Context::default())
}
pub fn conn(&mut self) -> &mut C {
&mut self.backend.conn
}
pub fn into_conn(self) -> C {
self.backend.conn
}
pub fn with_context(conn: C, cache: &'a Cache, context: Context) -> MySqlAsync<'a, C> {
MySqlAsync {
backend: MySqlAsyncBackend {
conn,
cache,
context,
},
}
}
pub fn set_roles(&mut self, roles: HashSet<String>) -> &mut Self {
self.backend.context.roles = roles;
self
}
pub fn registry(
&self,
) -> std::result::Result<RwLockReadGuard<'_, TableMapperRegistry>, ToqlError> {
self.backend.cache.registry.read().map_err(ToqlError::from)
}
pub fn roles(&self) -> &HashSet<String> {
&self.backend.context.roles
}
pub fn alias_format(&self) -> AliasFormat {
self.backend.context.alias_format.to_owned()
}
pub fn aux_params(&self) -> &HashMap<String, SqlArg> {
&self.backend.context.aux_params
}
pub fn set_aux_param(&mut self, name: String, value: SqlArg) {
self.backend.context.aux_params.insert(name, value);
}
}