forked from swingmx/swingmusic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.py
74 lines (54 loc) · 1.92 KB
/
db.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from sqlalchemy import create_engine, text, Table, Column, Integer, String, MetaData, select
from sqlalchemy.orm import DeclarativeBase
from typing import List, Optional
from sqlalchemy.orm import Mapped, mapped_column, relationship
fullpath = "/home/cwilvx/temp/swingmusic/swing.db"
engine = create_engine(f"sqlite+pysqlite:///{fullpath}", echo=True)
class Base(DeclarativeBase):
pass
class Tracks(Base):
__tablename__ = "tracks"
id: Mapped[int] = mapped_column(primary_key=True)
album: Mapped[str] = mapped_column(String())
albumartist: Mapped[str] = mapped_column(String())
copyright: Mapped[Optional[str]]
def __repr__(self):
return f"<Tracks(album={self.album}, albumartist={self.albumartist})>"
stmt = select(Tracks.album, Tracks.copyright).where(Tracks.album == "RAVAGE")
print(stmt)
with engine.connect() as conn:
result = conn.execute(stmt)
for row in result:
print(row)
# Base.metadata.create_all(engine)
# metadata = MetaData()
# track_table = Table(
# "tracks",
# metadata,
# Column("id", Integer, primary_key=True, autoincrement=True),
# Column("album", String),
# Column("albumartist", String),
# Column("albumhash", String),
# Column("artist", String),
# Column("bitrate", Integer),
# Column("copyright", String),
# Column("date", Integer),
# Column("disc", Integer),
# Column("duration", Integer),
# Column("filepath", String),
# Column("folder", String),
# Column("genre", String),
# Column("title", String),
# Column("track", Integer),
# Column("trackhash", String),
# Column("last_mod", Integer),
# )
# metadata.create_all(engine)
# with engine.connect() as conn:
# result = conn.execute(
# text("SELECT * FROM tracks where trackhash = :trackhash"),
# {"trackhash": "93acbea22b"},
# )
# # print(result.all())
# for r in result.mappings():
# print(r["trackhash"])