database: pagedao: Add findByTitle()
This commit is contained in:
parent
03c5646858
commit
3e736db0ef
@ -13,6 +13,7 @@ class PageDao
|
|||||||
virtual bool exists(std::string page) const = 0;
|
virtual bool exists(std::string page) const = 0;
|
||||||
virtual bool exists(unsigned int id) const = 0;
|
virtual bool exists(unsigned int id) const = 0;
|
||||||
virtual std::optional<Page> find(std::string name) = 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::optional<Page> find(unsigned int id) = 0;
|
||||||
virtual std::vector<std::string> getPageList(QueryOption option) = 0;
|
virtual std::vector<std::string> getPageList(QueryOption option) = 0;
|
||||||
virtual std::vector<std::string> fetchCategories(std::string pagename, 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)
|
std::optional<Page> PageDaoSqlite::find(unsigned int id)
|
||||||
{
|
{
|
||||||
Page result;
|
Page result;
|
||||||
|
@ -20,6 +20,7 @@ class PageDaoSqlite : public PageDao, protected SqliteDao
|
|||||||
bool exists(std::string name) const override;
|
bool exists(std::string name) const override;
|
||||||
void save(const Page &page) override;
|
void save(const Page &page) override;
|
||||||
std::optional<Page> find(std::string name) 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::optional<Page> find(unsigned int id) override;
|
||||||
std::vector<std::string> getPageList(QueryOption option) override;
|
std::vector<std::string> getPageList(QueryOption option) override;
|
||||||
std::vector<std::string> fetchCategories(std::string pagename, QueryOption option) override;
|
std::vector<std::string> fetchCategories(std::string pagename, QueryOption option) override;
|
||||||
|
Loading…
Reference in New Issue
Block a user