mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Support SQLAlchemy 1.4 URL.create recommendation
This fixes a deprecating warning when using SQLAlchemy 1.4. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
81856f3b64
commit
82f3871a83
2 changed files with 12 additions and 2 deletions
|
@ -6,3 +6,4 @@ include = aurweb/*
|
||||||
fail_under = 85
|
fail_under = 85
|
||||||
exclude_lines =
|
exclude_lines =
|
||||||
if __name__ == .__main__.:
|
if __name__ == .__main__.:
|
||||||
|
pragma: no cover
|
||||||
|
|
13
aurweb/db.py
13
aurweb/db.py
|
@ -16,9 +16,18 @@ def get_sqlalchemy_url():
|
||||||
Build an SQLAlchemy for use with create_engine based on the aurweb configuration.
|
Build an SQLAlchemy for use with create_engine based on the aurweb configuration.
|
||||||
"""
|
"""
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
|
|
||||||
|
constructor = sqlalchemy.engine.url.URL
|
||||||
|
|
||||||
|
parts = sqlalchemy.__version__.split('.')
|
||||||
|
major = int(parts[0])
|
||||||
|
minor = int(parts[1])
|
||||||
|
if major == 1 and minor >= 4: # pragma: no cover
|
||||||
|
constructor = sqlalchemy.engine.url.URL.create
|
||||||
|
|
||||||
aur_db_backend = aurweb.config.get('database', 'backend')
|
aur_db_backend = aurweb.config.get('database', 'backend')
|
||||||
if aur_db_backend == 'mysql':
|
if aur_db_backend == 'mysql':
|
||||||
return sqlalchemy.engine.url.URL(
|
return constructor(
|
||||||
'mysql+mysqlconnector',
|
'mysql+mysqlconnector',
|
||||||
username=aurweb.config.get('database', 'user'),
|
username=aurweb.config.get('database', 'user'),
|
||||||
password=aurweb.config.get('database', 'password'),
|
password=aurweb.config.get('database', 'password'),
|
||||||
|
@ -29,7 +38,7 @@ def get_sqlalchemy_url():
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
elif aur_db_backend == 'sqlite':
|
elif aur_db_backend == 'sqlite':
|
||||||
return sqlalchemy.engine.url.URL(
|
return constructor(
|
||||||
'sqlite',
|
'sqlite',
|
||||||
database=aurweb.config.get('database', 'name'),
|
database=aurweb.config.get('database', 'name'),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue