-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathartists.py
More file actions
31 lines (25 loc) · 1.17 KB
/
Copy pathartists.py
File metadata and controls
31 lines (25 loc) · 1.17 KB
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
from db import db
def get_all_artists():
sql = "SELECT DISTINCT id, aname FROM artists ORDER BY aname"
return db.session.execute(sql).fetchall()
def add_artist(creator_id, genre_id, aname):
sql = """INSERT INTO artists (creator_id, genre_id, aname)
VALUES (:creator_id, :genre_id, :aname) RETURNING id"""
artist_id = db.session.execute(sql, {"creator_id":creator_id, "genre_id":genre_id, "aname":aname}).fetchone()[0]
db.session.commit()
return artist_id
def get_by_id(artist_id):
sql = """SELECT id, aname FROM artists WHERE id=:artist_id"""
artist = db.session.execute(sql, {"artist_id":artist_id}).fetchone()
return artist
def check_if_exists(aname):
sql = """SELECT EXISTS
(SELECT 1 FROM artists WHERE aname=:aname)"""
truthValue = db.session.execute(sql, {"aname":aname}).fetchone()
return truthValue
def get_id_by_name(aname):
sql = """SELECT id FROM artists WHERE aname=:aname"""
return db.session.execute(sql, {"aname":aname}).fetchone()
def get_artists_by_genre_id(genre_id):
sql = """SELECT id, aname FROM artists WHERE genre_id=:genre_id"""
return db.session.execute(sql, {"genre_id":genre_id}).fetchall()