summaryrefslogtreecommitdiff
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/album.py20
-rw-r--r--models/artist.py20
-rw-r--r--models/track.py22
3 files changed, 53 insertions, 9 deletions
diff --git a/models/album.py b/models/album.py
index 727156f..24af0b5 100644
--- a/models/album.py
+++ b/models/album.py
@@ -87,22 +87,36 @@ class Album():
set_clause = utils.update_clause_from_dict(dirty_attributes)
dirty_attributes[id] = self.id
-
+
sql = " ".join(("UPDATE album"), set_clause, "WHERE id = :id")
db.execute(sql, dirty_attributes)
db.commit()
def search(**search_params):
+ """Find an album with the given params
+
+ Args:
+ name: dict, with 'data' and 'operator' keys
+ date: dict, with 'data' and 'operator' keys
+ musicbrainz_albumid: dict, with 'data' and 'operator' keys
+ """
albums = []
db = DbManager()
- where_clause = utils.make_where_clause(search_params)
+ # unpack search params
+ where_params = {}
+ value_params = {}
+ for (attr, value) in search_params.items():
+ where_params[attr] = value["operator"]
+ value_params[attr] = value["data"]
+
+ where_clause = utils.make_where_clause(where_params)
result = None
if where_clause:
statement = " ".join(("SELECT * FROM album", where_clause))
- result = db.execute(statement, search_params)
+ result = db.execute(statement, value_params)
else:
result = db.execute("SELECT * FROM album")
diff --git a/models/artist.py b/models/artist.py
index eaae27e..7d36457 100644
--- a/models/artist.py
+++ b/models/artist.py
@@ -87,22 +87,36 @@ class Artist:
set_clause = utils.update_clause_from_dict(dirty_attributes)
dirty_attributes[id] = self.id
-
+
sql = " ".join(("UPDATE artist"), set_clause, "WHERE id = :id")
db.execute(sql, dirty_attributes)
db.commit()
def search(**search_params):
+ """Find an artist with the given params
+
+ Args:
+ name: dict, with 'data' and 'operator' keys
+ sortname: dict, with 'data' and 'operator' keys
+ musicbrainz_artist_id: dict, with 'data' and 'operator' keys
+ """
artists = []
db = DbManager()
- where_clause = utils.make_where_clause(search_params)
+ # unpack search params
+ where_params = {}
+ value_params = {}
+ for (attr, value) in search_params.items():
+ where_params[attr] = value["operator"]
+ value_params[attr] = value["data"]
+
+ where_clause = utils.make_where_clause(where_params)
result = []
if where_clause:
statement = " ".join(("SELECT * FROM artist", where_clause))
- result = db.execute(statement, search_params)
+ result = db.execute(statement, value_params)
else:
result = db.execute("SELECT * FROM artist")
diff --git a/models/track.py b/models/track.py
index 264db81..90eba9f 100644
--- a/models/track.py
+++ b/models/track.py
@@ -271,21 +271,37 @@ class Track:
set_clause = utils.update_clause_from_dict(dirty_attributes)
dirty_attributes[id] = self.id
-
+
sql = " ".join(("UPDATE track"), set_clause, "WHERE id = :id")
db.execute(sql, dirty_attributes)
db.commit()
def search(**search_params):
+ """Find a track with the given params
+
+ Args:
+ tracknumber: dict, with 'data' and 'operator' keys
+ name: dict, with 'data' and 'operator' keys
+ grouping: dict, with 'data' and 'operator' keys
+ filename: dict, with 'data' and 'operator' keys
+ """
+
db = DbManager()
tracks = []
- where_clause = utils.make_where_clause(search_params)
+ # unpack search params
+ where_params = {}
+ value_params = {}
+ for (attr, value) in search_params.items():
+ where_params[attr] = value["operator"]
+ value_params[attr] = value["data"]
+
+ where_clause = utils.make_where_clause(where_params)
result = None
if where_clause:
statement = " ".join(("SELECT * FROM track", where_clause))
- result = db.execute(statement, search_params)
+ result = db.execute(statement, value_params)
else:
result = db.execute("SELECT * FROM track")