Насоздавали новых таблиц

This commit is contained in:
2025-08-10 12:08:49 +05:00
parent 78b01bc0b1
commit b4fa718be6
7 changed files with 124 additions and 78 deletions

View File

@@ -23,25 +23,25 @@ void fillBooksBD(uDBase& db)
try try
{ {
QVector<Author_S> authors = { QVector<Author_S> authors = {
Author_S("George Orwell", "en"), Author_S("George Orwell"),
Author_S("J.K. Rowling", "en"), Author_S("J.K. Rowling"),
Author_S("J.R.R. Tolkien", "en"), Author_S("J.R.R. Tolkien"),
Author_S("Leo Tolstoy", "ru"), Author_S("Leo Tolstoy"),
Author_S("Fyodor Dostoevsky", "ru"), Author_S("Fyodor Dostoevsky"),
Author_S("Mark Twain", "en"), Author_S("Mark Twain"),
Author_S("Charles Dickens", "en"), Author_S("Charles Dickens"),
Author_S("Virginia Woolf", "en"), Author_S("Virginia Woolf"),
Author_S("Ernest Hemingway", "en"), Author_S("Ernest Hemingway"),
Author_S("Gabriel García Márquez", "en"), Author_S("Gabriel García Márquez"),
Author_S("Franz Kafka", "de"), Author_S("Franz Kafka"),
Author_S("Harper Lee", "en"), Author_S("Harper Lee"),
Author_S("William Shakespeare", "en"), Author_S("William Shakespeare"),
Author_S("Oscar Wilde", "en"), Author_S("Oscar Wilde"),
Author_S("Aldous Huxley", "en"), Author_S("Aldous Huxley"),
Author_S("Jane Austen", "en"), Author_S("Jane Austen"),
Author_S("John Steinbeck", "en"), Author_S("John Steinbeck"),
Author_S("Agatha Christie", "en"), Author_S("Agatha Christie"),
Author_S("Isaac Asimov", "ru"), Author_S("Isaac Asimov"),
}; };
addBook(*db, "Очень странная книжка", { "Автор 1", "Автор 2", "Авторк 3" }); addBook(*db, "Очень странная книжка", { "Автор 1", "Автор 2", "Авторк 3" });

View File

@@ -3,19 +3,13 @@
#include <model/model_global.h> #include <model/model_global.h>
// @JsonSerializer
class Author_S;
#pragma db object #pragma db object
class MODEL_EXPORT Author_S class MODEL_EXPORT Author_S
{ {
public: public:
Author_S() = default; Author_S() = default;
Author_S(const QString& fullName, Author_S(const QString& fullName) :
const QString& langCode) : m_fullName(fullName) {}
m_fullName(fullName),
m_langCode(langCode)
{}
quint64 id() const { return m_id; } quint64 id() const { return m_id; }
void setId(quint64 newId) { m_id = newId; } void setId(quint64 newId) { m_id = newId; }
@@ -29,7 +23,7 @@ public:
private: private:
friend class odb::access; friend class odb::access;
public: // for Redkit-gen private:
#pragma db id auto #pragma db id auto
quint64 m_id; quint64 m_id;

View File

@@ -5,34 +5,11 @@
#include <QDateTime> #include <QDateTime>
#include "author_s.h"
#include "genre_s.h"
#include "series_s.h"
struct Book_SZ
{
QString title;
SH<Series_S> series;
quint8 year;
SH<Genre_S> genre;
QDateTime lastModified = QDateTime::currentDateTime();
QString lang;
};
#pragma db object #pragma db object
class MODEL_EXPORT Book_S class MODEL_EXPORT Book_S
{ {
public: public:
Book_S() = default; Book_S() = default;
Book_S(const Book_SZ& book)
{
m_title = book.title;
m_series = book.series;
m_year = book.year;
m_genre = book.genre;
m_lastModified = book.lastModified;
m_lang = book.lang;
}
quint64 id() const { return m_id; } quint64 id() const { return m_id; }
void setId(const quint64& newId) { m_id = newId; } void setId(const quint64& newId) { m_id = newId; }
@@ -40,15 +17,9 @@ public:
QString title() const { return m_title; } QString title() const { return m_title; }
void setTitle(const QString& newTitle) { m_title = newTitle; } void setTitle(const QString& newTitle) { m_title = newTitle; }
SH<Series_S> series() const { return m_series; }
void setSeries(const SH<Series_S>& newSeries) { m_series = newSeries; }
quint8 year() const { return m_year; } quint8 year() const { return m_year; }
void setYear(const quint8& newYear) { m_year = newYear; } void setYear(const quint8& newYear) { m_year = newYear; }
SH<Genre_S> genre() const { return m_genre; }
void setGenre(const SH<Genre_S>& newGenre) { m_genre = newGenre; }
QDateTime lastModified() const { return m_lastModified; } QDateTime lastModified() const { return m_lastModified; }
void setLastModified(const QDateTime& newLastModified) { m_lastModified = newLastModified; } void setLastModified(const QDateTime& newLastModified) { m_lastModified = newLastModified; }
@@ -58,33 +29,14 @@ public:
private: private:
friend class odb::access; friend class odb::access;
// public: // for Redkit-gen
private: private:
#pragma db id auto #pragma db id auto
quint64 m_id; quint64 m_id;
QString m_title; QString m_title;
SH<Series_S> m_series;
quint8 m_year; quint8 m_year;
SH<Genre_S> m_genre;
QDateTime m_lastModified; QDateTime m_lastModified;
QString m_lang; QString m_lang;
}; };
// #pragma db view object(Book_S) object(Author_S = author:Book_S::m_author)
// struct BookByAuthorView
// {
// #pragma db column(Book_S::m_id)
// quint64 book_id;
// #pragma db column(Book_S::m_name)
// QString book_name;
// #pragma db column(Book_S::m_year)
// qint8 year;
// #pragma db column(Author_S::m_first + " " + Author_S::m_last)
// QString author_full_name;
// };
#endif // BOOK_S_H #endif // BOOK_S_H

View File

@@ -0,0 +1,45 @@
#ifndef GENRE_BOOK_S_H
#define GENRE_BOOK_S_H
#include <model/model_global.h>
#include "book_s.h"
#include "genre_s.h"
#pragma db object
class GenreBook_S
{
private:
GenreBook_S() = default;
public:
GenreBook_S(const SH<Genre_S>& genreId, const SH<Book_S>& bookId) :
m_genreId(genreId),
m_bookId(bookId) {}
quint64 id() const { return m_id; }
void setId(quint64 newId) { m_id = newId; }
SH<Genre_S> genreId() const { return m_genreId; }
void setGenreId(const SH<Genre_S>& newGenreId) { m_genreId = newGenreId; }
SH<Book_S> bookId() const { return m_bookId; }
void setBookId(const SH<Book_S>& newBookId) { m_bookId = newBookId; }
private:
friend class odb::access;
private:
#pragma db id auto
quint64 m_id;
#pragma db not_null
SH<Genre_S> m_genreId;
#pragma db not_null
SH<Book_S> m_bookId;
#pragma db index("genre_book_unique") member(m_genreId) member(m_bookId) unique
};
#endif // GENRE_BOOK_S_H

View File

@@ -0,0 +1,10 @@
#ifndef MANUTOMANYBASE_H
#define MANUTOMANYBASE_H
class ManuToManyBase
{
public:
ManuToManyBase();
};
#endif // MANUTOMANYBASE_H

View File

@@ -0,0 +1,45 @@
#ifndef SERIES_BOOK_S_H
#define SERIES_BOOK_S_H
#include <model/model_global.h>
#include "book_s.h"
#include "series_s.h"
#pragma db object
class MODEL_EXPORT SeriesBook_S
{
private:
SeriesBook_S() = default;
public:
SeriesBook_S(const SH<Series_S>& serieId, const SH<Book_S>& bookId) :
m_serieId(serieId),
m_bookId(bookId) {}
quint64 id() const { return m_id; }
void setId(quint64 newId) { m_id = newId; }
SH<Series_S> serieId() const { return m_serieId; }
void setSerieId(const SH<Series_S>& newSerieId) { m_serieId = newSerieId; }
SH<Book_S> bookId() const { return m_bookId; }
void setBookId(const SH<Book_S>& newBookId) { m_bookId = newBookId; }
private:
friend class odb::access;
private:
#pragma db id auto
quint64 m_id;
#pragma db not_null
SH<Series_S> m_serieId;
#pragma db not_null
SH<Book_S> m_bookId;
#pragma db index("series_book_unique") member(m_serieId) member(m_bookId) unique
};
#endif // SERIES_BOOK_S_H

View File

@@ -12,8 +12,8 @@ public:
quint64 id() const { return m_id; } quint64 id() const { return m_id; }
void setId(const quint64& newId) { m_id = newId; } void setId(const quint64& newId) { m_id = newId; }
QString serName() const { return m_serName; } QString name() const { return m_serName; }
void setSerName(const QString& newSerName) { m_serName = newSerName; } void setName(const QString& newSerName) { m_serName = newSerName; }
private: private:
friend class odb::access; friend class odb::access;