add Package SQLAlchemy ORM model

Additionally, add an optional **kwargs passing via make_relationship.
This allows us to use things like `uselist=False`, which was needed
for test/test_package.py.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-06-01 00:25:49 -07:00
parent 621e459dfb
commit 15b1332656
3 changed files with 106 additions and 2 deletions

View file

@ -53,9 +53,10 @@ def make_random_value(table: str, column: str):
return string
def make_relationship(model, foreign_key, backref_):
def make_relationship(model, foreign_key: str, backref_: str, **kwargs):
return relationship(model, foreign_keys=[foreign_key],
backref=backref(backref_, lazy="dynamic"))
backref=backref(backref_, lazy="dynamic"),
**kwargs)
def query(model, *args, **kwargs):

24
aurweb/models/package.py Normal file
View file

@ -0,0 +1,24 @@
from sqlalchemy.orm import mapper
from aurweb.db import make_relationship
from aurweb.models.package_base import PackageBase
from aurweb.schema import Packages
class Package:
def __init__(self,
PackageBase: PackageBase = None,
Name: str = None, Version: str = None,
Description: str = None, URL: str = None):
self.PackageBase = PackageBase
self.Name = Name
self.Version = Version
self.Description = Description
self.URL = URL
mapper(Package, Packages, properties={
"PackageBase": make_relationship(PackageBase,
Packages.c.PackageBaseID,
"package", uselist=False)
})