@@ -8,377 +8,6 @@ use crate::{
88 value_converter:: { convert_parameters, postgres_to_py, PythonDTO , QueryParameter } ,
99} ;
1010
11- // #[allow(clippy::module_name_repetitions)]
12- // pub struct RustConnection {
13- // pub db_client: Arc<tokio::sync::RwLock<Object>>,
14- // }
15-
16- // impl RustConnection {
17- // #[must_use]
18- // pub fn new(db_client: Arc<tokio::sync::RwLock<Object>>) -> Self {
19- // RustConnection { db_client }
20- // }
21- // /// Execute statement with or witout parameters.
22- // ///
23- // /// # Errors
24- // ///
25- // /// May return Err Result if
26- // /// 1) Cannot convert incoming parameters
27- // /// 2) Cannot prepare statement
28- // /// 3) Cannot execute query
29- // pub async fn inner_execute(
30- // &self,
31- // querystring: String,
32- // parameters: Vec<PythonDTO>,
33- // prepared: bool,
34- // ) -> RustPSQLDriverPyResult<PSQLDriverPyQueryResult> {
35- // let db_client = self.db_client.read().await;
36- // let vec_parameters: Vec<&QueryParameter> = parameters
37- // .iter()
38- // .map(|param| param as &QueryParameter)
39- // .collect();
40-
41- // let result = if prepared {
42- // db_client
43- // .query(
44- // &db_client.prepare_cached(&querystring).await?,
45- // &vec_parameters.into_boxed_slice(),
46- // )
47- // .await?
48- // } else {
49- // db_client
50- // .query(&querystring, &vec_parameters.into_boxed_slice())
51- // .await?
52- // };
53-
54- // Ok(PSQLDriverPyQueryResult::new(result))
55- // }
56-
57- // /// Execute querystring with many parameters.
58- // ///
59- // /// Method doesn't acquire lock on any structure fields.
60- // /// It prepares and caches querystring in the inner Object object.
61- // ///
62- // /// Then execute the query.
63- // ///
64- // /// # Errors
65- // /// May return Err Result if:
66- // /// 1) Transaction is not started
67- // /// 2) Transaction is done already
68- // /// 3) Can not create/retrieve prepared statement
69- // /// 4) Can not execute statement
70- // pub async fn inner_execute_many(
71- // &self,
72- // querystring: String,
73- // parameters: Vec<Vec<PythonDTO>>,
74- // prepared: bool,
75- // ) -> RustPSQLDriverPyResult<()> {
76- // let mut db_client = self.db_client.write().await;
77- // let transaction = db_client.transaction().await?;
78- // for single_parameters in parameters {
79- // if prepared {
80- // transaction
81- // .query(
82- // &transaction.prepare_cached(&querystring).await?,
83- // &single_parameters
84- // .iter()
85- // .map(|p| p as &QueryParameter)
86- // .collect::<Vec<_>>(),
87- // )
88- // .await?;
89- // } else {
90- // transaction
91- // .query(
92- // &querystring,
93- // &single_parameters
94- // .iter()
95- // .map(|p| p as &QueryParameter)
96- // .collect::<Vec<_>>(),
97- // )
98- // .await?;
99- // }
100- // }
101-
102- // transaction.commit().await?;
103-
104- // Ok(())
105- // }
106-
107- // /// Fetch exaclty single row from query.
108- // ///
109- // /// Method doesn't acquire lock on any structure fields.
110- // /// It prepares and caches querystring in the inner Object object.
111- // ///
112- // /// Then execute the query.
113- // ///
114- // /// # Errors
115- // /// May return Err Result if:
116- // /// 1) Transaction is not started
117- // /// 2) Transaction is done already
118- // /// 3) Can not create/retrieve prepared statement
119- // /// 4) Can not execute statement
120- // /// 5) Query returns more than one row
121- // pub async fn inner_fetch_row(
122- // &self,
123- // querystring: String,
124- // parameters: Vec<PythonDTO>,
125- // prepared: bool,
126- // ) -> RustPSQLDriverPyResult<PSQLDriverSinglePyQueryResult> {
127- // let vec_parameters: Vec<&QueryParameter> = parameters
128- // .iter()
129- // .map(|param| param as &QueryParameter)
130- // .collect();
131- // let db_client_guard = self.db_client.read().await;
132-
133- // let result = if prepared {
134- // db_client_guard
135- // .query_one(
136- // &db_client_guard.prepare_cached(&querystring).await?,
137- // &vec_parameters.into_boxed_slice(),
138- // )
139- // .await?
140- // } else {
141- // db_client_guard
142- // .query_one(&querystring, &vec_parameters.into_boxed_slice())
143- // .await?
144- // };
145-
146- // Ok(PSQLDriverSinglePyQueryResult::new(result))
147- // }
148-
149- // /// Execute querystring with parameters.
150- // ///
151- // /// Method doesn't acquire lock on any structure fields.
152- // /// It prepares and caches querystring in the inner Object object.
153- // ///
154- // /// Then execute the query.
155- // ///
156- // /// It returns `Vec<Row>` instead of `PSQLDriverPyQueryResult`.
157- // ///
158- // /// # Errors
159- // /// May return Err Result if:
160- // /// 1) Transaction is not started
161- // /// 2) Transaction is done already
162- // /// 3) Can not create/retrieve prepared statement
163- // /// 4) Can not execute statement
164- // pub async fn inner_execute_raw(
165- // &self,
166- // querystring: String,
167- // parameters: Vec<PythonDTO>,
168- // prepared: bool,
169- // ) -> RustPSQLDriverPyResult<Vec<Row>> {
170- // let db_client_guard = self.db_client.read().await;
171- // let vec_parameters: Vec<&QueryParameter> = parameters
172- // .iter()
173- // .map(|param| param as &QueryParameter)
174- // .collect();
175-
176- // let result = if prepared {
177- // db_client_guard
178- // .query(
179- // &db_client_guard.prepare_cached(&querystring).await?,
180- // &vec_parameters.into_boxed_slice(),
181- // )
182- // .await?
183- // } else {
184- // db_client_guard
185- // .query(&querystring, &vec_parameters.into_boxed_slice())
186- // .await?
187- // };
188-
189- // Ok(result)
190- // }
191-
192- // /// Return new instance of transaction.
193- // #[must_use]
194- // pub fn inner_transaction(
195- // &self,
196- // isolation_level: Option<IsolationLevel>,
197- // read_variant: Option<ReadVariant>,
198- // deferrable: Option<bool>,
199- // ) -> Transaction {
200- // let inner_transaction = RustTransaction::new(
201- // Arc::new(RustConnection::new(self.db_client.clone())),
202- // false,
203- // false,
204- // Arc::new(tokio::sync::RwLock::new(HashSet::new())),
205- // isolation_level,
206- // read_variant,
207- // deferrable,
208- // );
209-
210- // Transaction::new(
211- // Arc::new(tokio::sync::RwLock::new(inner_transaction)),
212- // Default::default(),
213- // )
214- // }
215- // }
216-
217- // #[pyclass()]
218- // pub struct Connection {
219- // pub inner_connection: Arc<RustConnection>,
220- // }
221-
222- // impl Connection {
223- // #[must_use]
224- // pub fn new(inner_connection: Arc<RustConnection>) -> Self {
225- // Connection { inner_connection }
226- // }
227- // }
228-
229- // #[pymethods]
230- // impl Connection {
231- // /// Execute statement with or witout parameters.
232- // ///
233- // /// # Errors
234- // ///
235- // /// May return Err Result if
236- // /// 1) Cannot convert incoming parameters
237- // /// 2) Cannot prepare statement
238- // /// 3) Cannot execute query
239- // pub fn execute<'a>(
240- // &'a self,
241- // py: Python<'a>,
242- // querystring: String,
243- // parameters: Option<&PyAny>,
244- // prepared: Option<bool>,
245- // ) -> RustPSQLDriverPyResult<&PyAny> {
246- // let mut params: Vec<PythonDTO> = vec![];
247- // if let Some(parameters) = parameters {
248- // params = convert_parameters(parameters)?;
249- // }
250- // let inner_connection_arc = self.inner_connection.clone();
251- // rustdriver_future(py, async move {
252- // inner_connection_arc
253- // .inner_execute(querystring, params, prepared.unwrap_or(true))
254- // .await
255- // })
256- // }
257-
258- // /// Execute querystring with parameters.
259- // ///
260- // /// It converts incoming parameters to rust readable
261- // /// and then execute the query with them.
262- // ///
263- // /// # Errors
264- // ///
265- // /// May return Err Result if:
266- // /// 1) Cannot convert python parameters
267- // /// 2) Cannot execute querystring.
268- // pub fn execute_many<'a>(
269- // &'a self,
270- // py: Python<'a>,
271- // querystring: String,
272- // parameters: Option<&'a PyList>,
273- // prepared: Option<bool>,
274- // ) -> RustPSQLDriverPyResult<&PyAny> {
275- // let transaction_arc = self.inner_connection.clone();
276- // let mut params: Vec<Vec<PythonDTO>> = vec![];
277- // if let Some(parameters) = parameters {
278- // for single_parameters in parameters {
279- // params.push(convert_parameters(single_parameters)?);
280- // }
281- // }
282-
283- // rustdriver_future(py, async move {
284- // transaction_arc
285- // .inner_execute_many(querystring, params, prepared.unwrap_or(true))
286- // .await
287- // })
288- // }
289-
290- // / Execute querystring with parameters and return first row.
291- // /
292- // / It converts incoming parameters to rust readable,
293- // / executes query with them and returns first row of response.
294- // /
295- // / # Errors
296- // /
297- // / May return Err Result if:
298- // / 1) Cannot convert python parameters
299- // / 2) Cannot execute querystring.
300- // / 3) Query returns more than one row.
301- // pub fn fetch_row<'a>(
302- // &'a self,
303- // py: Python<'a>,
304- // querystring: String,
305- // parameters: Option<&'a PyList>,
306- // prepared: Option<bool>,
307- // ) -> RustPSQLDriverPyResult<&PyAny> {
308- // let transaction_arc = self.inner_connection.clone();
309- // let mut params: Vec<PythonDTO> = vec![];
310- // if let Some(parameters) = parameters {
311- // params = convert_parameters(parameters)?;
312- // }
313-
314- // rustdriver_future(py, async move {
315- // transaction_arc
316- // .inner_fetch_row(querystring, params, prepared.unwrap_or(true))
317- // .await
318- // })
319- // }
320-
321- // /// Execute querystring with parameters and return first value in the first row.
322- // ///
323- // /// It converts incoming parameters to rust readable,
324- // /// executes query with them and returns first row of response.
325- // ///
326- // /// # Errors
327- // ///
328- // /// May return Err Result if:
329- // /// 1) Cannot convert python parameters
330- // /// 2) Cannot execute querystring.
331- // /// 3) Query returns more than one row
332- // pub fn fetch_val<'a>(
333- // &'a self,
334- // py: Python<'a>,
335- // querystring: String,
336- // parameters: Option<&'a PyList>,
337- // prepared: Option<bool>,
338- // ) -> RustPSQLDriverPyResult<&PyAny> {
339- // let transaction_arc = self.inner_connection.clone();
340- // let mut params: Vec<PythonDTO> = vec![];
341- // if let Some(parameters) = parameters {
342- // params = convert_parameters(parameters)?;
343- // }
344-
345- // rustdriver_future(py, async move {
346- // let first_row = transaction_arc
347- // .inner_fetch_row(querystring, params, prepared.unwrap_or(true))
348- // .await?
349- // .get_inner();
350- // Python::with_gil(|py| match first_row.columns().first() {
351- // Some(first_column) => postgres_to_py(py, &first_row, first_column, 0),
352- // None => Ok(py.None()),
353- // })
354- // })
355- // }
356-
357- // /// Return new instance of transaction.
358- // #[must_use]
359- // pub fn transaction(
360- // &self,
361- // isolation_level: Option<IsolationLevel>,
362- // read_variant: Option<ReadVariant>,
363- // deferrable: Option<bool>,
364- // ) -> Transaction {
365- // let inner_transaction = RustTransaction::new(
366- // self.inner_connection.clone(),
367- // false,
368- // false,
369- // Arc::new(tokio::sync::RwLock::new(HashSet::new())),
370- // isolation_level,
371- // read_variant,
372- // deferrable,
373- // );
374-
375- // Transaction::new(
376- // Arc::new(tokio::sync::RwLock::new(inner_transaction)),
377- // Default::default(),
378- // )
379- // }
380- // }
381-
38211#[ pyclass]
38312pub struct Connection {
38413 pub db_client : Arc < Object > ,
0 commit comments