ibs/sql_app/models.py
HeshamTB b0dc22070e
sql_app: basic models and schemas from FastAPI docs
- Classes in models describe tables in database

	- Classes in schemas desribe pydantic models to
	read from the API.

	- database provides a connection and sessions to
	the database.

	- crud exposes the interface to the database, i.e.
	actions we can take from the application onto the
	database

Signed-off-by: HeshamTB <hishaminv@gmail.com>
2022-03-03 15:49:26 +03:00

26 lines
715 B
Python

from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
from .database import Base
class User(Base):
__tablename__ = "user_accounts"
id = Column(Integer, primary_key=True, index=True)
email = Column(String, unique=True, index=True)
hashed_password = Column(String)
is_active = Column(Boolean, default=True)
items = relationship("Item", back_populates="owner")
class IotEntity(Base):
__tablename__ = "iot_entities"
id = Column(Integer, primary_key=True, index=True)
description = Column(String, index=True)
owner_id = Column(Integer, ForeignKey("users.id"))
owner = relationship("User", back_populates="items")