diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-05-16 14:11:38 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-05-16 14:11:38 +1000 |
| commit | d71f726c42963d55809605b4dc4144970ca0f230 (patch) | |
| tree | 5dc8e6355f5e870e767c3d23ec4009bc39155821 /src/main/app_console.cpp | |
| parent | 785349eb5b3255d0a51ca7459531f75cb47c90ac (diff) | |
| download | tangara-fw-d71f726c42963d55809605b4dc4144970ca0f230.tar.gz | |
Add pagination to database queries
Diffstat (limited to 'src/main/app_console.cpp')
| -rw-r--r-- | src/main/app_console.cpp | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/main/app_console.cpp b/src/main/app_console.cpp index 759afa91..a85faaf0 100644 --- a/src/main/app_console.cpp +++ b/src/main/app_console.cpp @@ -176,15 +176,15 @@ int CmdDbSongs(int argc, char** argv) { return 1; } - database::Result<database::Song> res = - sInstance->database_->GetSongs(20).get(); + std::unique_ptr<database::Result<database::Song>> res( + sInstance->database_->GetSongs(5).get()); while (true) { - std::unique_ptr<std::vector<database::Song>> r(res.values()); - for (database::Song s : *r) { + for (database::Song s : res->values()) { std::cout << s.tags().title.value_or("[BLANK]") << std::endl; } - if (res.HasMore()) { - res = sInstance->database_->GetMoreSongs(10, res.continuation()).get(); + if (res->next_page()) { + auto continuation = res->next_page().value(); + res.reset(sInstance->database_->GetPage(&continuation).get()); } else { break; } @@ -211,17 +211,18 @@ int CmdDbDump(int argc, char** argv) { std::cout << "=== BEGIN DUMP ===" << std::endl; - database::Result<std::string> res = sInstance->database_->GetDump(20).get(); + std::unique_ptr<database::Result<std::string>> res( + sInstance->database_->GetDump(5).get()); while (true) { - std::unique_ptr<std::vector<std::string>> r(res.values()); - if (r == nullptr) { - break; - } - for (std::string s : *r) { + for (std::string s : res->values()) { std::cout << s << std::endl; } - if (res.HasMore()) { - res = sInstance->database_->GetMoreDump(20, res.continuation()).get(); + if (res->next_page()) { + auto continuation = res->next_page().value(); + res.reset( + sInstance->database_->GetPage<std::string>(&continuation).get()); + } else { + break; } } |
