Пересматриваем решение на счёт SQL
This commit was merged in pull request #4.
This commit is contained in:
65
src/model/book.h
Normal file
65
src/model/book.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#ifndef BOOK_H
|
||||
#define BOOK_H
|
||||
|
||||
#include <model/author.h>
|
||||
|
||||
#include <sql_builder/create_table.h>
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace model
|
||||
{
|
||||
|
||||
namespace bookconst
|
||||
{
|
||||
|
||||
const QString TABLE = "books";
|
||||
|
||||
const QString ID = "id";
|
||||
const QString TITLE = "title";
|
||||
const QString AUTHOR_ID = "author_id";
|
||||
const QString FILEPATH = "file_path";
|
||||
|
||||
}
|
||||
|
||||
struct Book
|
||||
{
|
||||
int id = 0;
|
||||
QString title;
|
||||
Author author;
|
||||
QString filePath;
|
||||
};
|
||||
|
||||
static inline QString createTableBook()
|
||||
{
|
||||
// query.exec("CREATE TABLE IF NOT EXISTS books ("
|
||||
// "id INTEGER PRIMARY KEY AUTOINCREMENT,"
|
||||
// "title TEXT NOT NULL,"
|
||||
// "file_path TEXT NOT NULL,"
|
||||
// "author_id INTEGER NOT NULL,"
|
||||
// "FOREIGN KEY (author_id) REFERENCES authors(id) ON DELETE CASCADE"
|
||||
// ");");
|
||||
|
||||
Builder::TableSchema tBuilder(model::bookconst::TABLE);
|
||||
tBuilder.addColumn({ .name = model::bookconst::ID,
|
||||
.type = "INTEGER",
|
||||
.primaryKey = true });
|
||||
|
||||
tBuilder.addColumn({ .name = model::bookconst::TITLE,
|
||||
.type = "TEXT",
|
||||
.notNull = true });
|
||||
|
||||
tBuilder.addColumn({ .name = model::bookconst::FILEPATH,
|
||||
.type = "TEXT",
|
||||
.notNull = true });
|
||||
|
||||
tBuilder.addColumn({ .name = model::bookconst::AUTHOR_ID,
|
||||
.type = "INTEGER",
|
||||
.notNull = true,
|
||||
.foreignKeyTable = model::authorconst::TABLE,
|
||||
.foreignKeyColumn = model::authorconst::ID });
|
||||
return tBuilder.get();
|
||||
}
|
||||
|
||||
} // namespace model
|
||||
#endif // BOOK_H
|
||||
Reference in New Issue
Block a user