1
1
use pyo3:: {
2
2
types:: { PyAnyMethods , PyModule , PyModuleMethods } ,
3
- Bound , PyAny , PyResult , Python ,
4
- } ;
5
-
6
- use crate :: {
7
- driver:: connection:: PsqlpyConnection ,
8
- exceptions:: rust_errors:: RustPSQLDriverPyResult ,
9
- query_result:: { PSQLDriverPyQueryResult , PSQLDriverSinglePyQueryResult } ,
10
- value_converter:: { convert_parameters, PythonDTO , QueryParameter } ,
3
+ Bound , PyResult , Python ,
11
4
} ;
12
5
13
6
/// Add new module to the parent one.
@@ -33,104 +26,3 @@ pub fn add_module(
33
26
) ?;
34
27
Ok ( ( ) )
35
28
}
36
-
37
- pub trait ObjectQueryTrait {
38
- fn psqlpy_query_one (
39
- & self ,
40
- querystring : String ,
41
- parameters : Option < pyo3:: Py < PyAny > > ,
42
- prepared : Option < bool > ,
43
- ) -> impl std:: future:: Future < Output = RustPSQLDriverPyResult < PSQLDriverSinglePyQueryResult > > + Send ;
44
-
45
- fn psqlpy_query (
46
- & self ,
47
- querystring : String ,
48
- parameters : Option < pyo3:: Py < PyAny > > ,
49
- prepared : Option < bool > ,
50
- ) -> impl std:: future:: Future < Output = RustPSQLDriverPyResult < PSQLDriverPyQueryResult > > + Send ;
51
-
52
- fn psqlpy_query_simple (
53
- & self ,
54
- querystring : String ,
55
- ) -> impl std:: future:: Future < Output = RustPSQLDriverPyResult < ( ) > > + Send ;
56
- }
57
-
58
- impl ObjectQueryTrait for PsqlpyConnection {
59
- async fn psqlpy_query_one (
60
- & self ,
61
- querystring : String ,
62
- parameters : Option < pyo3:: Py < PyAny > > ,
63
- prepared : Option < bool > ,
64
- ) -> RustPSQLDriverPyResult < PSQLDriverSinglePyQueryResult > {
65
- let mut params: Vec < PythonDTO > = vec ! [ ] ;
66
- if let Some ( parameters) = parameters {
67
- params = convert_parameters ( parameters) ?;
68
- }
69
- let prepared = prepared. unwrap_or ( true ) ;
70
-
71
- let result = if prepared {
72
- self . query_one (
73
- & self . prepare_cached ( & querystring) . await ?,
74
- & params
75
- . iter ( )
76
- . map ( |param| param as & QueryParameter )
77
- . collect :: < Vec < & QueryParameter > > ( )
78
- . into_boxed_slice ( ) ,
79
- )
80
- . await ?
81
- } else {
82
- self . query_one (
83
- & querystring,
84
- & params
85
- . iter ( )
86
- . map ( |param| param as & QueryParameter )
87
- . collect :: < Vec < & QueryParameter > > ( )
88
- . into_boxed_slice ( ) ,
89
- )
90
- . await ?
91
- } ;
92
-
93
- Ok ( PSQLDriverSinglePyQueryResult :: new ( result) )
94
- }
95
-
96
- async fn psqlpy_query (
97
- & self ,
98
- querystring : String ,
99
- parameters : Option < pyo3:: Py < PyAny > > ,
100
- prepared : Option < bool > ,
101
- ) -> RustPSQLDriverPyResult < PSQLDriverPyQueryResult > {
102
- let mut params: Vec < PythonDTO > = vec ! [ ] ;
103
- if let Some ( parameters) = parameters {
104
- params = convert_parameters ( parameters) ?;
105
- }
106
- let prepared = prepared. unwrap_or ( true ) ;
107
-
108
- let result = if prepared {
109
- self . query (
110
- & self . prepare_cached ( & querystring) . await ?,
111
- & params
112
- . iter ( )
113
- . map ( |param| param as & QueryParameter )
114
- . collect :: < Vec < & QueryParameter > > ( )
115
- . into_boxed_slice ( ) ,
116
- )
117
- . await ?
118
- } else {
119
- self . query (
120
- & querystring,
121
- & params
122
- . iter ( )
123
- . map ( |param| param as & QueryParameter )
124
- . collect :: < Vec < & QueryParameter > > ( )
125
- . into_boxed_slice ( ) ,
126
- )
127
- . await ?
128
- } ;
129
-
130
- Ok ( PSQLDriverPyQueryResult :: new ( result) )
131
- }
132
-
133
- async fn psqlpy_query_simple ( & self , querystring : String ) -> RustPSQLDriverPyResult < ( ) > {
134
- self . batch_execute ( querystring. as_str ( ) ) . await
135
- }
136
- }
0 commit comments