Skip to content

Commit 007296d

Browse files
committed
LISTEN/NOTIFY funcionality
Signed-off-by: chandr-andr (Kiselev Aleksandr) <chandr@chandr.net>
1 parent f6104bc commit 007296d

File tree

12 files changed

+57
-80
lines changed

12 files changed

+57
-80
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ repos:
5858
- clippy::all
5959
- -W
6060
- clippy::pedantic
61-
- -D
62-
- warnings
6361

6462
- id: check
6563
types:

Cargo.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,8 @@ crate-type = ["cdylib"]
1010

1111
[dependencies]
1212
deadpool-postgres = { git = "https://github.com/chandr-andr/deadpool.git", branch = "psqlpy" }
13-
pyo3 = { version = "*", features = [
14-
"chrono",
15-
"experimental-async",
16-
"rust_decimal",
17-
"py-clone",
18-
"gil-refs",
19-
"macros",
20-
] }
21-
pyo3-async-runtimes = { git = "https://github.com/chandr-andr/pyo3-async-runtimes.git", branch = "main", features = [
13+
pyo3 = { version = "0.23.4", features = ["chrono", "experimental-async", "rust_decimal", "py-clone", "macros"] }
14+
pyo3-async-runtimes = { git = "https://github.com/chandr-andr/pyo3-async-runtimes.git", branch = "psqlpy", features = [
2215
"tokio-runtime",
2316
] }
2417

src/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ pub fn add_module(
2424
child_mod_name: &'static str,
2525
child_mod_builder: impl FnOnce(Python<'_>, &Bound<'_, PyModule>) -> PyResult<()>,
2626
) -> PyResult<()> {
27-
let sub_module = PyModule::new_bound(py, child_mod_name)?;
27+
let sub_module = PyModule::new(py, child_mod_name)?;
2828
child_mod_builder(py, &sub_module)?;
2929
parent_mod.add_submodule(&sub_module)?;
30-
py.import_bound("sys")?.getattr("modules")?.set_item(
30+
py.import("sys")?.getattr("modules")?.set_item(
3131
format!("{}.{}", parent_mod.name()?, child_mod_name),
3232
sub_module,
3333
)?;

src/driver/connection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl Connection {
177177
let (is_exception_none, py_err) = pyo3::Python::with_gil(|gil| {
178178
(
179179
exception.is_none(gil),
180-
PyErr::from_value_bound(exception.into_bound(gil)),
180+
PyErr::from_value(exception.into_bound(gil)),
181181
)
182182
});
183183

src/driver/cursor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl Cursor {
179179
self_.closed,
180180
self_.cursor_name.clone(),
181181
exception.is_none(gil),
182-
PyErr::from_value_bound(exception.into_bound(gil)),
182+
PyErr::from_value(exception.into_bound(gil)),
183183
)
184184
});
185185

src/driver/listener/core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl Listener {
104104
(
105105
self_.connection.db_client(),
106106
exception.is_none(gil),
107-
PyErr::from_value_bound(exception.into_bound(gil)),
107+
PyErr::from_value(exception.into_bound(gil)),
108108
)
109109
});
110110

src/driver/transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl Transaction {
236236
(
237237
self_.check_is_transaction_ready(),
238238
exception.is_none(gil),
239-
PyErr::from_value_bound(exception.into_bound(gil)),
239+
PyErr::from_value(exception.into_bound(gil)),
240240
self_.db_client.clone(),
241241
)
242242
});

src/driver/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ pub fn build_manager(
226226
/// 2) extract boolean
227227
pub fn is_coroutine_function(function: Py<PyAny>) -> RustPSQLDriverPyResult<bool> {
228228
let is_coroutine_function: bool = Python::with_gil(|py| {
229-
let inspect = py.import_bound("inspect")?;
229+
let inspect = py.import("inspect")?;
230230

231231
let is_cor = inspect
232232
.call_method1("iscoroutinefunction", (function,))

src/exceptions/python_errors.rs

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use pyo3::{
33
types::{PyModule, PyModuleMethods},
44
Bound, PyResult, Python,
55
};
6+
67
// Main exception.
78
create_exception!(
89
psqlpy.exceptions,
@@ -146,108 +147,93 @@ create_exception!(psqlpy.exceptions, SSLError, RustPSQLDriverPyBaseError);
146147
pub fn python_exceptions_module(py: Python<'_>, pymod: &Bound<'_, PyModule>) -> PyResult<()> {
147148
pymod.add(
148149
"RustPSQLDriverPyBaseError",
149-
py.get_type_bound::<RustPSQLDriverPyBaseError>(),
150+
py.get_type::<RustPSQLDriverPyBaseError>(),
150151
)?;
151152

152153
pymod.add(
153154
"BaseConnectionPoolError",
154-
py.get_type_bound::<BaseConnectionPoolError>(),
155+
py.get_type::<BaseConnectionPoolError>(),
155156
)?;
156157
pymod.add(
157158
"ConnectionPoolBuildError",
158-
py.get_type_bound::<ConnectionPoolBuildError>(),
159+
py.get_type::<ConnectionPoolBuildError>(),
159160
)?;
160161
pymod.add(
161162
"ConnectionPoolConfigurationError",
162-
py.get_type_bound::<ConnectionPoolConfigurationError>(),
163+
py.get_type::<ConnectionPoolConfigurationError>(),
163164
)?;
164165
pymod.add(
165166
"ConnectionPoolExecuteError",
166-
py.get_type_bound::<ConnectionPoolExecuteError>(),
167+
py.get_type::<ConnectionPoolExecuteError>(),
167168
)?;
168169

169-
pymod.add(
170-
"BaseConnectionError",
171-
py.get_type_bound::<BaseConnectionError>(),
172-
)?;
170+
pymod.add("BaseConnectionError", py.get_type::<BaseConnectionError>())?;
173171
pymod.add(
174172
"ConnectionExecuteError",
175-
py.get_type_bound::<ConnectionExecuteError>(),
173+
py.get_type::<ConnectionExecuteError>(),
176174
)?;
177175
pymod.add(
178176
"ConnectionClosedError",
179-
py.get_type_bound::<ConnectionClosedError>(),
177+
py.get_type::<ConnectionClosedError>(),
180178
)?;
181179

182180
pymod.add(
183181
"BaseTransactionError",
184-
py.get_type_bound::<BaseTransactionError>(),
182+
py.get_type::<BaseTransactionError>(),
185183
)?;
186184
pymod.add(
187185
"TransactionBeginError",
188-
py.get_type_bound::<TransactionBeginError>(),
186+
py.get_type::<TransactionBeginError>(),
189187
)?;
190188
pymod.add(
191189
"TransactionCommitError",
192-
py.get_type_bound::<TransactionCommitError>(),
190+
py.get_type::<TransactionCommitError>(),
193191
)?;
194192
pymod.add(
195193
"TransactionRollbackError",
196-
py.get_type_bound::<TransactionRollbackError>(),
194+
py.get_type::<TransactionRollbackError>(),
197195
)?;
198196
pymod.add(
199197
"TransactionSavepointError",
200-
py.get_type_bound::<TransactionSavepointError>(),
198+
py.get_type::<TransactionSavepointError>(),
201199
)?;
202200
pymod.add(
203201
"TransactionExecuteError",
204-
py.get_type_bound::<TransactionExecuteError>(),
202+
py.get_type::<TransactionExecuteError>(),
205203
)?;
206204
pymod.add(
207205
"TransactionClosedError",
208-
py.get_type_bound::<TransactionClosedError>(),
206+
py.get_type::<TransactionClosedError>(),
209207
)?;
210208

211-
pymod.add("BaseCursorError", py.get_type_bound::<BaseCursorError>())?;
212-
pymod.add("CursorStartError", py.get_type_bound::<CursorStartError>())?;
213-
pymod.add("CursorCloseError", py.get_type_bound::<CursorCloseError>())?;
214-
pymod.add("CursorFetchError", py.get_type_bound::<CursorFetchError>())?;
215-
pymod.add(
216-
"CursorClosedError",
217-
py.get_type_bound::<CursorClosedError>(),
218-
)?;
209+
pymod.add("BaseCursorError", py.get_type::<BaseCursorError>())?;
210+
pymod.add("CursorStartError", py.get_type::<CursorStartError>())?;
211+
pymod.add("CursorCloseError", py.get_type::<CursorCloseError>())?;
212+
pymod.add("CursorFetchError", py.get_type::<CursorFetchError>())?;
213+
pymod.add("CursorClosedError", py.get_type::<CursorClosedError>())?;
219214

220215
pymod.add(
221216
"RustToPyValueMappingError",
222-
py.get_type_bound::<RustToPyValueMappingError>(),
217+
py.get_type::<RustToPyValueMappingError>(),
223218
)?;
224219
pymod.add(
225220
"PyToRustValueMappingError",
226-
py.get_type_bound::<PyToRustValueMappingError>(),
221+
py.get_type::<PyToRustValueMappingError>(),
227222
)?;
228223
pymod.add(
229224
"UUIDValueConvertError",
230-
py.get_type_bound::<UUIDValueConvertError>(),
225+
py.get_type::<UUIDValueConvertError>(),
231226
)?;
232227
pymod.add(
233228
"MacAddrConversionError",
234-
py.get_type_bound::<MacAddrConversionError>(),
235-
)?;
236-
pymod.add(
237-
"BaseListenerError",
238-
py.get_type_bound::<BaseListenerError>(),
239-
)?;
240-
pymod.add(
241-
"ListenerStartError",
242-
py.get_type_bound::<ListenerStartError>(),
243-
)?;
244-
pymod.add(
245-
"ListenerClosedError",
246-
py.get_type_bound::<ListenerClosedError>(),
229+
py.get_type::<MacAddrConversionError>(),
247230
)?;
231+
pymod.add("BaseListenerError", py.get_type::<BaseListenerError>())?;
232+
pymod.add("ListenerStartError", py.get_type::<ListenerStartError>())?;
233+
pymod.add("ListenerClosedError", py.get_type::<ListenerClosedError>())?;
248234
pymod.add(
249235
"ListenerCallbackError",
250-
py.get_type_bound::<ListenerCallbackError>(),
236+
py.get_type::<ListenerCallbackError>(),
251237
)?;
252238
Ok(())
253239
}

src/query_result.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn row_to_dict<'a>(
1616
postgres_row: &'a Row,
1717
custom_decoders: &Option<Py<PyDict>>,
1818
) -> RustPSQLDriverPyResult<pyo3::Bound<'a, PyDict>> {
19-
let python_dict = PyDict::new_bound(py);
19+
let python_dict = PyDict::new(py);
2020
for (column_idx, column) in postgres_row.columns().iter().enumerate() {
2121
let python_type = postgres_to_py(py, postgres_row, column, column_idx, custom_decoders)?;
2222
python_dict.set_item(column.name().to_object(py), python_type)?;
@@ -85,7 +85,7 @@ impl PSQLDriverPyQueryResult {
8585
let mut res: Vec<Py<PyAny>> = vec![];
8686
for row in &self.inner {
8787
let pydict: pyo3::Bound<'_, PyDict> = row_to_dict(py, row, &None)?;
88-
let convert_class_inst = as_class.call_bound(py, (), Some(&pydict))?;
88+
let convert_class_inst = as_class.call(py, (), Some(&pydict))?;
8989
res.push(convert_class_inst);
9090
}
9191

@@ -109,7 +109,7 @@ impl PSQLDriverPyQueryResult {
109109
let mut res: Vec<Py<PyAny>> = vec![];
110110
for row in &self.inner {
111111
let pydict: pyo3::Bound<'_, PyDict> = row_to_dict(py, row, &custom_decoders)?;
112-
let row_factory_class = row_factory.call_bound(py, (pydict,), None)?;
112+
let row_factory_class = row_factory.call(py, (pydict,), None)?;
113113
res.push(row_factory_class);
114114
}
115115
Ok(res.to_object(py))
@@ -170,7 +170,7 @@ impl PSQLDriverSinglePyQueryResult {
170170
as_class: Py<PyAny>,
171171
) -> RustPSQLDriverPyResult<Py<PyAny>> {
172172
let pydict: pyo3::Bound<'_, PyDict> = row_to_dict(py, &self.inner, &None)?;
173-
Ok(as_class.call_bound(py, (), Some(&pydict))?)
173+
Ok(as_class.call(py, (), Some(&pydict))?)
174174
}
175175

176176
/// Convert result from database with function passed from Python.
@@ -188,6 +188,6 @@ impl PSQLDriverSinglePyQueryResult {
188188
custom_decoders: Option<Py<PyDict>>,
189189
) -> RustPSQLDriverPyResult<Py<PyAny>> {
190190
let pydict = row_to_dict(py, &self.inner, &custom_decoders)?.to_object(py);
191-
Ok(row_factory.call_bound(py, (pydict,), None)?)
191+
Ok(row_factory.call(py, (pydict,), None)?)
192192
}
193193
}

src/runtime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use futures_util::Future;
2-
use pyo3::{IntoPy, Py, PyAny, PyObject, Python};
2+
use pyo3::{IntoPyObject, Py, PyAny, Python};
33

44
use crate::exceptions::rust_errors::RustPSQLDriverPyResult;
55

@@ -21,7 +21,7 @@ pub fn tokio_runtime() -> &'static tokio::runtime::Runtime {
2121
pub fn rustdriver_future<F, T>(py: Python<'_>, future: F) -> RustPSQLDriverPyResult<Py<PyAny>>
2222
where
2323
F: Future<Output = RustPSQLDriverPyResult<T>> + Send + 'static,
24-
T: IntoPy<PyObject>,
24+
T: for<'py> IntoPyObject<'py>,
2525
{
2626
let res =
2727
pyo3_async_runtimes::tokio::future_into_py(py, async { future.await.map_err(Into::into) })

0 commit comments

Comments
 (0)