Revision 82442988
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
EntityManager.pro | ||
---|---|---|
src/expression.cpp \
|
||
src/orderby.cpp
|
||
|
||
CONFIG += c++14
|
||
QMAKE_CXXFLAGS += -std=c++14
|
||
|
||
unix {
|
||
target.path = /usr/lib
|
||
INSTALLS += target
|
||
QMAKE_CXXFLAGS += -Wall -Wextra -Wmaybe-uninitialized -Wsuggest-final-types -Wsuggest-final-methods -Wsuggest-override -Wunsafe-loop-optimizations -pedantic -Wfloat-equal -Wundef -Wpointer-arith -Wcast-align -Wunreachable-code -O
|
||
}
|
||
CONFIG += c++14
|
||
QMAKE_CXXFLAGS += -std=c++14
|
||
|
||
win32-g++ {
|
||
CONFIG += c++11
|
||
QMAKE_CXXFLAGS += -std=c++11 -Wall
|
||
}
|
||
|
||
#QMAKE_CXXFLAGS += -Winit-self
|
||
CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT
|
samples/example/Example.pro | ||
---|---|---|
unix {
|
||
QMAKE_CXXFLAGS += -Wall -Wextra -Wmaybe-uninitialized -Wsuggest-final-types -Wsuggest-final-methods -Wsuggest-override -Wunsafe-loop-optimizations -pedantic -Wfloat-equal -Wundef -Wpointer-arith -Wcast-align -Wunreachable-code -O -Winit-self
|
||
}
|
||
|
||
win32-g++ {
|
||
CONFIG += c++11
|
||
QMAKE_CXXFLAGS += -std=c++11 -Wall
|
||
}
|
||
|
||
CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT
|
samples/example/main.cpp | ||
---|---|---|
*/
|
||
Query q = Query();
|
||
q.appendWhere(e->getQueryBuilder()->like(QString("firstname"), QString("Tim")));
|
||
q.appendJoin(Join("person","pupil.id = person.id"));
|
||
q.setDistinct(true);
|
||
q.appendOrderBy(OrderBy(QString("birthday"), Direction::SORT_DESC));
|
||
q.setLimit(10);
|
||
QList<QSharedPointer<Person>> list = e->find<Person>(q);
|
||
QList<QSharedPointer<Pupil>> list = e->find<Pupil>(q);
|
||
for (int i = 0; i < list.size(); ++i) {
|
||
qDebug() << list.at(i)->toString();
|
||
}
|
samples/example/models/faker/createfakemodeldata.cpp | ||
---|---|---|
#include "../group.h"
|
||
|
||
void CreateFakeModelData::fillGroup(Group* group) {
|
||
group->addPerson(new Person("Tim","Berg",Person::Gender::MALE,"Tim Berg.jpg",QString(),QString(),QDate(2000,7,13),0));
|
||
group->addPerson(new Person("Lena","Conrad",Person::Gender::FEMALE,"Lena Conrad.jpg",QString(),QString(),QDate(2000,7,13),0));
|
||
group->addPerson(new Person("Marcel","Dunst",Person::Gender::MALE,"Marcel Dunst.jpg",QString(),QString(),QDate(2000,7,13),0));
|
||
group->addPerson(new Person("Thomas","Berg",Person::Gender::MALE,"",QString(),QString(),QDate(1971,7,13),0));
|
||
group->addPerson(new Person("Teresa","Conrad",Person::Gender::FEMALE,"",QString(),QString(),QDate(1970,7,13),0));
|
||
group->addPerson(new Person("Heinz","Dunst",Person::Gender::MALE,"",QString(),QString(),QDate(1972,7,13),0));
|
||
|
||
group->addPupil(new Pupil("Tim","Berg",Person::Gender::MALE,"Tim Berg.jpg",QString(),QString(),QDate(2000,7,13),"05c",0));
|
||
group->addPupil(new Pupil("Lena","Conrad",Person::Gender::FEMALE,"Lena Conrad.jpg",QString(),QString(),QDate(2000,7,13),"05c",0));
|
||
... | ... | |
group->addPupil(new Pupil("Birthe","Jäger",Person::Gender::FEMALE,"Birthe Jaeger.jpg",QString(),QString(),QDate(2000,2,14),"05c",0));
|
||
|
||
group->pupilAt(0)->addAddress(new Address("Erzieher","Bukesweg 473","33330","Gütersloh"));
|
||
group->pupilAt(1)->addAddress(new Address("Erzieher","Bukesweg 473","33330","Gütersloh"));
|
||
group->pupilAt(2)->addAddress(new Address("Erzieher","Bukesweg 473","33330","Gütersloh"));
|
||
group->pupilAt(3)->addAddress(new Address("Erzieher","Bukesweg 473","33330","Gütersloh"));
|
||
group->pupilAt(4)->addAddress(new Address("Erzieher","Bukesweg 473","33330","Gütersloh"));
|
||
group->pupilAt(1)->addAddress(new Address("Erzieher","Bukesweg 474","33330","Gütersloh"));
|
||
group->pupilAt(2)->addAddress(new Address("Erzieher","Bukesweg 47","33330","Gütersloh"));
|
||
group->pupilAt(3)->addAddress(new Address("Erzieher","Bukesweg 4","33330","Gütersloh"));
|
||
group->pupilAt(4)->addAddress(new Address("Erzieher","Bukesweg 43","33330","Gütersloh"));
|
||
group->pupilAt(5)->addAddress(new Address("Erzieher","Auguste-Viktoria-Platz 193","77652","Offenburg"));
|
||
group->pupilAt(6)->addAddress(new Address("Erzieher","Bullenwinkel 467","74074","Heilbronn"));
|
||
group->pupilAt(7)->addAddress(new Address("Erzieher","Schinkelplatz 389","46236","Bottrop"));
|
src/entity.cpp | ||
---|---|---|
|
||
#include "entity.h"
|
||
#include "entityhelper.h"
|
||
#include "entityinstancefactory.h"
|
||
using namespace CuteEntityManager;
|
||
|
||
Entity::Entity(QObject *parent) : QObject(parent) {
|
||
... | ... | |
if (var.value().isEnumType()) {
|
||
val = var.value().enumerator().valueToKey(var.value().read(this).toInt());
|
||
} else if (value.canConvert<QList<QVariant>>()) {
|
||
auto list = value.toList();
|
||
val.append("[");
|
||
for (int i = 0; i < list.size(); ++i) {
|
||
val = list.at(i).toString();
|
||
}
|
||
auto list = EntityInstanceFactory::castQVariantList(value);
|
||
int size = list.size();
|
||
val.append(QString::number(size));
|
||
val.append(" ");
|
||
val.append(size == 1 ? "element" : "elements");
|
||
val.append("]");
|
||
} else {
|
||
val = value.toString();
|
src/entitymanager.cpp | ||
---|---|---|
#include "entitymanager.h"
|
||
#include "enums/databasetype.h"
|
||
#include "databasemigration.h"
|
||
#include "queryinterpreter.h"
|
||
using namespace CuteEntityManager;
|
||
|
||
QStringList EntityManager::connectionNames = QStringList();
|
src/entitymanager.h | ||
---|---|---|
#include <QObject>
|
||
#include <QSharedPointer>
|
||
#include <QDebug>
|
||
#include "schema.h"
|
||
#include <QtSql/QSqlError>
|
||
#include <QMetaType>
|
||
#include "schema.h"
|
||
#include "entity.h"
|
||
#include "database.h"
|
||
#include "entityinstancefactory.h"
|
||
#include "cache.h"
|
||
#include "queryinterpreter.h"
|
||
|
||
#include "cache.h"
|
||
#include "querybuilder.h"
|
||
namespace CuteEntityManager {
|
||
|
||
class Logger;
|
src/expression.h | ||
---|---|---|
QHash<QString, QVariant> params;
|
||
bool onlyColumn;
|
||
};
|
||
|
||
inline bool operator==(const Expression &e1, const Expression &e2) {
|
||
return e1.getExpression() == e2.getExpression();
|
||
}
|
||
}
|
||
#endif // EXPRESSION_H
|
src/join.h | ||
---|---|---|
Expression getExpression() const;
|
||
void setExpression(const Expression &value);
|
||
|
||
|
||
private:
|
||
QString type = QStringLiteral("LEFT JOIN");
|
||
QString foreignTable;
|
||
Expression expression;
|
||
|
||
};
|
||
inline bool operator==(const Join &e1, const Join &e2) {
|
||
return e1.getForeignTable() == e2.getForeignTable()
|
||
&& e1.getExpression() == e2.getExpression();
|
||
}
|
||
|
||
}
|
||
#endif // JOIN_H
|
src/query.cpp | ||
---|---|---|
Query::Query() {
|
||
}
|
||
|
||
Query::~Query() {
|
||
}
|
||
|
||
Query::Query(QStringList from, QList<Expression> where, QList<Join> joins,
|
||
QHash<QString, QVariant> params, quint64 limit, quint64 offset,
|
||
QList<Expression> select, QStringList groupBy, bool distinct,
|
||
... | ... | |
distinct = value;
|
||
}
|
||
|
||
void Query::appendFrom(const QString &value) {
|
||
if (!this->from.contains(value)) {
|
||
this->from.append(value);
|
||
}
|
||
}
|
||
|
||
QStringList Query::getFrom() const {
|
||
return from;
|
||
}
|
||
... | ... | |
from = value;
|
||
}
|
||
|
||
void Query::appendJoin(const Join &value) {
|
||
if (!this->joins.contains(value)) {
|
||
this->joins.append(value);
|
||
}
|
||
}
|
||
|
||
QStringList Query::getGroupBy() const {
|
||
return groupBy;
|
||
}
|
||
... | ... | |
void Query::setOrderBy(const QList<OrderBy> &value) {
|
||
orderBy = value;
|
||
}
|
||
|
||
void Query::appendGroupBy(const QString &value) {
|
||
if (!this->groupBy.contains(value)) {
|
||
this->groupBy.append(value);
|
||
}
|
||
}
|
src/query.h | ||
---|---|---|
class Query {
|
||
public:
|
||
Query();
|
||
~Query();
|
||
Query(QStringList from, QList<Expression> where,
|
||
QList<Join> joins = QList<Join>(),
|
||
QHash<QString, QVariant> params = QHash<QString, QVariant>(), quint64 limit = 0,
|
||
... | ... | |
bool getDistinct() const;
|
||
void setDistinct(bool value);
|
||
|
||
void appendFrom(const QString &value);
|
||
QStringList getFrom() const;
|
||
void setFrom(const QStringList &value);
|
||
|
||
void appendJoin(const Join &value);
|
||
QList<Join> getJoins() const;
|
||
void setJoins(const QList<Join> &value);
|
||
|
||
... | ... | |
quint64 getOffset() const;
|
||
void setOffset(const quint64 &value);
|
||
|
||
void appendWhere(const QString &condition);
|
||
void appendWhere(const Expression &condition);
|
||
|
||
void appendHaving(const QString &condition);
|
||
void appendHaving(const Expression &condition);
|
||
|
||
void appendOrderBy(const OrderBy &orderBy);
|
||
void appendOrderBy(const QString &column, const Direction &direction);
|
||
QList<OrderBy> getOrderBy() const;
|
||
void setOrderBy(const QList<OrderBy> &value);
|
||
|
||
void appendGroupBy(const QString &value);
|
||
QStringList getGroupBy() const;
|
||
void setGroupBy(const QStringList &value);
|
||
|
||
... | ... | |
void setSelect(const QList<Expression> &value);
|
||
void setSelect(const QStringList &value);
|
||
|
||
void appendWhere(const QString &condition);
|
||
void appendWhere(const Expression &condition);
|
||
QList<Expression> getWhere() const;
|
||
void setWhere(const QList<Expression> &value);
|
||
|
||
void appendHaving(const QString &condition);
|
||
void appendHaving(const Expression &condition);
|
||
QList<Expression> getHaving() const;
|
||
void setHaving(const QList<Expression> &value);
|
||
|
src/querybuilder.h | ||
---|---|---|
#include <QStringList>
|
||
#include <QMetaProperty>
|
||
#include "relation.h"
|
||
#include "query.h"
|
||
#include "expression.h"
|
||
#include "query.h"
|
||
namespace CuteEntityManager {
|
||
class Schema;
|
||
class Entity;
|
||
... | ... | |
QString transformTypeToAbstractDbType(QString typeName) const;
|
||
QString transformAbstractTypeToRealDbType(QString typeName) const;
|
||
QString getColumnType(const QString &type) const;
|
||
virtual QString placeHolder(const QString &key) const;
|
||
void bindValues(const QHash<QString, QVariant> &h, QSqlQuery &q,
|
||
bool ignoreID = false, const QString &primaryKey = "id") const;
|
||
void bindValue(const QString &key, const QVariant &value, QSqlQuery &q) const;
|
||
virtual QString placeHolder(const QString &key) const;
|
||
Expression where(QString column, QVariant value);
|
||
/**
|
||
* @brief where
|
||
... | ... | |
QString conjunction = "AND",
|
||
JokerPosition jp = JokerPosition::BOTH, QChar wildcard = '%');
|
||
|
||
QStringList quoteTableNames(const QStringList &tables);
|
||
QString getSeparator() const;
|
||
void setSeparator(const QString &value);
|
||
|
||
protected:
|
||
class ClassAttributes {
|
||
public:
|
||
... | ... | |
QString pk;
|
||
QHash<QString, QVariant> attributes;
|
||
};
|
||
|
||
QStringList quoteTableNames(const QStringList &tables);
|
||
QString getSeparator() const;
|
||
void setSeparator(const QString &value);
|
||
QSqlQuery find(const qint64 &id, const QString &tableName) const;
|
||
QSqlQuery find(const qint64 &id, const QSharedPointer<Entity> &entity,
|
||
qint64 offset = 0, QString pk = "id") const;
|
src/schema.h | ||
---|---|---|
*/
|
||
#ifndef SCHEMA_H
|
||
#define SCHEMA_H
|
||
#include "tableschema.h"
|
||
#include <QStringList>
|
||
#include <QHash>
|
||
#include <QSharedPointer>
|
||
#include <QSqlField>
|
||
#include "tableschema.h"
|
||
#include "querybuilder.h"
|
||
namespace CuteEntityManager {
|
||
class Database;
|
Auch abrufbar als: Unified diff
...