Older/UnitTest/DatabaseTest.cpp

82 lines
2.4 KiB
C++
Raw Normal View History

2024-11-26 22:58:54 +08:00
#include "Database/Database.h"
2023-12-30 01:19:36 +08:00
#include "BoostLog.h"
2024-11-26 22:58:54 +08:00
#include "Database/Session.h"
#include <Wt/Dbo/SqlConnectionPool.h>
2023-12-30 01:19:36 +08:00
#include <boost/test/unit_test.hpp>
2024-07-10 22:37:40 +08:00
#include <filesystem>
2023-12-30 01:19:36 +08:00
static constexpr auto path = "build/database.sqlite";
using namespace std::chrono;
BOOST_AUTO_TEST_CASE(DatabaseTest) {
2024-07-10 22:37:40 +08:00
if (std::filesystem::exists(path)) {
std::filesystem::remove(path);
}
2023-12-30 01:19:36 +08:00
Database database;
2024-11-26 22:58:54 +08:00
database.open(path);
// BOOST_TEST(database.open(path));
2023-12-30 01:19:36 +08:00
2024-11-26 22:58:54 +08:00
auto session = database.session();
2023-12-30 01:19:36 +08:00
2024-11-26 22:58:54 +08:00
Wt::Dbo ::Transaction transaction(*session);
2024-07-10 22:37:40 +08:00
2024-11-26 22:58:54 +08:00
auto task = std::make_unique<Task>();
task->comment = "my_comment";
task->content = "my_content";
auto p = session->add(std::move(task));
{
task = std::make_unique<Task>();
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>();
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>();
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>();
task->comment = "my_comment4";
task->content = "my_content4";
auto d = session->add(std::move(task));
c.modify()->children.insert(d);
}
}
Wt::Dbo::ptr<Task> tt = session->find<Task>("where id = 3");
LOG(info) << tt->parent->content;
LOG(info) << tt->children.size();
{
auto item = std::make_unique<HomeBox::Item>();
item->cost = 1499;
item->location = "抽屉";
item->name = "手机";
auto d = session->add(std::move(item));
}
2023-12-30 01:19:36 +08:00
2024-07-31 22:28:05 +08:00
auto now = std::chrono::system_clock::now();
std::time_t now_time = std::chrono::system_clock::to_time_t(now);
2024-07-29 00:46:11 +08:00
2024-07-31 22:28:05 +08:00
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);
2024-11-26 22:58:54 +08:00
}