From 601198884d58c0f3825e7108a9adb4dc4353ff5c Mon Sep 17 00:00:00 2001 From: Michaƫl Ball Date: Wed, 24 Dec 2014 17:52:04 +0000 Subject: Better searching methods --- models/artist.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'models/artist.py') 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") -- cgit v1.2.3