mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
use declarative_base for all ORM models
This rewrites the entire model base as declarative models. This allows us to more easily customize overlay fields in tables and is more common. This effort also brought some DB violations to light which this commit addresses. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
7f7a975614
commit
888cf5118a
29 changed files with 398 additions and 292 deletions
13
aurweb/db.py
13
aurweb/db.py
|
@ -1,7 +1,5 @@
|
|||
import math
|
||||
|
||||
from sqlalchemy.orm import backref, relationship
|
||||
|
||||
import aurweb.config
|
||||
import aurweb.util
|
||||
|
||||
|
@ -53,12 +51,6 @@ def make_random_value(table: str, column: str):
|
|||
return string
|
||||
|
||||
|
||||
def make_relationship(model, foreign_key: str, backref_: str, **kwargs):
|
||||
return relationship(model, foreign_keys=[foreign_key],
|
||||
backref=backref(backref_, lazy="dynamic"),
|
||||
**kwargs)
|
||||
|
||||
|
||||
def query(model, *args, **kwargs):
|
||||
return session.query(model).filter(*args, **kwargs)
|
||||
|
||||
|
@ -77,6 +69,10 @@ def delete(model, *args, **kwargs):
|
|||
session.commit()
|
||||
|
||||
|
||||
def rollback():
|
||||
session.rollback()
|
||||
|
||||
|
||||
def get_sqlalchemy_url():
|
||||
"""
|
||||
Build an SQLAlchemy for use with create_engine based on the aurweb configuration.
|
||||
|
@ -137,7 +133,6 @@ def get_engine(echo: bool = False):
|
|||
# check_same_thread is for a SQLite technicality
|
||||
# https://fastapi.tiangolo.com/tutorial/sql-databases/#note
|
||||
connect_args["check_same_thread"] = False
|
||||
|
||||
engine = create_engine(get_sqlalchemy_url(),
|
||||
connect_args=connect_args,
|
||||
echo=echo)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue