mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-08 12:15:39 +00:00
39 lines
1008 B
Python
39 lines
1008 B
Python
from app.db.sqlite.utils import SQLiteManager
|
|
|
|
|
|
class SQLiteTrackLogger:
|
|
@classmethod
|
|
def insert_track(cls, trackhash: str, duration: int, source: str, timestamp: int):
|
|
"""
|
|
Inserts a track into the database
|
|
"""
|
|
|
|
with SQLiteManager(userdata_db=True) as cur:
|
|
sql = """INSERT OR REPLACE INTO track_logger(
|
|
trackhash,
|
|
duration,
|
|
timestamp,
|
|
source,
|
|
userid
|
|
) VALUES(?,?,?,?,?)
|
|
"""
|
|
|
|
cur.execute(sql, (trackhash, duration, timestamp, source, 0))
|
|
lastrowid = cur.lastrowid
|
|
|
|
return lastrowid
|
|
|
|
@classmethod
|
|
def get_all(cls):
|
|
"""
|
|
Returns all tracks from the database
|
|
"""
|
|
|
|
with SQLiteManager(userdata_db=True) as cur:
|
|
sql = """SELECT * FROM track_logger ORDER BY timestamp DESC"""
|
|
|
|
cur.execute(sql)
|
|
rows = cur.fetchall()
|
|
|
|
return rows
|