Revision 24c5480c
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
EntityManager.pro | ||
---|---|---|
src/schema/mysqlschema.h \
|
||
src/databasemigration.h \
|
||
src/querybuilder.h \
|
||
src/schema/sqlitequerybuilder.h
|
||
src/schema/sqlitequerybuilder.h \
|
||
src/relation.h
|
||
|
||
SOURCES += \
|
||
src/entity.cpp \
|
||
... | ... | |
src/schema/mysqlschema.cpp \
|
||
src/databasemigration.cpp \
|
||
src/querybuilder.cpp \
|
||
src/schema/sqlitequerybuilder.cpp
|
||
src/schema/sqlitequerybuilder.cpp \
|
||
src/relation.cpp
|
||
|
||
unix {
|
||
target.path = /usr/lib
|
src/entity.cpp | ||
---|---|---|
return QString(this->metaObject()->className());
|
||
}
|
||
|
||
QList<Relation> Entity::getRelations() {
|
||
return QList<Relation>();
|
||
}
|
||
|
||
QStringList Entity::getTransientAttributes() {
|
||
return QStringList();
|
||
}
|
||
qint64 Entity::getId() const
|
||
|
||
QStringList Entity::getBLOBColumns() {
|
||
return QStringList();
|
||
}
|
||
|
||
QString Entity::getPrimaryKey() {
|
||
return "id";
|
||
}
|
||
qint32 Entity::getId() const
|
||
{
|
||
return id;
|
||
}
|
||
|
||
void Entity::setId(const qint64 &value)
|
||
void Entity::setId(const qint32 &value)
|
||
{
|
||
id = value;
|
||
}
|
||
|
src/entity.h | ||
---|---|---|
#include <QDebug>
|
||
#include <QObject>
|
||
#include "enums/databasetype.h"
|
||
#include "relation.h"
|
||
#include <QStringList>
|
||
namespace CuteEntityManager {
|
||
|
||
class Entity : public QObject {
|
||
Q_OBJECT
|
||
Q_PROPERTY(qint64 firstName READ getId WRITE setId NOTIFY idChanged)
|
||
Q_PROPERTY(qint64 id READ getId WRITE setId NOTIFY idChanged)
|
||
|
||
signals:
|
||
void idChanged();
|
||
... | ... | |
virtual QString toString();
|
||
virtual ~Entity();
|
||
virtual QString getTablename();
|
||
virtual QList<Relation> getRelations();
|
||
/**
|
||
* You should return the names of properties which should not persisted e.g. Properties which are only exposed to qml
|
||
* @brief getTransientAttributes
|
||
* @return
|
||
*/
|
||
virtual QStringList getTransientAttributes();
|
||
// virtual QMap<QString, QString> getManyToManyRelations() = 0; //Key = Table, Value = joined Table Column
|
||
virtual qint64 getId() const;
|
||
virtual void setId(const qint64 &value);
|
||
virtual QStringList getBLOBColumns();
|
||
//return value must be the exact name defined in Q_PROPERTY
|
||
virtual QString getPrimaryKey();
|
||
|
||
protected:
|
||
qint64 id;
|
||
qint32 getId() const;
|
||
void setId(const qint32 &value);
|
||
|
||
protected:
|
||
qint32 id;
|
||
};
|
||
}
|
||
//Q_DECLARE_METATYPE(CuteEntityManager::Entity)
|
||
//Q_DECLARE_METATYPE(CuteEntityManager::Entity*)
|
||
#endif // ENTITY_H
|
src/entitymanager.h | ||
---|---|---|
namespace CuteEntityManager {
|
||
|
||
class EntityManager {
|
||
signals:
|
||
void actionFinished(qint64 id);
|
||
|
||
private:
|
||
static QStringList connectionNames;
|
||
QSharedPointer<Schema> schema;
|
src/relation.cpp | ||
---|---|---|
#include "relation.h"
|
||
using namespace CuteEntityManager;
|
||
|
||
Relation::Relation() {
|
||
}
|
||
|
||
Relation::Relation(QString propertyName, RelationType type, bool optional) {
|
||
this->propertyName = propertyName;
|
||
this->type = type;
|
||
this->optional = optional;
|
||
}
|
||
|
||
Relation::~Relation() {
|
||
}
|
||
|
||
RelationType Relation::getType() const {
|
||
return type;
|
||
}
|
||
|
||
void Relation::setType(const RelationType &value) {
|
||
type = value;
|
||
}
|
||
|
||
QString Relation::getPropertyName() const {
|
||
return propertyName;
|
||
}
|
||
|
||
void Relation::setPropertyName(const QString &value) {
|
||
propertyName = value;
|
||
}
|
||
bool Relation::getOptional() const {
|
||
return optional;
|
||
}
|
||
|
||
void Relation::setOptional(bool value) {
|
||
optional = value;
|
||
}
|
src/relation.h | ||
---|---|---|
#ifndef RELATION_H
|
||
#define RELATION_H
|
||
#include <QString>
|
||
namespace CuteEntityManager {
|
||
enum RelationType {
|
||
ONE_TO_ONE,
|
||
ONE_TO_MANY,
|
||
MANY_TO_MANY,
|
||
MANY_TO_ONE
|
||
};
|
||
|
||
class Relation {
|
||
public:
|
||
Relation();
|
||
Relation(QString propertyName, RelationType type, bool optional = true);
|
||
~Relation();
|
||
RelationType getType() const;
|
||
void setType(const RelationType &value);
|
||
|
||
QString getPropertyName() const;
|
||
void setPropertyName(const QString &value);
|
||
|
||
bool getOptional() const;
|
||
void setOptional(bool value);
|
||
|
||
protected:
|
||
QString propertyName;
|
||
RelationType type;
|
||
bool optional;
|
||
|
||
};
|
||
}
|
||
|
||
#endif // RELATION_H
|
src/schema.cpp | ||
---|---|---|
typeMap.insert("unsigned long long", TYPE_INTEGER);
|
||
typeMap.insert("char",TYPE_CHAR);
|
||
typeMap.insert("std::string", TYPE_TEXT);
|
||
typeMap.insert("std::wstring", TYPE_TEXT);
|
||
typeMap.insert("QString", TYPE_TEXT);
|
||
typeMap.insert("QVariant", TYPE_TEXT);
|
||
typeMap.insert("QUuid", TYPE_TEXT);
|
src/schema.h | ||
---|---|---|
public:
|
||
Schema(QSharedPointer<Database> database);
|
||
virtual ~Schema();
|
||
//http://doc.qt.io/qt-5/sql-types.html
|
||
const QString TYPE_PK = "pk";
|
||
const QString TYPE_BIGPK = "bigpk";
|
||
const QString TYPE_STRING = "string";
|
src/schema/mysqlschema.cpp | ||
---|---|---|
|
||
//QHash<QString, QString> *MysqlSchema::getTypeMap() {
|
||
// if (this->typeMap.data()->empty()) {
|
||
//// this->typeMap->data()->insert(TYPE_SMALLINT, 'tinyint');
|
||
//// this->typeMap->data()->insert(TYPE_SMALLINT, 'bit');
|
||
//// this->typeMap->data()->insert(TYPE_BOOLEAN, 'boolean');
|
||
//// this->typeMap->data()->insert(TYPE_BOOLEAN, 'bool');
|
||
//// this->typeMap->data()->insert(TYPE_SMALLINT, 'smallint');
|
||
//// this->typeMap->data()->insert(TYPE_INTEGER, 'mediumint');
|
||
//// this->typeMap->data()->insert(TYPE_INTEGER, 'int');
|
||
//// this->typeMap->data()->insert(TYPE_INTEGER, 'integer');
|
||
//// this->typeMap->data()->insert(TYPE_BIGINT, 'bigint');
|
||
//// this->typeMap->data()->insert(TYPE_FLOAT, 'float');
|
||
//// this->typeMap->data()->insert(TYPE_DOUBLE, 'double');
|
||
//// this->typeMap->data()->insert(TYPE_FLOAT, 'real');
|
||
//// this->typeMap->data()->insert(TYPE_DECIMAL, 'decimal');
|
||
//// this->typeMap->data()->insert(TYPE_DECIMAL, 'numeric');
|
||
//// this->typeMap->data()->insert(TYPE_TEXT, 'tinytext');
|
||
//// this->typeMap->data()->insert(TYPE_TEXT, 'mediumtext');
|
||
//// this->typeMap->data()->insert(TYPE_TEXT, 'longtext');
|
||
//// this->typeMap->data()->insert(TYPE_TEXT, 'text');
|
||
//// this->typeMap->data()->insert(TYPE_STRING, 'varchar');
|
||
//// this->typeMap->data()->insert(TYPE_STRING, 'string');
|
||
//// this->typeMap->data()->insert(TYPE_STRING, 'char');
|
||
//// this->typeMap->data()->insert(TYPE_BINARY, 'blob');
|
||
//// this->typeMap->data()->insert(TYPE_DATETIME, 'datetime');
|
||
//// this->typeMap->data()->insert(TYPE_DATE, 'year');
|
||
//// this->typeMap->data()->insert(TYPE_DATE, 'date');
|
||
//// this->typeMap->data()->insert(TYPE_TIME, 'time');
|
||
//// this->typeMap->data()->insert(TYPE_TIMESTAMP, 'timestamp');
|
||
//// this->typeMap->data()->insert(TYPE_STRING, 'enum');
|
||
// this->typeMap.data()->insert(TYPE_SMALLINT, "tinyint");
|
||
// this->typeMap.data()->insert(TYPE_BOOLEAN, "boolean");
|
||
// this->typeMap.data()->insert(TYPE_SMALLINT, "smallint");
|
||
// this->typeMap.data()->insert(TYPE_INTEGER, "int");
|
||
// this->typeMap.data()->insert(TYPE_BIGINT, "bigint");
|
||
// this->typeMap.data()->insert(TYPE_FLOAT, "float");
|
||
// this->typeMap.data()->insert(TYPE_DOUBLE, "double");
|
||
// this->typeMap.data()->insert(TYPE_FLOAT, "real");
|
||
// this->typeMap.data()->insert(TYPE_DECIMAL, "decimal");
|
||
// this->typeMap.data()->insert(TYPE_TEXT, "text");
|
||
// this->typeMap.data()->insert(TYPE_STRING, "varchar");
|
||
// this->typeMap.data()->insert(TYPE_CHAR, "char");
|
||
// this->typeMap.data()->insert(TYPE_BINARY, "blob");
|
||
// this->typeMap.data()->insert(TYPE_DATETIME, "datetime");
|
||
// this->typeMap.data()->insert(TYPE_DATE, "date");
|
||
// this->typeMap.data()->insert(TYPE_TIME, "time");
|
||
// this->typeMap.data()->insert(TYPE_TIMESTAMP, "timestamp");
|
||
// }
|
||
// return this->typeMap.data();
|
||
//}
|
Auch abrufbar als: Unified diff
...