-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
27 lines (19 loc) · 748 Bytes
/
database.py
File metadata and controls
27 lines (19 loc) · 748 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
from typing import Optional
from datetime import datetime
from sqlmodel import Field, SQLModel, create_engine
DB_FILE = 'db.sqlite3'
engine = create_engine(f"sqlite:///{DB_FILE}", echo=True)
class TrackModel(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
title: str
artist: str
duration: float
last_play: str
def create_tables():
"""Create the tables registered with SQLModel.metadata (i.e classes with table=True).
More info: https://sqlmodel.tiangolo.com/tutorial/create-db-and-table/#sqlmodel-metadata
"""
SQLModel.metadata.create_all(engine)
# if __name__ == '__main__':
# # creates the table if this file is run independently, as a script
# create_tables()