File tree Expand file tree Collapse file tree 4 files changed +30
-8
lines changed
Expand file tree Collapse file tree 4 files changed +30
-8
lines changed Original file line number Diff line number Diff line change @@ -26,18 +26,14 @@ jobs:
2626 python-version : ' 3.6'
2727 - name : Setup databases
2828 run : |
29- python setup.py install
30- pip install mysqlclient
31- pip install psycopg2-binary
32- touch test.db test1.db
29+ pip install .
30+ pip install mysqlclient psycopg2-binary
3331 - name : Run tests
3432 run : python tests/sql.py
3533 - name : Install pypa/build
36- run : |
37- python -m pip install build --user
34+ run : python -m pip install build --user
3835 - name : Build a binary wheel and a source tarball
39- run : |
40- python -m build --sdist --wheel --outdir dist/ .
36+ run : python -m build --sdist --wheel --outdir dist/ .
4137 - name : Deploy to PyPI
4238 if : ${{ github.ref == 'refs/heads/main' }}
4339 uses : pypa/gh-action-pypi-publish@release/v1
Original file line number Diff line number Diff line change 55* .db
66* .egg-info /
77* .pyc
8+ build /
89dist /
910test.db
Original file line number Diff line number Diff line change 11import threading
2+ import warnings
23
34from ._engine_util import create_engine
45
@@ -11,6 +12,7 @@ class Engine:
1112 """
1213
1314 def __init__ (self , url ):
15+ url = _replace_scheme_if_postgres (url )
1416 self ._engine = create_engine (url )
1517
1618 def get_transaction_connection (self ):
@@ -64,3 +66,23 @@ def _thread_local_connections():
6466 connections = thread_local_data .connections = {}
6567
6668 return connections
69+
70+ def _replace_scheme_if_postgres (url ):
71+ """
72+ Replaces the postgres scheme with the postgresql scheme if possible since the postgres scheme
73+ is deprecated.
74+
75+ :returns: url with postgresql scheme if the scheme was postgres; otherwise returns url as is
76+ """
77+
78+ if url .startswith ("postgres://" ):
79+ with warnings .catch_warnings ():
80+ warnings .simplefilter ("always" )
81+ warnings .warn (
82+ "The postgres:// scheme is deprecated and will not be supported in the next major"
83+ + " release of the library. Please use the postgresql:// scheme instead." ,
84+ DeprecationWarning
85+ )
86+ url = f"postgresql{ url [len ('postgres' ):]} "
87+
88+ return url
Original file line number Diff line number Diff line change @@ -169,6 +169,9 @@ def setUp(self):
169169 def test_cte (self ):
170170 self .assertEqual (self .db .execute ("WITH foo AS ( SELECT 1 AS bar ) SELECT bar FROM foo" ), [{"bar" : 1 }])
171171
172+ def test_postgres_scheme (self ):
173+ db = SQL ("postgres://postgres:postgres@127.0.0.1/test" )
174+ db .execute ("SELECT 1" )
172175
173176class SQLiteTests (SQLTests ):
174177
You can’t perform that action at this time.
0 commit comments