Instance: add GetDatabaseOrThrow()
This commit is contained in:
@@ -54,19 +54,17 @@ static CommandResult
|
||||
handle_sticker_song(Response &r, Partition &partition, Request args)
|
||||
{
|
||||
Error error;
|
||||
const Database *db = partition.GetDatabase(error);
|
||||
if (db == nullptr)
|
||||
return print_error(r, error);
|
||||
const Database &db = partition.GetDatabaseOrThrow();
|
||||
|
||||
const char *const cmd = args.front();
|
||||
|
||||
/* get song song_id key */
|
||||
if (args.size == 4 && StringIsEqual(cmd, "get")) {
|
||||
const LightSong *song = db->GetSong(args[2]);
|
||||
const LightSong *song = db.GetSong(args[2]);
|
||||
|
||||
const auto value = sticker_song_get_value(*song, args[3],
|
||||
error);
|
||||
db->ReturnSong(song);
|
||||
db.ReturnSong(song);
|
||||
if (value.empty()) {
|
||||
if (error.IsDefined())
|
||||
return print_error(r, error);
|
||||
@@ -80,11 +78,11 @@ handle_sticker_song(Response &r, Partition &partition, Request args)
|
||||
return CommandResult::OK;
|
||||
/* list song song_id */
|
||||
} else if (args.size == 3 && StringIsEqual(cmd, "list")) {
|
||||
const LightSong *song = db->GetSong(args[2]);
|
||||
const LightSong *song = db.GetSong(args[2]);
|
||||
assert(song != nullptr);
|
||||
|
||||
Sticker *sticker = sticker_song_get(*song, error);
|
||||
db->ReturnSong(song);
|
||||
db.ReturnSong(song);
|
||||
if (sticker) {
|
||||
sticker_print(r, *sticker);
|
||||
sticker_free(sticker);
|
||||
@@ -94,12 +92,12 @@ handle_sticker_song(Response &r, Partition &partition, Request args)
|
||||
return CommandResult::OK;
|
||||
/* set song song_id id key */
|
||||
} else if (args.size == 5 && StringIsEqual(cmd, "set")) {
|
||||
const LightSong *song = db->GetSong(args[2]);
|
||||
const LightSong *song = db.GetSong(args[2]);
|
||||
assert(song != nullptr);
|
||||
|
||||
bool ret = sticker_song_set_value(*song, args[3], args[4],
|
||||
error);
|
||||
db->ReturnSong(song);
|
||||
db.ReturnSong(song);
|
||||
if (!ret) {
|
||||
if (error.IsDefined())
|
||||
return print_error(r, error);
|
||||
@@ -113,13 +111,13 @@ handle_sticker_song(Response &r, Partition &partition, Request args)
|
||||
/* delete song song_id [key] */
|
||||
} else if ((args.size == 3 || args.size == 4) &&
|
||||
StringIsEqual(cmd, "delete")) {
|
||||
const LightSong *song = db->GetSong(args[2]);
|
||||
const LightSong *song = db.GetSong(args[2]);
|
||||
assert(song != nullptr);
|
||||
|
||||
bool ret = args.size == 3
|
||||
? sticker_song_delete(*song, error)
|
||||
: sticker_song_delete_value(*song, args[3], error);
|
||||
db->ReturnSong(song);
|
||||
db.ReturnSong(song);
|
||||
if (!ret) {
|
||||
if (error.IsDefined())
|
||||
return print_error(r, error);
|
||||
@@ -163,7 +161,7 @@ handle_sticker_song(Response &r, Partition &partition, Request args)
|
||||
args[3],
|
||||
};
|
||||
|
||||
if (!sticker_song_find(*db, base_uri, data.name,
|
||||
if (!sticker_song_find(db, base_uri, data.name,
|
||||
op, value,
|
||||
sticker_song_find_print_cb, &data,
|
||||
error)) {
|
||||
|
Reference in New Issue
Block a user