Еще немного генерированных тестовых данных

This commit is contained in:
2025-08-03 18:15:17 +05:00
parent 594b3a936f
commit 65059351f7
3 changed files with 16 additions and 4 deletions

View File

@@ -45,7 +45,7 @@ private:
QString m_firstName; QString m_firstName;
QString m_lastName; QString m_lastName;
quint8 m_age; quint64 m_age;
}; };
#pragma db view object(Author_S) #pragma db view object(Author_S)

View File

@@ -64,7 +64,7 @@ int generate_random_year(int min_year = 1900, int max_year = 2020)
return dis(gen); return dis(gen);
} }
QVector<testData> fillDB() QVector<testData> fillAuthorDB()
{ {
QVector<QString> first_names = { QVector<QString> first_names = {
"John", "Jane", "Alex", "Chris", "Robert", "Emily", "James", "Linda", "David", "Sarah", "John", "Jane", "Alex", "Chris", "Robert", "Emily", "James", "Linda", "David", "Sarah",

View File

@@ -101,7 +101,7 @@ void fillBooksBD(uDBase& db)
{ {
odb::core::transaction t(db->begin()); odb::core::transaction t(db->begin());
for (auto& author : authors) for (auto& author : authors)
db->persist(author); // Используем get() для получения сырого указателя db->persist(author);
t.commit(); t.commit();
} }
@@ -129,7 +129,19 @@ int main(int argc, char* argv[])
uDBase db(openDB(dbPath)); uDBase db(openDB(dbPath));
// TODO Как-то нужно выполнять лишь раз // TODO Как-то нужно выполнять лишь раз
// fillBooksBD(db); fillBooksBD(db);
// Сохранение дополнителньых авторов в базу данных
{
auto authors = fillAuthorDB();
odb::core::transaction t(db->begin());
for (auto& author : authors)
{
SH<Author_S> tempAuthor = SH<Author_S>::create(author.first, author.last, author.age);
db->persist(tempAuthor);
}
t.commit();
}
RestApiServer server(*db); RestApiServer server(*db);
server.start(8080); server.start(8080);