sql_middleware/postgres/typed/
dml.rs1use bb8::PooledConnection;
2
3use crate::middleware::{RowValues, SqlMiddlewareDbError};
4use crate::postgres::query::execute_dml_on_client;
5
6use super::{PgConnection, PgManager};
7
8impl PgConnection<super::core::Idle> {
9 pub async fn execute_batch(&mut self, sql: &str) -> Result<(), SqlMiddlewareDbError> {
14 crate::postgres::executor::execute_batch(self.conn_mut(), sql).await
15 }
16
17 pub async fn dml(
22 &mut self,
23 query: &str,
24 params: &[RowValues],
25 ) -> Result<usize, SqlMiddlewareDbError> {
26 crate::postgres::executor::execute_dml(self.conn_mut(), query, params).await
27 }
28}
29
30impl PgConnection<super::core::InTx> {
31 pub async fn execute_batch(&mut self, sql: &str) -> Result<(), SqlMiddlewareDbError> {
36 self.conn_mut().batch_execute(sql).await.map_err(|e| {
37 SqlMiddlewareDbError::ExecutionError(format!("postgres tx batch error: {e}"))
38 })
39 }
40
41 pub async fn dml(
46 &mut self,
47 query: &str,
48 params: &[RowValues],
49 ) -> Result<usize, SqlMiddlewareDbError> {
50 execute_dml_on_client(self.conn_mut(), query, params, "postgres tx execute error").await
51 }
52}
53
54pub async fn dml(
59 conn: &mut PooledConnection<'_, PgManager>,
60 query: &str,
61 params: &[RowValues],
62) -> Result<usize, SqlMiddlewareDbError> {
63 execute_dml_on_client(conn, query, params, "postgres dml error").await
64}