52 lines
1.0 KiB
Python
52 lines
1.0 KiB
Python
from datetime import timedelta
|
|
from typing import Any, Optional
|
|
|
|
from peewee import (
|
|
BooleanField,
|
|
DatabaseProxy,
|
|
DateTimeField,
|
|
Field,
|
|
ForeignKeyField,
|
|
IntegerField,
|
|
Model,
|
|
TextField,
|
|
)
|
|
|
|
proxy = DatabaseProxy()
|
|
|
|
|
|
class BaseModel(Model):
|
|
class Meta:
|
|
database = proxy
|
|
|
|
|
|
class DurationField(IntegerField):
|
|
def db_value(self, value: timedelta) -> Optional[int]:
|
|
return value.microseconds if value else None
|
|
|
|
def python_value(self, value: Optional[int]) -> Optional[timedelta]:
|
|
return timedelta(microseconds=value) if value else None
|
|
|
|
|
|
class CoverArt(BaseModel):
|
|
id = TextField(unique=True, primary_key=True)
|
|
url = TextField()
|
|
filename = TextField(null=True)
|
|
|
|
|
|
class Playlist(BaseModel):
|
|
id = TextField(unique=True, primary_key=True)
|
|
name = TextField()
|
|
song_count = IntegerField()
|
|
duration = DurationField()
|
|
created = DateTimeField()
|
|
changed = DateTimeField()
|
|
public = BooleanField()
|
|
cover_art = TextField()
|
|
|
|
|
|
ALL_TABLES = (
|
|
CoverArt,
|
|
Playlist,
|
|
)
|