mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 14:33:33 -07:00
sqlalchemy models
This commit is contained in:
parent
ed883013de
commit
e978e2978b
7 changed files with 78 additions and 1 deletions
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"python.formatting.provider": "black",
|
||||
"python.pythonPath": "/home/hayden/Projects/mealie/.venv/bin/python3",
|
||||
"python.pythonPath": "venv/bin/python3.8",
|
||||
"python.linting.pylintEnabled": true,
|
||||
"python.linting.enabled": true,
|
||||
"python.autoComplete.extraPaths": ["mealie", "mealie/mealie"],
|
||||
|
|
1
mealie/db/sql/_all_models.py
Normal file
1
mealie/db/sql/_all_models.py
Normal file
|
@ -0,0 +1 @@
|
|||
from db.sql.recipe_models import RecipeModel
|
24
mealie/db/sql/db_session.py
Normal file
24
mealie/db/sql/db_session.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
from pathlib import Path
|
||||
|
||||
import sqlalchemy as sa
|
||||
import sqlalchemy.orm as orm
|
||||
from db.sql.model_base import SqlAlchemyBase
|
||||
|
||||
factory = None
|
||||
|
||||
|
||||
def globa_init(db_file: Path):
|
||||
global factory
|
||||
|
||||
if factory:
|
||||
return
|
||||
|
||||
conn_str = "sqlite:///" + db_file.absolute()
|
||||
|
||||
engine = sa.create_engine(conn_str, echo=False)
|
||||
|
||||
factory = orm.sessionmaker(bind=engine)
|
||||
|
||||
import db.sql._all_models
|
||||
|
||||
SqlAlchemyBase.metadata.create_all(engine)
|
0
mealie/db/sql/meal_models.py
Normal file
0
mealie/db/sql/meal_models.py
Normal file
3
mealie/db/sql/model_base.py
Normal file
3
mealie/db/sql/model_base.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
import sqlalchemy.ext.declarative as dec
|
||||
|
||||
SqlAlchemyBase = dec.declarative_base()
|
49
mealie/db/sql/recipe_models.py
Normal file
49
mealie/db/sql/recipe_models.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
from datetime import date
|
||||
|
||||
import sqlalchemy as sa
|
||||
import sqlalchemy.orm as orm
|
||||
from db.sql.model_base import SqlAlchemyBase
|
||||
|
||||
|
||||
class RecipeModel(SqlAlchemyBase):
|
||||
__tablename__ = 'recipes'
|
||||
# id = mongoengine.UUIDField(primary_key=True)
|
||||
name = sa.Column(sa.String)
|
||||
description = sa.Column(sa.String)
|
||||
image = sa.Column(sa.String)
|
||||
recipeYield = sa.Column(sa.String)
|
||||
recipeIngredient = orm.relation("RecipeIngredient")
|
||||
recipeInstructions = orm.relation("RecipeInstruction")
|
||||
totalTime = sa.Column(sa.String)
|
||||
|
||||
# Mealie Specific
|
||||
slug = sa.Column(sa.String, primary_key=True, index=True, unique=True)
|
||||
categories = orm.relation("Category")
|
||||
tags = orm.relation("Tag")
|
||||
dateAdded = sa.Column(sa.Date, default=date.today())
|
||||
notes = orm.relation("Note")
|
||||
rating = sa.Column(sa.Integer)
|
||||
orgURL = sa.Column(sa.String)
|
||||
# extras =
|
||||
|
||||
|
||||
class Category(SqlAlchemyBase):
|
||||
name = sa.Column(sa.String, index=True)
|
||||
|
||||
|
||||
class Tag(SqlAlchemyBase):
|
||||
name = sa.Column(sa.String, index=True)
|
||||
|
||||
|
||||
class Note(SqlAlchemyBase):
|
||||
title = sa.Column(sa.String)
|
||||
text = sa.Column(sa.String)
|
||||
|
||||
|
||||
class RecipeIngredient(SqlAlchemyBase):
|
||||
ingredient: sa.Column(sa.String)
|
||||
|
||||
|
||||
class RecipeInstruction(SqlAlchemyBase):
|
||||
type = sa.Column(sa.String)
|
||||
text = sa.Column(sa.String)
|
0
mealie/db/sql/settings_models.py
Normal file
0
mealie/db/sql/settings_models.py
Normal file
Loading…
Add table
Add a link
Reference in a new issue