Skip to content

Commit 8b0c3ad

Browse files
committed
Started implementing chain to create pool
Signed-off-by: chandr-andr (Kiselev Aleksandr) <chandr@chandr.net>
1 parent e57e438 commit 8b0c3ad

File tree

8 files changed

+380
-294
lines changed

8 files changed

+380
-294
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ name = "psqlpy"
99
crate-type = ["cdylib"]
1010

1111
[dependencies]
12-
deadpool-postgres = { git = "https://github.com/chandr-andr/deadpool.git", version = "0.13.0" }
12+
deadpool-postgres = { git = "https://github.com/chandr-andr/deadpool.git", branch = "master" }
1313
pyo3 = { version = "*", features = ["chrono", "experimental-async"] }
1414
pyo3-asyncio = { git = "https://github.com/chandr-andr/pyo3-asyncio.git", version = "0.20.0", features = [
1515
"tokio-runtime",
@@ -24,13 +24,13 @@ uuid = { version = "1.7.0", features = ["v4"] }
2424
serde_json = "1.0.113"
2525
futures-util = "0.3.30"
2626
macaddr = "1.0.1"
27-
tokio-postgres = { git = "https://github.com/chandr-andr/rust-postgres.git", version = "0.7.10", features = [
27+
tokio-postgres = { git = "https://github.com/chandr-andr/rust-postgres.git", branch = "master", features = [
2828
"with-serde_json-1",
2929
"array-impls",
3030
"with-chrono-0_4",
3131
"with-uuid-1",
3232
] }
33-
postgres-types = { git = "https://github.com/chandr-andr/rust-postgres.git", version = "0.2.6", features = [
33+
postgres-types = { git = "https://github.com/chandr-andr/rust-postgres.git", branch = "master", features = [
3434
"derive",
3535
] }
36-
postgres-protocol = { git = "https://github.com/chandr-andr/rust-postgres.git", version = "*" }
36+
postgres-protocol = { git = "https://github.com/chandr-andr/rust-postgres.git", branch = "master" }

python/psqlpy/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
ConnRecyclingMethod,
55
Cursor,
66
IsolationLevel,
7+
KeepaliveConfig,
78
LoadBalanceHosts,
89
QueryResult,
910
ReadVariant,
1011
SingleQueryResult,
12+
SslMode,
1113
TargetSessionAttrs,
1214
Transaction,
1315
connect,
@@ -26,4 +28,6 @@
2628
"connect",
2729
"LoadBalanceHosts",
2830
"TargetSessionAttrs",
31+
"SslMode",
32+
"KeepaliveConfig",
2933
]

python/psqlpy/_internal/__init__.pyi

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,33 @@ class ConnRecyclingMethod(Enum):
171171
Verified = 2
172172
Clean = 3
173173

174+
class SslMode(Enum):
175+
"""TLS configuration."""
176+
177+
# Do not use TLS.
178+
Disable = 1
179+
# Pay the overhead of encryption if the server insists on it.
180+
Allow = 2
181+
# Attempt to connect with TLS but allow sessions without.
182+
Prefer = 3
183+
# Require the use of TLS.
184+
Require = 4
185+
# I want my data encrypted,
186+
# and I accept the overhead.
187+
# I want to be sure that I connect to a server that I trust.
188+
VerifyCa = 5
189+
# I want my data encrypted,
190+
# and I accept the overhead.
191+
# I want to be sure that I connect to a server I trust,
192+
# and that it's the one I specify.
193+
VerifyFull = 6
194+
195+
class KeepaliveConfig:
196+
"""Config for configuring keepalive."""
197+
198+
def __init__(self: Self, idle: int, interval: int, retries: int) -> None:
199+
"""Initialize new config."""
200+
174201
class Cursor:
175202
"""Represent opened cursor in a transaction.
176203

src/driver/common_options.rs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
use std::time::Duration;
2+
13
use deadpool_postgres::RecyclingMethod;
2-
use pyo3::pyclass;
4+
use pyo3::{pyclass, pymethods};
35

46
#[pyclass]
57
#[derive(Clone, Copy)]
@@ -60,3 +62,60 @@ impl TargetSessionAttrs {
6062
}
6163
}
6264
}
65+
66+
#[pyclass]
67+
#[derive(Clone, Copy)]
68+
pub enum SslMode {
69+
/// Do not use TLS.
70+
Disable,
71+
/// Pay the overhead of encryption if the server insists on it.
72+
Allow,
73+
/// Attempt to connect with TLS but allow sessions without.
74+
Prefer,
75+
/// Require the use of TLS.
76+
Require,
77+
/// I want my data encrypted,
78+
/// and I accept the overhead.
79+
/// I want to be sure that I connect to a server that I trust.
80+
VerifyCa,
81+
/// I want my data encrypted,
82+
/// and I accept the overhead.
83+
/// I want to be sure that I connect to a server I trust,
84+
/// and that it's the one I specify.
85+
VerifyFull,
86+
}
87+
88+
impl SslMode {
89+
#[must_use]
90+
pub fn to_internal(&self) -> tokio_postgres::config::SslMode {
91+
match self {
92+
SslMode::Disable => tokio_postgres::config::SslMode::Disable,
93+
SslMode::Allow => tokio_postgres::config::SslMode::Allow,
94+
SslMode::Prefer => tokio_postgres::config::SslMode::Prefer,
95+
SslMode::Require => tokio_postgres::config::SslMode::Require,
96+
SslMode::VerifyCa => tokio_postgres::config::SslMode::VerifyCa,
97+
SslMode::VerifyFull => tokio_postgres::config::SslMode::VerifyFull,
98+
}
99+
}
100+
}
101+
102+
#[pyclass]
103+
#[derive(Clone, Copy)]
104+
pub struct KeepaliveConfig {
105+
pub idle: Duration,
106+
pub interval: Option<Duration>,
107+
pub retries: Option<u32>,
108+
}
109+
110+
#[pymethods]
111+
impl KeepaliveConfig {
112+
#[new]
113+
fn build_config(idle: u64, interval: Option<u64>, retries: Option<u32>) -> Self {
114+
let interval_internal = interval.map(Duration::from_secs);
115+
KeepaliveConfig {
116+
idle: Duration::from_secs(idle),
117+
interval: interval_internal,
118+
retries,
119+
}
120+
}
121+
}

src/driver/connection_pool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub fn connect(
105105
}
106106

107107
#[pyclass]
108-
pub struct ConnectionPool(Pool);
108+
pub struct ConnectionPool(pub Pool);
109109

110110
#[pymethods]
111111
impl ConnectionPool {

0 commit comments

Comments
 (0)