Add SQLAlchemy and database boilerplate code
This commit is contained in:
parent
2da6e43797
commit
31df889dcb
15 changed files with 454 additions and 60 deletions
1
tofu_api/models/__init__.py
Normal file
1
tofu_api/models/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from .task import Task
|
||||
25
tofu_api/models/task.py
Normal file
25
tofu_api/models/task.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
from sqlalchemy import Column, Integer, String, Text
|
||||
|
||||
from tofu_api.common.database import Model
|
||||
|
||||
|
||||
class Task(Model):
|
||||
"""
|
||||
Database model for tasks.
|
||||
"""
|
||||
|
||||
__tablename__ = 'tasks'
|
||||
|
||||
id: int = Column(Integer, nullable=False, primary_key=True)
|
||||
# TODO: created_at, modified_at
|
||||
|
||||
title: str = Column(String(255), nullable=False)
|
||||
description: str = Column(Text, nullable=False, default='')
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
# TODO: Implement a generic to_dict() in the base model
|
||||
return {
|
||||
'id': self.id,
|
||||
'title': self.title,
|
||||
'description': self.description,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue