@@ -7,7 +7,7 @@ use polodb_core::options::UpdateOptions;
77use polodb_core:: { Collection , CollectionT , Database } ;
88use pyo3:: exceptions:: PyOSError ;
99use pyo3:: exceptions:: PyRuntimeError ; // Import PyRuntimeError for error handling
10- use pyo3:: prelude:: * ;
10+ use pyo3:: { prelude:: * , IntoPyObjectExt } ;
1111use pyo3:: types:: { PyDict , PyList } ;
1212use std:: borrow:: Borrow ;
1313use std:: path:: Path ;
@@ -31,7 +31,7 @@ impl PyCollection {
3131
3232 // Example: Create a Python object or interact with the Python runtime.
3333 let bson_vec_docs: Vec < Document > =
34- convert_py_list_to_vec_document ( doc. to_object ( py) . as_any ( ) ) ;
34+ convert_py_list_to_vec_document ( & doc. into_py_any ( py) . unwrap ( ) ) ;
3535 // let bson_doc = convert_py_to_bson(doc);
3636 match self . inner . insert_many ( bson_vec_docs) {
3737 Ok ( result) => {
@@ -42,7 +42,7 @@ impl PyCollection {
4242 dict. set_item ( key, bson_to_py_obj ( py, value) ) . unwrap ( ) ;
4343 }
4444
45- Ok ( dict. to_object ( py) )
45+ Ok ( dict. into_py_any ( py) . unwrap ( ) )
4646 }
4747 Err ( e) => {
4848 // Raise a Python exception on error
@@ -55,7 +55,7 @@ impl PyCollection {
5555 pub fn insert_one ( & self , doc : Py < PyDict > ) -> PyResult < PyObject > {
5656 // Acquire the Python GIL (Global Interpreter Lock)
5757 Python :: with_gil ( |py| {
58- let bson_doc: Document = match convert_py_obj_to_document ( doc. to_object ( py) . as_any ( ) ) {
58+ let bson_doc: Document = match convert_py_obj_to_document ( & doc. into_py_any ( py) . unwrap ( ) ) {
5959 Ok ( d) => d,
6060 Err ( e) => return Err ( PyRuntimeError :: new_err ( format ! ( "Insert many error: {}" , e) ) ) ,
6161 } ;
@@ -67,7 +67,7 @@ impl PyCollection {
6767 let dict = PyDict :: new ( py) ;
6868 let dict_ref = dict. borrow ( ) ;
6969 dict_ref. set_item ( "inserted_id" , py_inserted_id) ?;
70- Ok ( dict. to_object ( py) )
70+ Ok ( dict. into_py_any ( py) . unwrap ( ) )
7171
7272 // Ok(Py::new(py, result)?.to_object(py))
7373 }
@@ -86,15 +86,15 @@ impl PyCollection {
8686 update : Py < PyDict > ,
8787 ) -> PyResult < Option < PyObject > > {
8888 // Convert PyDict to BSON Document
89- let filter_doc = convert_py_obj_to_document ( filter. to_object ( py) . as_any ( ) ) ?;
90- let update_doc = convert_py_obj_to_document ( update. to_object ( py) . as_any ( ) ) ?;
89+ let filter_doc = convert_py_obj_to_document ( & filter. into_py_any ( py) . unwrap ( ) ) ?;
90+ let update_doc = convert_py_obj_to_document ( & update. into_py_any ( py) . unwrap ( ) ) ?;
9191
9292 // Call the Rust method `find_one`
9393 match self . inner . update_one ( filter_doc, update_doc) {
9494 Ok ( update_result) => {
9595 // Convert BSON Document to Python Dict
9696 let py_result = update_result_to_pydict ( py, update_result) . unwrap ( ) ;
97- Ok ( Some ( py_result. to_object ( py) ) )
97+ Ok ( Some ( py_result. into_py_any ( py) . unwrap ( ) ) )
9898 }
9999 Err ( err) => Err ( PyErr :: new :: < pyo3:: exceptions:: PyRuntimeError , _ > ( format ! (
100100 "Update one error: {}" ,
@@ -110,15 +110,15 @@ impl PyCollection {
110110 update : Py < PyDict > ,
111111 ) -> PyResult < Option < PyObject > > {
112112 // Convert PyDict to BSON Document
113- let filter_doc = convert_py_obj_to_document ( filter. to_object ( py) . as_any ( ) ) ?;
114- let update_doc = convert_py_obj_to_document ( update. to_object ( py) . as_any ( ) ) ?;
113+ let filter_doc = convert_py_obj_to_document ( & filter. into_py_any ( py) . unwrap ( ) ) ?;
114+ let update_doc = convert_py_obj_to_document ( & update. into_py_any ( py) . unwrap ( ) ) ?;
115115
116116 // Call the Rust method `find_one`
117117 match self . inner . update_many ( filter_doc, update_doc) {
118118 Ok ( update_result) => {
119119 // Convert BSON Document to Python Dict
120120 let py_result = update_result_to_pydict ( py, update_result) . unwrap ( ) ;
121- Ok ( Some ( py_result. to_object ( py) ) )
121+ Ok ( Some ( py_result. into_py_any ( py) . unwrap ( ) ) )
122122 }
123123 Err ( err) => Err ( PyErr :: new :: < pyo3:: exceptions:: PyRuntimeError , _ > ( format ! (
124124 "Update many error: {}" ,
@@ -134,8 +134,8 @@ impl PyCollection {
134134 update : Py < PyDict > ,
135135 ) -> PyResult < Option < PyObject > > {
136136 // Convert PyDict to BSON Document
137- let filter_doc = convert_py_obj_to_document ( filter. to_object ( py) . as_any ( ) ) ?;
138- let update_doc = convert_py_obj_to_document ( update. to_object ( py) . as_any ( ) ) ?;
137+ let filter_doc = convert_py_obj_to_document ( & filter. into_py_any ( py) . unwrap ( ) ) ?;
138+ let update_doc = convert_py_obj_to_document ( & update. into_py_any ( py) . unwrap ( ) ) ?;
139139
140140 match self . inner . update_one_with_options (
141141 filter_doc,
@@ -145,7 +145,7 @@ impl PyCollection {
145145 Ok ( update_result) => {
146146 // Convert BSON Document to Python Dict
147147 let py_result = update_result_to_pydict ( py, update_result) . unwrap ( ) ;
148- Ok ( Some ( py_result. to_object ( py) ) )
148+ Ok ( Some ( py_result. into_py_any ( py) . unwrap ( ) ) )
149149 }
150150 Err ( err) => Err ( PyErr :: new :: < pyo3:: exceptions:: PyRuntimeError , _ > ( format ! (
151151 "Upsert one error: {}" ,
@@ -158,7 +158,7 @@ impl PyCollection {
158158 Python :: with_gil ( |py| {
159159
160160 let bson_vec_pipeline: Vec < Document > =
161- convert_py_list_to_vec_document ( pipeline. to_object ( py) . as_any ( ) ) ;
161+ convert_py_list_to_vec_document ( & pipeline. into_py_any ( py) . unwrap ( ) ) ;
162162 match self . inner . aggregate ( bson_vec_pipeline) . run ( ) {
163163 Ok ( result) => {
164164 let vec_result = result. collect :: < Result < Vec < Document > , _ > > ( ) . unwrap ( ) ;
@@ -167,7 +167,7 @@ impl PyCollection {
167167 . into_iter ( )
168168 . map ( |x| document_to_pydict ( py, x) . unwrap ( ) )
169169 . collect ( ) ;
170- Ok ( py_result. to_object ( py) )
170+ Ok ( py_result. into_py_any ( py) . unwrap ( ) )
171171 }
172172 Err ( e) => {
173173 // Raise a Python exception on error
@@ -184,8 +184,8 @@ impl PyCollection {
184184 update : Py < PyDict > ,
185185 ) -> PyResult < Option < PyObject > > {
186186 // Convert PyDict to BSON Document
187- let filter_doc = convert_py_obj_to_document ( filter. to_object ( py) . as_any ( ) ) ?;
188- let update_doc = convert_py_obj_to_document ( update. to_object ( py) . as_any ( ) ) ?;
187+ let filter_doc = convert_py_obj_to_document ( & filter. into_py_any ( py) . unwrap ( ) ) ?;
188+ let update_doc = convert_py_obj_to_document ( & update. into_py_any ( py) . unwrap ( ) ) ?;
189189
190190 // Call the Rust method `find_one`
191191 match self . inner . update_many_with_options (
@@ -196,7 +196,7 @@ impl PyCollection {
196196 Ok ( update_result) => {
197197 // Convert BSON Document to Python Dict
198198 let py_result = update_result_to_pydict ( py, update_result) . unwrap ( ) ;
199- Ok ( Some ( py_result. to_object ( py) ) )
199+ Ok ( Some ( py_result. into_py_any ( py) . unwrap ( ) ) )
200200 }
201201 Err ( err) => Err ( PyErr :: new :: < pyo3:: exceptions:: PyRuntimeError , _ > ( format ! (
202202 "Upsert many error: {}" ,
@@ -207,9 +207,9 @@ impl PyCollection {
207207
208208 pub fn delete_one ( & self , filter : Py < PyDict > ) -> PyResult < PyObject > {
209209 // Acquire the Python GIL (Global Interpreter Lock)
210- // let filter_doc = convert_py_obj_to_document(filter.to_object (py).as_any ())?;
210+ // let filter_doc = convert_py_obj_to_document(& filter.into_py_any (py).unwrap ())?;
211211 Python :: with_gil ( |py| {
212- let bson_doc: Document = match convert_py_obj_to_document ( filter. to_object ( py) . as_any ( ) )
212+ let bson_doc: Document = match convert_py_obj_to_document ( & filter. into_py_any ( py) . unwrap ( ) )
213213 {
214214 Ok ( d) => d,
215215 Err ( e) => return Err ( PyRuntimeError :: new_err ( format ! ( "Delete one : {}" , e) ) ) ,
@@ -219,7 +219,7 @@ impl PyCollection {
219219 Ok ( delete_result) => {
220220 // Create a Python object from the Rust result and return it
221221 let py_result = delete_result_to_pydict ( py, delete_result) . unwrap ( ) ;
222- Ok ( py_result. to_object ( py) )
222+ Ok ( py_result. into_py_any ( py) . unwrap ( ) )
223223
224224 // Ok(Py::new(py, result)?.to_object(py))
225225 }
@@ -234,7 +234,7 @@ impl PyCollection {
234234 pub fn delete_many ( & self , filter : Py < PyDict > ) -> PyResult < PyObject > {
235235 // Acquire the Python GIL (Global Interpreter Lock)
236236 Python :: with_gil ( |py| {
237- let bson_doc: Document = match convert_py_obj_to_document ( filter. to_object ( py) . as_any ( ) )
237+ let bson_doc: Document = match convert_py_obj_to_document ( & filter. into_py_any ( py) . unwrap ( ) )
238238 {
239239 Ok ( d) => d,
240240 Err ( e) => return Err ( PyRuntimeError :: new_err ( format ! ( "Delete many : {}" , e) ) ) ,
@@ -244,7 +244,7 @@ impl PyCollection {
244244 Ok ( delete_result) => {
245245 // Create a Python object from the Rust result and return it
246246 let py_result = delete_result_to_pydict ( py, delete_result) . unwrap ( ) ;
247- Ok ( py_result. to_object ( py) )
247+ Ok ( py_result. into_py_any ( py) . unwrap ( ) )
248248
249249 // Ok(Py::new(py, result)?.to_object(py))
250250 }
@@ -274,14 +274,14 @@ impl PyCollection {
274274
275275 pub fn find_one ( & self , py : Python , filter : Py < PyDict > ) -> PyResult < Option < PyObject > > {
276276 // Convert PyDict to BSON Document
277- let filter_doc = convert_py_obj_to_document ( filter. to_object ( py) . as_any ( ) ) ?;
277+ let filter_doc = convert_py_obj_to_document ( & filter. into_py_any ( py) . unwrap ( ) ) ?;
278278
279279 // Call the Rust method `find_one`
280280 match self . inner . find_one ( filter_doc) {
281281 Ok ( Some ( result_doc) ) => {
282282 // Convert BSON Document to Python Dict
283283 let py_result = document_to_pydict ( py, result_doc) . unwrap ( ) ;
284- Ok ( Some ( py_result. to_object ( py) ) )
284+ Ok ( Some ( py_result. into_py_any ( py) . unwrap ( ) ) )
285285 }
286286 Ok ( None ) => Ok ( None ) , // Return None if no document is found
287287 Err ( err) => Err ( PyErr :: new :: < pyo3:: exceptions:: PyRuntimeError , _ > ( format ! (
@@ -292,7 +292,7 @@ impl PyCollection {
292292 }
293293 pub fn find ( & self , py : Python , filter : Py < PyDict > ) -> PyResult < Option < PyObject > > {
294294 // Convert PyDict to BSON Document
295- let filter_doc = convert_py_obj_to_document ( filter. to_object ( py) . as_any ( ) ) ?;
295+ let filter_doc = convert_py_obj_to_document ( & filter. into_py_any ( py) . unwrap ( ) ) ?;
296296
297297 // Call the Rust method `find_one`
298298 match self . inner . find ( filter_doc) . run ( ) {
@@ -302,7 +302,7 @@ impl PyCollection {
302302 . map ( |x| document_to_pydict ( py, x. unwrap ( ) ) . unwrap ( ) )
303303 . collect ( ) ;
304304 // let py_result = document_to_pydict(py, result_doc).unwrap();
305- Ok ( Some ( py_result. to_object ( py) ) )
305+ Ok ( Some ( py_result. into_py_any ( py) . unwrap ( ) ) )
306306 }
307307 // Ok(None) => Ok(None), // Return None if no document is found
308308 Err ( err) => Err ( PyErr :: new :: < pyo3:: exceptions:: PyRuntimeError , _ > ( format ! (
0 commit comments