/************************************************************************** ** ** This file is part of Nut project. ** https://github.com/HamedMasafi/Nut ** ** Nut is free software: you can redistribute it and/or modify ** it under the terms of the GNU Lesser General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** ** Nut is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU Lesser General Public License for more details. ** ** You should have received a copy of the GNU Lesser General Public License ** along with Nut. If not, see . ** **************************************************************************/ #ifndef TABLESCHEEMA_H #define TABLESCHEEMA_H #include #include #include "defines.h" class QJsonObject; NUT_BEGIN_NAMESPACE class TableModel; struct FieldModel{ FieldModel() : name(QString::null), length(0), defaultValue(QString::null), notNull(false), isPrimaryKey(false), isAutoIncrement(false), isUnique(false) { } QString name; //TODO: QMetaType::Type?? QVariant::Type type; QString typeName; int length; QString defaultValue; bool notNull; bool isPrimaryKey; bool isAutoIncrement; bool isUnique; bool operator ==(const FieldModel &f) const{ bool b = name.toLower() == f.name.toLower() && type == f.type && length == f.length && defaultValue == f.defaultValue && notNull == f.notNull; return b; } bool operator !=(const FieldModel &f) const{ return !(*this == f); } }; struct RelationModel{ //slave QString localColumn; TableModel *slaveTable; //master QString foregionColumn; TableModel *masterTable; QString masterClassName; }; class TableModel { public: TableModel(int typeId, QString tableName = QString::null); TableModel(QJsonObject json, QString tableName); QJsonObject toJson() const; // static TableScheema *registerTable(int typeId, QString tableName); // static void createForegionKeys(); // static TableModel* model(QString className); FieldModel *field(QString name) const; RelationModel *foregionKey(QString otherTable) const; QString toString() const; QString primaryKey() const; QString name() const; void setName(const QString &name); QString className() const; void setClassName(const QString &className); int typeId() const; void setTypeId(const int &typeId); QList fields() const; QList foregionKeys() const; QStringList fieldsNames() const; static QSet allModels(); static TableModel *findByTypeId(int typeId); // static TableModel *findByName(QString name); static TableModel *findByClassName(QString className); bool operator ==(const TableModel &t) const; bool operator !=(const TableModel &t) const; private: QString _name; QString _className; int _typeId; QList _fields; QList _foregionKeys; static QSet_allModels; bool checkClassInfo(const QMetaClassInfo &classInfo, QString &type, QString &name, QString &value); }; NUT_END_NAMESPACE #endif // TABLESCHEEMA_H