#include "Database/Database.h" #include "BoostLog.h" #include "Database/Session.h" #include #include #include static constexpr auto path = "build/database.sqlite"; using namespace std::chrono; BOOST_AUTO_TEST_CASE(DatabaseTest) { if (std::filesystem::exists(path)) { std::filesystem::remove(path); } Database database; database.open(path); // BOOST_TEST(database.open(path)); auto session = database.session(); Wt::Dbo ::Transaction transaction(*session); auto task = std::make_unique(); task->comment = "my_comment"; task->content = "my_content"; auto p = session->add(std::move(task)); { task = std::make_unique(); task->comment = "my_comment1"; task->content = "my_content1"; auto c = session->add(std::move(task)); p.modify()->children.insert(c); } { task = std::make_unique(); task->comment = "my_comment2"; task->content = "my_content2"; auto c = session->add(std::move(task)); p.modify()->children.insert(c); { task = std::make_unique(); task->comment = "my_comment3"; task->content = "my_content3"; auto d = session->add(std::move(task)); c.modify()->children.insert(d); } { task = std::make_unique(); task->comment = "my_comment4"; task->content = "my_content4"; auto d = session->add(std::move(task)); c.modify()->children.insert(d); } } Wt::Dbo::ptr tt = session->find("where id = 3"); LOG(info) << tt->parent->content; LOG(info) << tt->children.size(); { auto item = std::make_unique(); item->cost = 1499; item->location = "抽屉"; item->name = "手机"; auto d = session->add(std::move(item)); } auto now = std::chrono::system_clock::now(); std::time_t now_time = std::chrono::system_clock::to_time_t(now); database.updateVisitCount("/note", "uuid_123", "chrome", now_time); database.updateVisitCount("/note/1", "uuid_1232", "chrome", now_time); database.updateVisitCount("/note", "uuid_123", "chrome", now_time); database.updateVisitCount("/note", "uuid_1234", "chrome", now_time); }