1use {
2 crate::{sql::Sql, ConnTrans, Connection, Error, Transaction},
3 std::convert::TryInto,
4};
5
6pub trait Execute<'__query>: Sql<'__query> {
7 fn execute<C: TryInto<ConnTrans<'__query>>>(
8 &'__query self,
9 into_conn_trans: C,
10 ) -> Result<u64, Error>
11 where
12 Error: From<C::Error>,
13 {
14 let conn_trans = into_conn_trans.try_into()?;
15
16 match conn_trans {
17 ConnTrans::Conn(conn) => match conn {
18 #[cfg(feature = "postgresql")]
19 Connection::PostgreSQL(mut conn) => {
20 let modified = conn.execute(
21 self.sql_postgres().as_ref(),
22 self.params_postgres().as_ref(),
23 )?;
24
25 Ok(modified)
26 }
27 #[cfg(feature = "sqlite")]
28 Connection::SQLite(conn) => {
29 let modified =
30 conn.execute(self.sql_sqlite().as_ref(), self.params_sqlite().as_ref())?;
31
32 Ok(modified as u64)
33 }
34 },
35 ConnTrans::Trans(trans) => match trans {
36 #[cfg(feature = "postgresql")]
37 Transaction::PostgreSQL(mut trans) => {
38 let modified = trans.execute(
39 self.sql_postgres().as_ref(),
40 self.params_postgres().as_ref(),
41 )?;
42
43 Ok(modified)
44 }
45 #[cfg(feature = "sqlite")]
46 Transaction::SQLite(trans) => {
47 let modified =
48 trans.execute(self.sql_sqlite().as_ref(), self.params_sqlite().as_ref())?;
49
50 Ok(modified as u64)
51 }
52 },
53 }
54 }
55}