Skip to content

Commit

Permalink
Add psycopg3 support for database functions
Browse files Browse the repository at this point in the history
  • Loading branch information
LerikP committed Apr 7, 2023
1 parent d81ea06 commit 0d0d02e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sqlalchemy_utils/functions/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def create_database(url, encoding='utf8', template=None):

if (dialect_name == 'mssql' and dialect_driver in {'pymssql', 'pyodbc'}) \
or (dialect_name == 'postgresql' and dialect_driver in {
'asyncpg', 'pg8000', 'psycopg2', 'psycopg2cffi'}):
'asyncpg', 'pg8000', 'psycopg', 'psycopg2', 'psycopg2cffi'}):
engine = sa.create_engine(url, isolation_level='AUTOCOMMIT')
else:
engine = sa.create_engine(url)
Expand Down Expand Up @@ -625,7 +625,7 @@ def drop_database(url):
if dialect_name == 'mssql' and dialect_driver in {'pymssql', 'pyodbc'}:
engine = sa.create_engine(url, connect_args={'autocommit': True})
elif dialect_name == 'postgresql' and dialect_driver in {
'asyncpg', 'pg8000', 'psycopg2', 'psycopg2cffi'}:
'asyncpg', 'pg8000', 'psycopg', 'psycopg2', 'psycopg2cffi'}:
engine = sa.create_engine(url, isolation_level='AUTOCOMMIT')
else:
engine = sa.create_engine(url)
Expand Down
11 changes: 11 additions & 0 deletions tests/functions/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ def dsn(self, postgresql_db_user, postgresql_db_password):
)


class TestDatabasePostgresPsycoPG3(DatabaseTest):

@pytest.fixture
def dsn(self, postgresql_db_user, postgresql_db_password):
return 'postgresql+psycopg://{}:{}@localhost/{}'.format(
postgresql_db_user,
postgresql_db_password,
'db_to_test_create_and_drop_via_psycopg3_driver'
)


@pytest.mark.usefixtures('postgresql_dsn')
class TestDatabasePostgresWithQuotedName(DatabaseTest):

Expand Down

0 comments on commit 0d0d02e

Please sign in to comment.