-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
33 lines (20 loc) · 943 Bytes
/
db.py
File metadata and controls
33 lines (20 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
from datetime import datetime, timezone
from sqlalchemy import create_engine, String, Text, DateTime
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, sessionmaker
from dotenv import load_dotenv
load_dotenv()
DATABASE_URL = "sqlite:///lecture_notes.db"
engine = create_engine(DATABASE_URL, echo=False)
SessionLocal = sessionmaker(bind=engine)
class Base(DeclarativeBase):
pass
class Transcript(Base):
__tablename__ = "transcripts"
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
title: Mapped[str] = mapped_column(String(255), unique=True, nullable=False)
content: Mapped[str] =mapped_column(Text, nullable=False)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now(timezone.utc))
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now(timezone.utc))
def init_db():
Base.metadata.create_all(bind=engine)