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:
26
26
python-version : ' 3.6'
27
27
- name : Setup databases
28
28
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
33
31
- name : Run tests
34
32
run : python tests/sql.py
35
33
- name : Install pypa/build
36
- run : |
37
- python -m pip install build --user
34
+ run : python -m pip install build --user
38
35
- 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/ .
41
37
- name : Deploy to PyPI
42
38
if : ${{ github.ref == 'refs/heads/main' }}
43
39
uses : pypa/gh-action-pypi-publish@release/v1
Original file line number Diff line number Diff line change 5
5
* .db
6
6
* .egg-info /
7
7
* .pyc
8
+ build /
8
9
dist /
9
10
test.db
Original file line number Diff line number Diff line change 1
1
import threading
2
+ import warnings
2
3
3
4
from ._engine_util import create_engine
4
5
@@ -11,6 +12,7 @@ class Engine:
11
12
"""
12
13
13
14
def __init__ (self , url ):
15
+ url = _replace_scheme_if_postgres (url )
14
16
self ._engine = create_engine (url )
15
17
16
18
def get_transaction_connection (self ):
@@ -64,3 +66,23 @@ def _thread_local_connections():
64
66
connections = thread_local_data .connections = {}
65
67
66
68
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):
169
169
def test_cte (self ):
170
170
self .assertEqual (self .db .execute ("WITH foo AS ( SELECT 1 AS bar ) SELECT bar FROM foo" ), [{"bar" : 1 }])
171
171
172
+ def test_postgres_scheme (self ):
173
+ db = SQL (
"postgres://postgres:[email protected] /test" )
174
+ db .execute ("SELECT 1" )
172
175
173
176
class SQLiteTests (SQLTests ):
174
177
You can’t perform that action at this time.
0 commit comments