summaryrefslogtreecommitdiffstats
path: root/aurweb/db.py
diff options
context:
space:
mode:
authorFrédéric Mangano-Tarumi <fmang@mg0.fr>2020-02-16 21:56:10 +0100
committerLukas Fleischer <lfleischer@archlinux.org>2020-02-27 16:44:36 +0100
commit7188743fc3b1a9c1f5f65e323a6502d018bd95d5 (patch)
treed313ae39015fd5b664206048a946f420aecc7775 /aurweb/db.py
parent4b2102ceb26b77bc8ee3e9b9d8929a915f1e65a9 (diff)
downloadaur-7188743fc3b1a9c1f5f65e323a6502d018bd95d5.tar.gz
aur-7188743fc3b1a9c1f5f65e323a6502d018bd95d5.tar.xz
Migrate the database schema to SQLAlchemy
The new schema was generated with sqlacodegen and then manually adjusted to fit schema/aur-schema.sql faithfully, both in the organisation of the code and in the SQL generated by SQLAlchemy. Initializing the database now requires the new tool aurweb.initdb. References to aur-schema.sql have been updated and the old schema dropped. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Diffstat (limited to 'aurweb/db.py')
-rw-r--r--aurweb/db.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/aurweb/db.py b/aurweb/db.py
index c6d4de11..1ccd9a07 100644
--- a/aurweb/db.py
+++ b/aurweb/db.py
@@ -11,6 +11,33 @@ except ImportError:
import aurweb.config
+def get_sqlalchemy_url():
+ """
+ Build an SQLAlchemy for use with create_engine based on the aurweb configuration.
+ """
+ import sqlalchemy
+ aur_db_backend = aurweb.config.get('database', 'backend')
+ if aur_db_backend == 'mysql':
+ return sqlalchemy.engine.url.URL(
+ 'mysql+mysqlconnector',
+ username=aurweb.config.get('database', 'user'),
+ password=aurweb.config.get('database', 'password'),
+ host=aurweb.config.get('database', 'host'),
+ database=aurweb.config.get('database', 'name'),
+ query={
+ 'unix_socket': aurweb.config.get('database', 'socket'),
+ 'buffered': True,
+ },
+ )
+ elif aur_db_backend == 'sqlite':
+ return sqlalchemy.engine.url.URL(
+ 'sqlite',
+ database=aurweb.config.get('database', 'name'),
+ )
+ else:
+ raise ValueError('unsupported database backend')
+
+
class Connection:
_conn = None
_paramstyle = None