database: pagedao: Add findByTitle()

This commit is contained in:
Albert S. 2022-03-29 22:30:20 +02:00
父節點 03c5646858
當前提交 3e736db0ef
共有 3 個檔案被更改,包括 22 行新增0 行删除

查看文件

@ -13,6 +13,7 @@ class PageDao
virtual bool exists(std::string page) const = 0;
virtual bool exists(unsigned int id) const = 0;
virtual std::optional<Page> find(std::string name) = 0;
virtual std::optional<Page> findByTitle(std::string title) = 0;
virtual std::optional<Page> find(unsigned int id) = 0;
virtual std::vector<std::string> getPageList(QueryOption option) = 0;
virtual std::vector<std::string> fetchCategories(std::string pagename, QueryOption option) = 0;

查看文件

@ -52,6 +52,26 @@ std::optional<Page> PageDaoSqlite::find(std::string name)
}
}
std::optional<Page> PageDaoSqlite::findByTitle(std::string title)
{
Page result;
try
{
auto ps = *db << "SELECT id, name, title, lastrevision, visible FROM page WHERE title = ?";
ps << title >> std::tie(result.pageid, result.name, result.title, result.current_revision, result.listed);
}
catch(const sqlite::errors::no_rows &e)
{
return {};
}
catch(sqlite::sqlite_exception &e)
{
throwFrom(e);
}
return result;
}
std::optional<Page> PageDaoSqlite::find(unsigned int id)
{
Page result;

查看文件

@ -20,6 +20,7 @@ class PageDaoSqlite : public PageDao, protected SqliteDao
bool exists(std::string name) const override;
void save(const Page &page) override;
std::optional<Page> find(std::string name) override;
std::optional<Page> findByTitle(std::string title) override;
std::optional<Page> find(unsigned int id) override;
std::vector<std::string> getPageList(QueryOption option) override;
std::vector<std::string> fetchCategories(std::string pagename, QueryOption option) override;