From 45ea7499b2b94e4e1cc7bd0ddcdd9b592444efec Mon Sep 17 00:00:00 2001 From: krateng Date: Sun, 17 Apr 2022 20:18:26 +0200 Subject: [PATCH] Added some return values to database --- maloja/apis/native_v1.py | 25 ++++++++++++++++++++----- maloja/database/__init__.py | 18 ++++++++++++++---- maloja/database/sqldb.py | 12 +++++++++++- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/maloja/apis/native_v1.py b/maloja/apis/native_v1.py index 2f5087f..2a51a83 100644 --- a/maloja/apis/native_v1.py +++ b/maloja/apis/native_v1.py @@ -588,30 +588,45 @@ def get_export(**keys): @authenticated_function(api=True) def delete_scrobble(timestamp): """Internal Use Only""" - return database.remove_scrobble(timestamp) + result = database.remove_scrobble(timestamp) + return { + "status":"success" + } @api.post("edit_artist") @authenticated_function(api=True) def edit_artist(id,name): """Internal Use Only""" - return database.edit_artist(id,name) + result = database.edit_artist(id,name) + return { + "status":"success" + } @api.post("edit_track") @authenticated_function(api=True) def edit_track(id,title): """Internal Use Only""" - return database.edit_track(id,{'title':title}) + result = database.edit_track(id,{'title':title}) + return { + "status":"success" + } @api.post("merge_tracks") @authenticated_function(api=True) def merge_tracks(target_id,source_ids): """Internal Use Only""" - return database.merge_tracks(target_id,source_ids) + result = database.merge_tracks(target_id,source_ids) + return { + "status":"success" + } @api.post("merge_artists") @authenticated_function(api=True) def merge_artists(target_id,source_ids): """Internal Use Only""" - return database.merge_artists(target_id,source_ids) + result = database.merge_artists(target_id,source_ids) + return { + "status":"success" + } diff --git a/maloja/database/__init__.py b/maloja/database/__init__.py index 45c7f79..5b56455 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -146,38 +146,48 @@ def remove_scrobble(timestamp): result = sqldb.delete_scrobble(timestamp) dbcache.invalidate_caches(timestamp) + return result + @waitfordb def edit_artist(id,artistinfo): artist = sqldb.get_artist(id) log(f"Renaming {artist} to {artistinfo}") - sqldb.edit_artist(id,artistinfo) + result = sqldb.edit_artist(id,artistinfo) dbcache.invalidate_entity_cache() dbcache.invalidate_caches() + return result + @waitfordb def edit_track(id,trackinfo): track = sqldb.get_track(id) log(f"Renaming {track['title']} to {trackinfo['title']}") - sqldb.edit_track(id,trackinfo) + result = sqldb.edit_track(id,trackinfo) dbcache.invalidate_entity_cache() dbcache.invalidate_caches() + return result + @waitfordb def merge_artists(target_id,source_ids): sources = [sqldb.get_artist(id) for id in source_ids] target = sqldb.get_artist(target_id) log(f"Merging {sources} into {target}") - sqldb.merge_artists(target_id,source_ids) + result = sqldb.merge_artists(target_id,source_ids) dbcache.invalidate_entity_cache() + return result + @waitfordb def merge_tracks(target_id,source_ids): sources = [sqldb.get_track(id) for id in source_ids] target = sqldb.get_track(target_id) log(f"Merging {sources} into {target}") - sqldb.merge_tracks(target_id,source_ids) + result = sqldb.merge_tracks(target_id,source_ids) dbcache.invalidate_entity_cache() + return result + diff --git a/maloja/database/sqldb.py b/maloja/database/sqldb.py index ff4037d..9c4f638 100644 --- a/maloja/database/sqldb.py +++ b/maloja/database/sqldb.py @@ -275,7 +275,9 @@ def delete_scrobble(scrobble_id,dbconn=None): DB['scrobbles'].c.timestamp == scrobble_id ) - dbconn.execute(op) + result = dbconn.execute(op) + + return True ### these will 'get' the ID of an entity, creating it if necessary @@ -367,6 +369,8 @@ def edit_artist(id,artistdict,dbconn=None): ) result = dbconn.execute(op) + return True + @connection_provider def edit_track(id,trackdict,dbconn=None): dbentry = track_dict_to_db(trackdict) @@ -378,6 +382,8 @@ def edit_track(id,trackdict,dbconn=None): ) result = dbconn.execute(op) + return True + ### Merge @@ -392,6 +398,8 @@ def merge_tracks(target_id,source_ids,dbconn=None): result = dbconn.execute(op) clean_db() + return True + @connection_provider def merge_artists(target_id,source_ids,dbconn=None): @@ -403,6 +411,8 @@ def merge_artists(target_id,source_ids,dbconn=None): result = dbconn.execute(op) clean_db() + return True + ### Functions that get rows according to parameters