forked from transact-rs/sqlx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery.rs
More file actions
54 lines (46 loc) · 1.22 KB
/
Copy pathquery.rs
File metadata and controls
54 lines (46 loc) · 1.22 KB
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
use crate::database::Database;
use crate::error::Error;
use crate::arguments::Arguments;
use crate::execute::Execute;
use crate::executor::Executor;
use crate::to_value::ToValue;
pub struct Query<'q, DB: Database> {
sql: &'q str,
arguments: Arguments<'q, DB>,
}
impl<'q, DB: Database> Query<'q, DB> {
pub fn bind<T: ToValue<DB>>(mut self, value: &'q T) -> Self {
self.arguments.bind(value);
self
}
pub fn bind_erased<T: ToValue<DB>>(mut self, value: &'q T) -> Self {
self.arguments.bind(value);
self
}
pub fn bind_unchecked<T: ToValue<DB>>(mut self, value: &'q T) -> Self {
self.arguments.bind(value);
self
}
#[inline]
pub async fn execute<'e, E>(self, executor: E) -> Result<u64, Error>
where
E: Executor<'e, Database = DB>,
{
executor.execute(self).await
}
}
impl<'q, DB: Database> Execute<'q, DB> for Query<'q, DB> {
fn sql(&self) -> &'q str {
self.sql
}
fn arguments(&'q mut self) -> Option<&'q Arguments<'q, DB>> {
Some(&self.arguments)
}
}
#[inline]
pub fn query<'q, DB: Database>(sql: &'q str) -> Query<'q, DB> {
Query {
sql,
arguments: Arguments::new(),
}
}