66import pytest
77from sqlalchemy import create_engine , event , insert , inspect , select , text , MetaData , Table , Column , Index , Integer , ARRAY
88from sqlalchemy .exc import StatementError
9+ from sqlalchemy .ext .asyncio import async_sessionmaker , create_async_engine
910from sqlalchemy .ext .automap import automap_base
10- from sqlalchemy .orm import declarative_base , Session
11+ from sqlalchemy .orm import declarative_base , mapped_column , Session
1112from sqlalchemy .sql import func
1213
13- try :
14- from sqlalchemy .orm import mapped_column
15- from sqlalchemy .ext .asyncio import async_sessionmaker , create_async_engine
16- sqlalchemy_version = 2
17- except ImportError :
18- mapped_column = Column
19- sqlalchemy_version = 1
20-
2114psycopg2_engine = create_engine ('postgresql+psycopg2://localhost/pgvector_python_test' )
2215psycopg2_type_engine = create_engine ('postgresql+psycopg2://localhost/pgvector_python_test' )
2316
@@ -30,42 +23,41 @@ def psycopg2_connect(dbapi_connection, connection_record):
3023
3124pg8000_engine = create_engine (f'postgresql+pg8000://{ getuser ()} @localhost/pgvector_python_test' )
3225
33- if sqlalchemy_version > 1 :
34- psycopg_engine = create_engine ('postgresql+psycopg://localhost/pgvector_python_test' )
35- psycopg_type_engine = create_engine ('postgresql+psycopg://localhost/pgvector_python_test' )
36-
37- @event .listens_for (psycopg_type_engine , "connect" )
38- def psycopg_connect (dbapi_connection , connection_record ):
39- from pgvector .psycopg import register_vector
40- register_vector (dbapi_connection )
41-
42- psycopg_async_engine = create_async_engine ('postgresql+psycopg://localhost/pgvector_python_test' )
43- psycopg_async_type_engine = create_async_engine ('postgresql+psycopg://localhost/pgvector_python_test' )
44-
45- @event .listens_for (psycopg_async_type_engine .sync_engine , "connect" )
46- def psycopg_async_connect (dbapi_connection , connection_record ):
47- from pgvector .psycopg import register_vector_async
48- dbapi_connection .run_async (register_vector_async )
49-
50- asyncpg_engine = create_async_engine ('postgresql+asyncpg://localhost/pgvector_python_test' )
51- asyncpg_type_engine = create_async_engine ('postgresql+asyncpg://localhost/pgvector_python_test' )
52-
53- @event .listens_for (asyncpg_type_engine .sync_engine , "connect" )
54- def asyncpg_connect (dbapi_connection , connection_record ):
55- from pgvector .asyncpg import register_vector
56- dbapi_connection .run_async (register_vector )
57-
58- engines = [psycopg2_engine , psycopg2_type_engine , pg8000_engine ]
59- array_engines = [psycopg2_type_engine ]
60- async_engines = []
61- async_array_engines = []
62-
63- if sqlalchemy_version > 1 :
64- engines += [psycopg_engine , psycopg_type_engine ]
65- array_engines += [psycopg_type_engine ]
66- # TODO support asyncpg_type_engine
67- async_engines += [psycopg_async_engine , psycopg_async_type_engine , asyncpg_engine ]
68- async_array_engines += [psycopg_async_type_engine , asyncpg_engine ]
26+ psycopg_engine = create_engine ('postgresql+psycopg://localhost/pgvector_python_test' )
27+ psycopg_type_engine = create_engine ('postgresql+psycopg://localhost/pgvector_python_test' )
28+
29+
30+ @event .listens_for (psycopg_type_engine , "connect" )
31+ def psycopg_connect (dbapi_connection , connection_record ):
32+ from pgvector .psycopg import register_vector
33+ register_vector (dbapi_connection )
34+
35+
36+ psycopg_async_engine = create_async_engine ('postgresql+psycopg://localhost/pgvector_python_test' )
37+ psycopg_async_type_engine = create_async_engine ('postgresql+psycopg://localhost/pgvector_python_test' )
38+
39+
40+ @event .listens_for (psycopg_async_type_engine .sync_engine , "connect" )
41+ def psycopg_async_connect (dbapi_connection , connection_record ):
42+ from pgvector .psycopg import register_vector_async
43+ dbapi_connection .run_async (register_vector_async )
44+
45+
46+ asyncpg_engine = create_async_engine ('postgresql+asyncpg://localhost/pgvector_python_test' )
47+ asyncpg_type_engine = create_async_engine ('postgresql+asyncpg://localhost/pgvector_python_test' )
48+
49+
50+ @event .listens_for (asyncpg_type_engine .sync_engine , "connect" )
51+ def asyncpg_connect (dbapi_connection , connection_record ):
52+ from pgvector .asyncpg import register_vector
53+ dbapi_connection .run_async (register_vector )
54+
55+
56+ engines = [psycopg_engine , psycopg_type_engine , psycopg2_engine , psycopg2_type_engine , pg8000_engine ]
57+ array_engines = [psycopg_type_engine , psycopg2_type_engine ]
58+ # TODO support asyncpg_type_engine
59+ async_engines = [psycopg_async_engine , psycopg_async_type_engine , asyncpg_engine ]
60+ async_array_engines = [psycopg_async_type_engine , asyncpg_engine ]
6961
7062setup_engine = engines [0 ]
7163with Session (setup_engine ) as session :
0 commit comments