-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathportal.rs
More file actions
52 lines (41 loc) · 1.29 KB
/
portal.rs
File metadata and controls
52 lines (41 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::sync::Arc;
use pyo3::{pyclass, pymethods};
use tokio_postgres::Portal as tp_Portal;
use crate::{exceptions::rust_errors::PSQLPyResult, query_result::PSQLDriverPyQueryResult};
use super::inner_transaction::PsqlpyTransaction;
#[pyclass]
struct Portal {
transaction: Arc<PsqlpyTransaction>,
inner: tp_Portal,
array_size: i32,
}
impl Portal {
async fn query_portal(&self, size: i32) -> PSQLPyResult<PSQLDriverPyQueryResult> {
let result = self.transaction.query_portal(&self.inner, size).await?;
Ok(PSQLDriverPyQueryResult::new(result))
}
}
#[pymethods]
impl Portal {
#[getter]
fn get_array_size(&self) -> i32 {
self.array_size
}
#[setter]
fn set_array_size(&mut self, value: i32) {
self.array_size = value;
}
async fn fetch_one(&self) -> PSQLPyResult<PSQLDriverPyQueryResult> {
self.query_portal(1).await
}
#[pyo3(signature = (size=None))]
async fn fetch_many(&self, size: Option<i32>) -> PSQLPyResult<PSQLDriverPyQueryResult> {
self.query_portal(size.unwrap_or(self.array_size)).await
}
async fn fetch_all(&self) -> PSQLPyResult<PSQLDriverPyQueryResult> {
self.query_portal(-1).await
}
async fn close(&mut self) {
let _ = Arc::downgrade(&self.transaction);
}
}