forked from transact-rs/sqlx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecute.rs
More file actions
103 lines (86 loc) · 2.49 KB
/
Copy pathexecute.rs
File metadata and controls
103 lines (86 loc) · 2.49 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
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
use crate::{Arguments, Database};
/// A type that may be executed against a SQL executor.
pub trait Execute<'q, 'a, Db: Database>: Send + Sync {
/// Returns the SQL to be executed.
fn sql(&self) -> &str;
/// Returns the arguments for bind variables in the SQL.
///
/// A value of `None` for arguments is different from an empty list of
/// arguments. The latter instructs SQLx to prepare the SQL command
/// (with no arguments) and then execute it. The former
/// will result in a simple and unprepared SQL command.
///
fn arguments(&self) -> Option<&'_ Arguments<'a, Db>> {
None
}
/// Returns `true` if the SQL statement should be cached for re-use.
fn persistent(&self) -> bool {
true
}
}
impl<'q, Db: Database> Execute<'q, '_, Db> for &'q str {
fn sql(&self) -> &str {
self
}
}
impl<Db: Database> Execute<'_, '_, Db> for String {
fn sql(&self) -> &str {
self
}
}
impl<'q, 'a, Db: Database, E: Execute<'q, 'a, Db>> Execute<'q, 'a, Db> for &'_ E {
fn sql(&self) -> &str {
(*self).sql()
}
fn arguments(&self) -> Option<&'_ Arguments<'a, Db>> {
(*self).arguments()
}
}
impl<'q, 'a, Db: Database> Execute<'q, 'a, Db> for (&'q str, Arguments<'a, Db>) {
fn sql(&self) -> &str {
self.0
}
fn arguments(&self) -> Option<&'_ Arguments<'a, Db>> {
Some(&self.1)
}
}
impl<'q, 'a, Db: Database> Execute<'q, 'a, Db> for (&'q String, Arguments<'a, Db>) {
fn sql(&self) -> &str {
self.0
}
fn arguments(&self) -> Option<&'_ Arguments<'a, Db>> {
Some(&self.1)
}
}
impl<'a, Db: Database> Execute<'_, 'a, Db> for (String, Arguments<'a, Db>) {
fn sql(&self) -> &str {
&self.0
}
fn arguments(&self) -> Option<&'_ Arguments<'a, Db>> {
Some(&self.1)
}
}
impl<'q, 'a, Db: Database> Execute<'q, 'a, Db> for (&'q str, &'a Arguments<'a, Db>) {
fn sql(&self) -> &str {
self.0
}
fn arguments(&self) -> Option<&'_ Arguments<'a, Db>> {
Some(self.1)
}
}
impl<'q, 'a, Db: Database> Execute<'q, 'a, Db> for (&'q String, &'a Arguments<'a, Db>) {
fn sql(&self) -> &str {
self.0
}
fn arguments(&self) -> Option<&'_ Arguments<'a, Db>> {
Some(self.1)
}
}
impl<'a, Db: Database> Execute<'_, 'a, Db> for (String, &'a Arguments<'a, Db>) {
fn sql(&self) -> &str {
&self.0
}
fn arguments(&self) -> Option<&'_ Arguments<'a, Db>> {
Some(self.1)
}
}