database: pagedao: Add-support for subpages

Bu işleme şunda yer alıyor:
Albert S. 2023-11-23 18:24:40 +01:00
ebeveyn f08e235d03
işleme 2d5d483790
4 değiştirilmiş dosya ile 31 ekleme ve 10 silme

Dosyayı Görüntüle

@ -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()
{
}

Dosyayı Görüntüle

@ -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;
}

Dosyayı Görüntüle

@ -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

1
page.h
Dosyayı Görüntüle

@ -8,6 +8,7 @@ class Page
Page();
std::string name;
std::string title;
std::string parentpage;
bool listed;
unsigned int current_revision;
unsigned int pageid;