#ifndef BOOK_H #define BOOK_H #include #include #include 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