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);