Skip to content

Commit 2d103b2

Browse files
Merge pull request #10 from NYPL/update-psql-kwargs
Pass in kwargs from PostgreSQLClient to ConnectionPool
2 parents bdbde85 + 894b81a commit 2d103b2

5 files changed

Lines changed: 13 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v0.0.8 - 3/3/23
4+
- Pass in all kwargs from PostgreSQLClient to ConnectionPool so that all ConnectionPool settings
5+
can be set from the wrapper
6+
37
## v0.0.7 - 3/1/23
48
- Added Oauth2ApiClient for oauth2 authenticated calls to our Platform API and Sierra
59
- Set PostgreSQL connection pool to have a default pool size minimum of 0
@@ -13,17 +17,14 @@
1317
- Updated README with deployment information
1418

1519
## v0.0.3 - 2/10/23
16-
1720
- Added GitHub Actions workflow for deploying to production
1821
- Switched PostgreSQLClient to use connection pooling
1922

2023
## v0.0.2 - 2/6/23
21-
2224
- Added CODEOWNERS
2325
- Added GitHub Actions workflows for running tests and deploying to QA
2426
- Added tests for helper functions
2527
- Updated Avro encoder to avoid dependency on pandas
2628

2729
## v0.0.1 - 1/26/23
28-
2930
Initial version. Includes the `avro_encoder`, `kinesis_client`, `mysql_client`, `postgresql_client`, `redshift_client`, and `s3_client` classes as well as the `config_helper`, `kms_helper`, `log_helper`, and `obfuscation_helper` functions.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This package contains common Python utility classes and functions.
1010
* Connecting to and querying a MySQL database
1111
* Connecting to and querying a PostgreSQL database using a connection pool
1212
* Connecting to and querying Redshift
13-
* Making requests to the Oauth2 authenticated APIS such as NYPL Platform API and Sierra
13+
* Making requests to the Oauth2 authenticated APIs such as NYPL Platform API and Sierra
1414

1515
## Functions
1616
* Reading a YAML config file and putting the contents in os.environ

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "nypl_py_utils"
7-
version = "0.0.7"
7+
version = "0.0.8"
88
authors = [
99
{ name="Aaron Friedman", email="aaronfriedman@nypl.org" },
1010
]

src/nypl_py_utils/classes/postgresql_client.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ def __init__(self, host, port, db_name, user, password, **kwargs):
1919
'{db_name}').format(user=user, password=password,
2020
host=host, port=port,
2121
db_name=db_name)
22-
self.min_size = kwargs.get('min_size', 0)
23-
self.max_size = kwargs.get('max_size', 1)
24-
self.pool = ConnectionPool(
25-
self.conn_info, open=False,
26-
min_size=self.min_size, max_size=self.max_size)
22+
self.kwargs = kwargs
23+
self.kwargs['min_size'] = kwargs.get('min_size', 0)
24+
self.kwargs['max_size'] = kwargs.get('max_size', 1)
25+
self.pool = ConnectionPool(self.conn_info, open=False, **self.kwargs)
2726

2827
def connect(self):
2928
"""
@@ -34,8 +33,7 @@ def connect(self):
3433
try:
3534
if self.pool is None:
3635
self.pool = ConnectionPool(
37-
self.conn_info, open=False, min_size=self.min_size,
38-
max_size=self.max_size)
36+
self.conn_info, open=False, **self.kwargs)
3937
self.pool.open(wait=True, timeout=self.timeout)
4038
except psycopg.Error as e:
4139
self.logger.error(

tests/test_postgresql_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ def test_init(self, test_instance):
2424
def test_init_with_kwargs(self):
2525
test_instance = PostgreSQLClient(
2626
'test_host', 'test_port', 'test_db_name', 'test_user',
27-
'test_password', min_size=5, max_size=10)
27+
'test_password', min_size=5, max_size=10, max_idle=15.0)
2828
assert test_instance.pool.conninfo == (
2929
'postgresql://test_user:test_password@test_host:test_port/' +
3030
'test_db_name')
3131
assert test_instance.pool._opened is False
3232
assert test_instance.pool.min_size == 5
3333
assert test_instance.pool.max_size == 10
34+
assert test_instance.pool.max_idle == 15.0
3435

3536
def test_connect(self, test_instance):
3637
test_instance.connect()

0 commit comments

Comments
 (0)