FlixRec/database.py

52 lines
1.4 KiB
Python
Raw Normal View History

2022-05-21 01:30:27 +01:00
import sqlalchemy
from sqlalchemy import create_engine
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey, PickleType
from sqlalchemy import insert
from sqlalchemy.orm import sessionmaker
from sqlalchemy.exc import IntegrityError
2022-05-22 18:42:00 +01:00
# database_url = "sqlite:///jlm.db"
2022-05-21 01:30:27 +01:00
meta = MetaData()
movies_table = Table(
"movies",
meta,
Column("trakt_id", Integer, primary_key=True, autoincrement=False),
Column("title", String),
Column("overview", String),
Column("genres", String),
Column("year", Integer),
Column("released", String),
Column("runtime", Integer),
Column("country", String),
Column("language", String),
Column("rating", Integer),
Column("votes", Integer),
Column("comment_count", Integer),
Column("tagline", String),
2022-05-22 18:42:00 +01:00
Column("embeddings", PickleType),
2022-05-21 01:30:27 +01:00
)
2022-05-22 18:42:00 +01:00
2022-05-21 01:30:27 +01:00
def init_db_stuff(database_url: str):
engine = create_engine(database_url)
meta.create_all(engine)
Session = sessionmaker(bind=engine)
return engine, Session
2022-05-22 18:42:00 +01:00
2022-05-21 01:30:27 +01:00
"""
movie = {
"title": movie["movie"]["title"],
"overview": movie["movie"]["overview"],
"genres": movie["movie"]["genres"],
"language": movie["movie"]["language"],
"year": movie["movie"]["year"],
"trakt_id": movie["movie"]["ids"]["trakt"],
"released": movie["movie"]["released"],
"runtime": movie["movie"]["runtime"],
"country": movie["movie"]["country"]
}
2022-05-22 18:42:00 +01:00
"""