diff options
author | Michaël Ball <michael.ball@gmail.com> | 2014-12-24 17:52:04 +0000 |
---|---|---|
committer | Michaël Ball <michael.ball@gmail.com> | 2014-12-24 17:52:04 +0000 |
commit | 601198884d58c0f3825e7108a9adb4dc4353ff5c (patch) | |
tree | 61740d70677e3da94ded71d8a9a6ec741dd5b24c /models/album.py | |
parent | 765a2d306b1d64480933999af96a7df6e9053934 (diff) |
Better searching methods
Diffstat (limited to 'models/album.py')
-rw-r--r-- | models/album.py | 20 |
1 files changed, 17 insertions, 3 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") |