75 lines
1.7 KiB
Python
75 lines
1.7 KiB
Python
"""Sigl Database ORM Setup.
|
|
|
|
Simple Grocery List (Sigl) | sigl.app
|
|
Copyright (c) 2022 Asymworks, LLC. All Rights Reserved.
|
|
"""
|
|
|
|
from sigl.domain.models import (
|
|
Product,
|
|
ProductLocation,
|
|
)
|
|
from sigl.domain.models.accessKey import AccessKey, AccessToken
|
|
from sigl.domain.models.list import ListEntry, ShoppingList
|
|
|
|
from .globals import db
|
|
from .tables import (
|
|
access_keys,
|
|
access_tokens,
|
|
list_entries,
|
|
lists,
|
|
product_locations,
|
|
products,
|
|
)
|
|
|
|
__all__ = ('init_orm', )
|
|
|
|
|
|
def init_orm():
|
|
"""Initialize the Sigl ORM."""
|
|
|
|
# # Access Keys
|
|
# db.mapper(AccessKey, access_keys, properties={
|
|
# 'tokens': db.relationship(
|
|
# AccessToken,
|
|
# backref='accessKey',
|
|
# cascade='all, delete-orphan',
|
|
# )
|
|
# })
|
|
|
|
# # Access Tokens
|
|
# db.mapper(AccessToken, access_tokens)
|
|
|
|
# # List Entries
|
|
# db.mapper(ListEntry, list_entries)
|
|
|
|
# Products
|
|
db.mapper(Product, products, properties={
|
|
'locations': db.relationship(
|
|
ProductLocation,
|
|
back_populates='product',
|
|
cascade='all, delete-orphan',
|
|
),
|
|
# 'shoppingLists': db.relationship(
|
|
# ShoppingList,
|
|
# backref='product',
|
|
# cascade='all, delete-orphan',
|
|
# ),
|
|
})
|
|
|
|
# Product Locations
|
|
db.mapper(ProductLocation, product_locations, properties={
|
|
'product': db.relationship(
|
|
Product,
|
|
back_populates='locations',
|
|
)
|
|
})
|
|
|
|
# # Shopping Lists
|
|
# db.mapper(ShoppingList, lists, properties={
|
|
# 'entries': db.relationship(
|
|
# ListEntry,
|
|
# backref='shoppingList',
|
|
# cascade='all, delete-orphan',
|
|
# )
|
|
# })
|