From 65059351f778319581c72932d9379be66472a53c Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 3 Aug 2025 18:15:17 +0500 Subject: [PATCH] =?UTF-8?q?=D0=95=D1=89=D0=B5=20=D0=BD=D0=B5=D0=BC=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D1=82=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=D1=8B=D1=85=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/author_s.h | 2 +- src/database/database.hxx | 2 +- src/main.cpp | 16 ++++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/database/author_s.h b/src/database/author_s.h index 5451fba..f821cb6 100644 --- a/src/database/author_s.h +++ b/src/database/author_s.h @@ -45,7 +45,7 @@ private: QString m_firstName; QString m_lastName; - quint8 m_age; + quint64 m_age; }; #pragma db view object(Author_S) diff --git a/src/database/database.hxx b/src/database/database.hxx index a33e812..91ccace 100644 --- a/src/database/database.hxx +++ b/src/database/database.hxx @@ -64,7 +64,7 @@ int generate_random_year(int min_year = 1900, int max_year = 2020) return dis(gen); } -QVector fillDB() +QVector fillAuthorDB() { QVector first_names = { "John", "Jane", "Alex", "Chris", "Robert", "Emily", "James", "Linda", "David", "Sarah", diff --git a/src/main.cpp b/src/main.cpp index 604f2cd..026e6f8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -101,7 +101,7 @@ void fillBooksBD(uDBase& db) { odb::core::transaction t(db->begin()); for (auto& author : authors) - db->persist(author); // Используем get() для получения сырого указателя + db->persist(author); t.commit(); } @@ -129,7 +129,19 @@ int main(int argc, char* argv[]) uDBase db(openDB(dbPath)); // TODO Как-то нужно выполнять лишь раз - // fillBooksBD(db); + fillBooksBD(db); + + // Сохранение дополнителньых авторов в базу данных + { + auto authors = fillAuthorDB(); + odb::core::transaction t(db->begin()); + for (auto& author : authors) + { + SH tempAuthor = SH::create(author.first, author.last, author.age); + db->persist(tempAuthor); + } + t.commit(); + } RestApiServer server(*db); server.start(8080);