Skip to content

Commit 75e14d8

Browse files
committed
Added pool test for Psycopg 2
1 parent 78e6459 commit 75e14d8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/test_psycopg2.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pgvector.psycopg2 import register_vector, HalfVector, SparseVector
33
import psycopg2
44
from psycopg2.extras import DictCursor, RealDictCursor, NamedTupleCursor
5+
from psycopg2.pool import ThreadedConnectionPool
56

67
conn = psycopg2.connect(dbname='pgvector_python_test')
78
conn.autocommit = True
@@ -94,3 +95,21 @@ def test_cursor_factory_connection(self):
9495
conn = psycopg2.connect(dbname='pgvector_python_test', cursor_factory=cursor_factory)
9596
register_vector(conn, globally=False)
9697
conn.close()
98+
99+
def test_pool(self):
100+
pool = ThreadedConnectionPool(1, 3, dbname='pgvector_python_test')
101+
102+
conn = pool.getconn()
103+
try:
104+
cur = conn.cursor()
105+
106+
# use globally=True for apps
107+
register_vector(cur, globally=False)
108+
109+
cur.execute("SELECT '[1,2,3]'::vector")
110+
res = cur.fetchone()
111+
assert np.array_equal(res[0], np.array([1, 2, 3]))
112+
finally:
113+
pool.putconn(conn)
114+
115+
pool.closeall()

0 commit comments

Comments
 (0)