Skip to content

Commit

Permalink
document v2
Browse files Browse the repository at this point in the history
  • Loading branch information
azliu0 committed Apr 15, 2024
1 parent 91dd99c commit b5252e0
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions server/models/document.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
"""Document."""

from sqlalchemy.orm import Mapped, mapped_column

from server import db


class Document(db.Model):
__tablename__ = "Documents"
"""Document.
id = db.Column(db.Integer, primary_key=True)
question = db.Column(db.Text(), nullable=False)
label = db.Column(db.Text(), nullable=False)
content = db.Column(db.Text(), nullable=False)
source = db.Column(db.Text(), nullable=False)
to_delete = db.Column(db.Boolean, default=False)
response_count = db.Column(db.Integer, default=0)
Table for storing documents.
id(str): The ID of the document.
question(str): The question of the document.
content(str): The content of the document.
source(str): The source of the document.
label(str): The label of the document.
to_delete(bool): Whether the document is to be deleted.
response_count(int): The number of responses the document has.
"""

__tablename__ = "Documents"

def __init__(self, question, content, source, label):
self.question = question
self.content = content
self.source = source
self.label = label
id: Mapped[str] = mapped_column(primary_key=True)
question: Mapped[str] = mapped_column(nullable=False)
label: Mapped[str] = mapped_column(nullable=False)
content: Mapped[str] = mapped_column(nullable=False)
source: Mapped[str] = mapped_column(nullable=False)
to_delete: Mapped[bool] = mapped_column(default=False, init=False)
response_count: Mapped[int] = mapped_column(default=0, init=False)

def map(self):
"""Map the document to a dictionary."""
return {
"id": self.id,
"question": self.question,
Expand Down

0 comments on commit b5252e0

Please sign in to comment.