database: pagedao: Add-support for subpages
This commit is contained in:
parent
f08e235d03
commit
2d5d483790
@ -23,6 +23,8 @@ class PageDao
|
||||
virtual void setCategories(std::string pagename, const std::vector<std::string> &catnames) = 0;
|
||||
virtual std::vector<SearchResult> search(std::string query, QueryOption option) = 0;
|
||||
|
||||
virtual std::vector<std::string> getChildren(std::string pagename) = 0;
|
||||
|
||||
virtual ~PageDao()
|
||||
{
|
||||
}
|
||||
|
@ -57,8 +57,10 @@ 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);
|
||||
auto ps = *db << "SELECT id, name, title, lastrevision, visible, (SELECT name FROM page WHERE id = parent) "
|
||||
"FROM page WHERE title = ?";
|
||||
ps << title >> std::tie(result.pageid, result.name, result.title, result.current_revision, result.listed,
|
||||
result.parentpage);
|
||||
}
|
||||
catch(const sqlite::errors::no_rows &e)
|
||||
{
|
||||
@ -78,9 +80,10 @@ std::optional<Page> PageDaoSqlite::find(unsigned int id)
|
||||
result.pageid = id;
|
||||
try
|
||||
{
|
||||
auto ps = *db << "SELECT name, title, lastrevision, visible FROM page WHERE id = ?";
|
||||
auto ps = *db << "SELECT name, title, lastrevision, visible, (SELECT name FROM page WHERE id = parent) FROM "
|
||||
"page WHERE id = ?";
|
||||
|
||||
ps << id >> std::tie(result.name, result.title, result.current_revision, result.listed);
|
||||
ps << id >> std::tie(result.name, result.title, result.current_revision, result.listed, result.parentpage);
|
||||
}
|
||||
catch(const sqlite::errors::no_rows &e)
|
||||
{
|
||||
@ -118,10 +121,12 @@ void PageDaoSqlite::save(const Page &page)
|
||||
{
|
||||
try
|
||||
{
|
||||
*db << "INSERT OR REPLACE INTO page (id, name, title, lastrevision, visible) VALUES((SELECT id FROM page WHERE "
|
||||
*db << "INSERT OR REPLACE INTO page (id, name, title, lastrevision, visible, parent) VALUES((SELECT id FROM "
|
||||
"page WHERE "
|
||||
"name = "
|
||||
"? OR id = ?), ?, ?, ?, ?)"
|
||||
<< page.name << page.pageid << page.name << page.title << page.current_revision << page.listed;
|
||||
"? OR id = ?), ?, ?, ?, ?, (SELECT id FROM page WHERE name = ?))"
|
||||
<< page.name << page.pageid << page.name << page.title << page.current_revision << page.listed
|
||||
<< page.parentpage;
|
||||
}
|
||||
catch(sqlite::sqlite_exception &e)
|
||||
{
|
||||
@ -140,9 +145,11 @@ std::vector<Page> PageDaoSqlite::getPageList(QueryOption option)
|
||||
.setVisibleColumnName("visible")
|
||||
.setPrependWhere(true)
|
||||
.build();
|
||||
std::string query = "SELECT id, name, title, lastrevision, visible FROM page " + queryOption;
|
||||
*db << query >>
|
||||
[&](unsigned int pageid, std::string name, std::string title, unsigned int current_revision, bool visible)
|
||||
std::string query =
|
||||
"SELECT id, name, title, lastrevision, visible, (SELECT name FROM page WHERE id = parent) FROM page " +
|
||||
queryOption;
|
||||
*db << query >> [&](unsigned int pageid, std::string name, std::string title, unsigned int current_revision,
|
||||
bool visible, std::string parent)
|
||||
{
|
||||
Page tmp;
|
||||
tmp.pageid = pageid;
|
||||
@ -150,6 +157,7 @@ std::vector<Page> PageDaoSqlite::getPageList(QueryOption option)
|
||||
tmp.title = title;
|
||||
tmp.current_revision = current_revision;
|
||||
tmp.listed = visible;
|
||||
tmp.parentpage = parent;
|
||||
result.push_back(tmp);
|
||||
};
|
||||
}
|
||||
@ -262,3 +270,11 @@ int PageDaoSqlite::fetchPageId(std::string pagename)
|
||||
auto binder = *db << "SELECT id FROM page WHERE name = ?" << pagename;
|
||||
return execInt(binder);
|
||||
}
|
||||
|
||||
std::vector<std::string> PageDaoSqlite::getChildren(std::string pagename)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
auto query = *db << "SELECT name FROM page WHERE parent = (SELECT id FROM page WHERE name = ?)" << pagename;
|
||||
query >> [&](std::string page) { result.push_back(page); };
|
||||
return result;
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ class PageDaoSqlite : public PageDao, protected SqliteDao
|
||||
int fetchPageId(std::string pagename);
|
||||
std::vector<SearchResult> search(std::string query, QueryOption option) override;
|
||||
void setCategories(std::string pagename, const std::vector<std::string> &catnames) override;
|
||||
std::vector<std::string> getChildren(std::string pagename) override;
|
||||
|
||||
};
|
||||
|
||||
#endif // PAGEDAOSQLITE_H
|
||||
|
Loading…
Reference in New Issue
Block a user