the37lab-authlib 0.1.1755164205__py3-none-any.whl → 0.1.1756367559__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of the37lab-authlib might be problematic. Click here for more details.
- the37lab_authlib/db.py +21 -4
- {the37lab_authlib-0.1.1755164205.dist-info → the37lab_authlib-0.1.1756367559.dist-info}/METADATA +1 -1
- {the37lab_authlib-0.1.1755164205.dist-info → the37lab_authlib-0.1.1756367559.dist-info}/RECORD +5 -5
- {the37lab_authlib-0.1.1755164205.dist-info → the37lab_authlib-0.1.1756367559.dist-info}/WHEEL +0 -0
- {the37lab_authlib-0.1.1755164205.dist-info → the37lab_authlib-0.1.1756367559.dist-info}/top_level.txt +0 -0
the37lab_authlib/db.py
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
import psycopg2
|
|
2
2
|
from psycopg2.extras import RealDictCursor
|
|
3
|
+
from psycopg2 import pool
|
|
3
4
|
from contextlib import contextmanager
|
|
4
5
|
from .models import UUIDGenerator, IntegerGenerator
|
|
5
6
|
|
|
6
7
|
class Database:
|
|
7
|
-
def __init__(self, dsn, id_type='uuid'):
|
|
8
|
+
def __init__(self, dsn, id_type='uuid', min_conn=1, max_conn=10):
|
|
8
9
|
self.dsn = dsn
|
|
9
10
|
self.id_generator = UUIDGenerator() if id_type == 'uuid' else IntegerGenerator()
|
|
10
11
|
self.id_type = id_type
|
|
12
|
+
self.min_conn = min_conn
|
|
13
|
+
self.max_conn = max_conn
|
|
14
|
+
self._pool = None
|
|
15
|
+
self._init_pool()
|
|
11
16
|
self._init_db()
|
|
12
17
|
|
|
18
|
+
def _init_pool(self):
|
|
19
|
+
self._pool = pool.ThreadedConnectionPool(
|
|
20
|
+
self.min_conn,
|
|
21
|
+
self.max_conn,
|
|
22
|
+
self.dsn,
|
|
23
|
+
cursor_factory=RealDictCursor
|
|
24
|
+
)
|
|
25
|
+
|
|
13
26
|
def _init_db(self):
|
|
14
27
|
with self.get_connection() as conn:
|
|
15
28
|
with conn.cursor() as cur:
|
|
@@ -54,7 +67,7 @@ class Database:
|
|
|
54
67
|
|
|
55
68
|
@contextmanager
|
|
56
69
|
def get_connection(self):
|
|
57
|
-
conn =
|
|
70
|
+
conn = self._pool.getconn()
|
|
58
71
|
try:
|
|
59
72
|
yield conn
|
|
60
73
|
conn.commit()
|
|
@@ -62,7 +75,7 @@ class Database:
|
|
|
62
75
|
conn.rollback()
|
|
63
76
|
raise
|
|
64
77
|
finally:
|
|
65
|
-
|
|
78
|
+
self._pool.putconn(conn)
|
|
66
79
|
|
|
67
80
|
@contextmanager
|
|
68
81
|
def get_cursor(self):
|
|
@@ -71,4 +84,8 @@ class Database:
|
|
|
71
84
|
yield cur
|
|
72
85
|
|
|
73
86
|
def get_id_generator(self):
|
|
74
|
-
return self.id_generator
|
|
87
|
+
return self.id_generator
|
|
88
|
+
|
|
89
|
+
def close(self):
|
|
90
|
+
if self._pool:
|
|
91
|
+
self._pool.closeall()
|
{the37lab_authlib-0.1.1755164205.dist-info → the37lab_authlib-0.1.1756367559.dist-info}/RECORD
RENAMED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
the37lab_authlib/__init__.py,sha256=cFVTWL-0YIMqwOMVy1P8mOt_bQODJp-L9bfp2QQ8CTo,132
|
|
2
2
|
the37lab_authlib/auth.py,sha256=eAeyS9wBO7euMkbnRZH8mvaUzy06KbQ3qwckOtmjhkw,23536
|
|
3
|
-
the37lab_authlib/db.py,sha256=
|
|
3
|
+
the37lab_authlib/db.py,sha256=cmnmykKvq6V5e-D0HGiRN4DjFBOGB-SL1HpFjR5uyCw,3162
|
|
4
4
|
the37lab_authlib/decorators.py,sha256=L-gJUUwDUT2JXTptQ6XEey1LkI5RprbqzEfArWI7F8Y,1305
|
|
5
5
|
the37lab_authlib/exceptions.py,sha256=mdplK5sKNtagPAzSGq5NGsrQ4r-k03DKJBKx6myWwZc,317
|
|
6
6
|
the37lab_authlib/models.py,sha256=-PlvQlHGIsSdrH0H9Cdh_vTPlltGV8G1Z1mmGQvAg9Y,3422
|
|
7
|
-
the37lab_authlib-0.1.
|
|
8
|
-
the37lab_authlib-0.1.
|
|
9
|
-
the37lab_authlib-0.1.
|
|
10
|
-
the37lab_authlib-0.1.
|
|
7
|
+
the37lab_authlib-0.1.1756367559.dist-info/METADATA,sha256=KJPNMX0OzIex4uWlzA96p3nr7gSB51DCxj3zKRNNbUI,8319
|
|
8
|
+
the37lab_authlib-0.1.1756367559.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
+
the37lab_authlib-0.1.1756367559.dist-info/top_level.txt,sha256=6Jmxw4UeLrhfJXgRKbXWY4OhxRSaMs0dKKhNCGWWSwc,17
|
|
10
|
+
the37lab_authlib-0.1.1756367559.dist-info/RECORD,,
|
{the37lab_authlib-0.1.1755164205.dist-info → the37lab_authlib-0.1.1756367559.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|