From ec1dee1a0fcc62e3223e7b029598fa506181b263 Mon Sep 17 00:00:00 2001 From: Hellow Date: Mon, 13 Feb 2023 17:07:36 +0100 Subject: [PATCH] Update database.py --- src/music_kraken/database/database.py | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/music_kraken/database/database.py b/src/music_kraken/database/database.py index 6a53d0e..627c48a 100644 --- a/src/music_kraken/database/database.py +++ b/src/music_kraken/database/database.py @@ -20,6 +20,38 @@ from .objects import ( SourceAttribute ) +""" +import peewee + +db = peewee.SqliteDatabase('music.db') + +class BaseModel(peewee.Model): + class Meta: + database = db + +class Artist(BaseModel): + name = peewee.CharField() + +class Song(BaseModel): + title = peewee.CharField() + artist = peewee.ManyToManyField(Artist, backref='songs') + +db.connect() +db.create_tables([Artist, Song, Song.artist.get_through_model()], safe=True) + +# Adding a song and its artists +beatles = Artist.create(name='The Beatles') +rolling_stones = Artist.create(name='The Rolling Stones') +song = Song.create(title='Hey Jude') +song.artist.add(beatles, rolling_stones) + +# Querying songs by artist +songs = Song.select().join(Song.artist).where(Artist.name == 'The Beatles') +for song in songs: + print(song.title) + +""" + logger = logging.getLogger("database") # Due to this not being deployed on a Server **HOPEFULLY**