Revision 2ee5022f
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
EntityManager.pro | ||
---|---|---|
src/entityhelper.h \
|
||
src/logger.h \
|
||
src/query.h \
|
||
src/join.h
|
||
src/join.h \
|
||
src/queryinterpreter.h \
|
||
src/condition.h
|
||
|
||
SOURCES += \
|
||
src/entity.cpp \
|
||
... | ... | |
src/entityhelper.cpp \
|
||
src/logger.cpp \
|
||
src/query.cpp \
|
||
src/join.cpp
|
||
src/join.cpp \
|
||
src/queryinterpreter.cpp \
|
||
src/condition.cpp
|
||
|
||
unix {
|
||
target.path = /usr/lib
|
src/condition.cpp | ||
---|---|---|
#include "condition.h"
|
||
using namespace CuteEntityManager;
|
||
Condition::Condition() {
|
||
|
||
}
|
||
|
||
Condition::Condition(QString condition) {
|
||
if (!condition.isEmpty()) {
|
||
this->conditions.append(condition);
|
||
}
|
||
}
|
||
|
||
void Condition::appendCondition(const QString &value) {
|
||
this->conditions.append(value);
|
||
}
|
||
|
||
QStringList Condition::getConditions() const {
|
||
return conditions;
|
||
}
|
||
|
||
void Condition::setConditions(const QStringList &value) {
|
||
conditions = value;
|
||
}
|
||
|
||
QList<Condition> Condition::getSubConditions() const {
|
||
return subConditions;
|
||
}
|
||
|
||
void Condition::setSubConditions(const QList<Condition> &value) {
|
||
subConditions = value;
|
||
}
|
||
|
||
void CuteEntityManager::Condition::addSubCondition(const
|
||
CuteEntityManager::Condition &value) {
|
||
this->subConditions.append(value);
|
||
}
|
src/condition.h | ||
---|---|---|
#ifndef CONDITION_H
|
||
#define CONDITION_H
|
||
|
||
#include <QStringList>
|
||
namespace CuteEntityManager {
|
||
class Condition {
|
||
public:
|
||
Condition();
|
||
Condition(QString condition);
|
||
void appendCondition(const QString &value);
|
||
QStringList getConditions() const;
|
||
void setConditions(const QStringList &value);
|
||
|
||
void addSubCondition(const Condition &value);
|
||
QList<Condition> getSubConditions() const;
|
||
void setSubConditions(const QList<Condition> &value);
|
||
|
||
private:
|
||
QStringList conditions;
|
||
QList<Condition> subConditions;
|
||
};
|
||
}
|
||
|
||
#endif // CONDITION_H
|
src/entitymanager.cpp | ||
---|---|---|
#include "entitymanager.h"
|
||
#include "enums/databasetype.h"
|
||
#include "databasemigration.h"
|
||
#include "queryinterpreter.h"
|
||
using namespace CuteEntityManager;
|
||
|
||
QStringList EntityManager::connectionNames = QStringList();
|
||
... | ... | |
this->db->getDatabase().driverName()), this->db);
|
||
this->schema = QSharedPointer<Schema>(schema);
|
||
this->schema->setTables(this->schema->getTableSchemas());
|
||
this->queryInterpreter = QSharedPointer<QueryInterpreter>(new QueryInterpreter(
|
||
this->schema->getQueryBuilder()));
|
||
}
|
||
|
||
EntityManager::~EntityManager() {
|
src/entitymanager.h | ||
---|---|---|
|
||
|
||
class Logger;
|
||
class QueryInterpreter;
|
||
class EntityManager : public QObject {
|
||
Q_OBJECT
|
||
signals:
|
||
... | ... | |
QString createConnection();
|
||
QList<QHash<QString, QVariant> > convertQueryResult(QSqlQuery &q);
|
||
bool checkTable(const QSharedPointer<Entity> &entity);
|
||
QSharedPointer<QueryInterpreter> queryInterpreter;
|
||
|
||
};
|
||
}
|
src/query.cpp | ||
---|---|---|
#include "query.h"
|
||
#include "condition.h"
|
||
using namespace CuteEntityManager;
|
||
Query::Query() {
|
||
this->select << "*";
|
||
... | ... | |
}
|
||
|
||
void Query::appendCondition(const QString &condition) {
|
||
this->conditions.append(Condition(condition));
|
||
}
|
||
|
||
void Query::appendCondition(const Condition &condition) {
|
||
this->conditions.append(condition);
|
||
}
|
||
QLinkedList<Condition> Query::getConditions() const {
|
||
return conditions;
|
||
}
|
||
|
||
void Query::setConditions(const QLinkedList<Condition> &value) {
|
||
conditions = value;
|
||
}
|
||
|
||
void Query::setSelect(const QStringList &value) {
|
||
select = value;
|
||
... | ... | |
void Query::setOffset(const uint &value) {
|
||
offset = value;
|
||
}
|
||
|
||
QLinkedList<QString> Query::getConditions() const {
|
||
return conditions;
|
||
}
|
||
|
||
void Query::setConditions(const QLinkedList<QString> &value) {
|
||
conditions = value;
|
||
}
|
src/query.h | ||
---|---|---|
#include "join.h"
|
||
|
||
namespace CuteEntityManager {
|
||
class Query
|
||
{
|
||
public:
|
||
class Condition;
|
||
class Query {
|
||
public:
|
||
Query();
|
||
QStringList getSelect() const;
|
||
void setSelect(const QStringList &value);
|
||
... | ... | |
uint getOffset() const;
|
||
void setOffset(const uint &value);
|
||
|
||
QLinkedList<QString> getConditions() const;
|
||
void appendCondition(const QString &condition);
|
||
void setConditions(const QLinkedList<QString> &value);
|
||
void appendCondition(const Condition &condition);
|
||
QLinkedList<Condition> getConditions() const;
|
||
void setConditions(const QLinkedList<Condition> &value);
|
||
|
||
private:
|
||
private:
|
||
QStringList select;
|
||
QString selectOption = QStringLiteral("");
|
||
bool distinct = false;
|
||
QStringList from;
|
||
QStringList groupBy;
|
||
QStringList orderBy;
|
||
QLinkedList<QString> conditions;
|
||
QLinkedList<Condition> conditions;
|
||
QList<Join> joins;
|
||
QHash<QString, QVariant> params;
|
||
uint limit = 0;
|
||
uint offset = 0;
|
||
uint limit = 0;
|
||
uint offset = 0;
|
||
};
|
||
|
||
enum class JokerPosition {
|
src/querybuilder.cpp | ||
---|---|---|
|
||
QString QueryBuilder::between(QString colName, QString valName1,
|
||
QString valName2, bool notOp) {
|
||
return "(" + this->schema->quoteColumnName(colName) + " " + this->between() +
|
||
return "(" + this->schema->quoteColumnName(colName) + (notOp ? (" " +
|
||
this->notKeyword() + " ") : " ") + this->between() +
|
||
" " + this->placeHolder(valName1) + " " + this->andKeyword() + " " +
|
||
this->placeHolder(valName2) + ")";
|
||
}
|
||
... | ... | |
}
|
||
}
|
||
|
||
QSqlQuery QueryBuilder::generateQuery(const Query &query) const {
|
||
|
||
}
|
||
|
||
|
||
void QueryBuilder::where(Query &query, QString column, QVariant value) {
|
||
QString placeholder = column + "_where";
|
||
query.appendCondition(this->schema->quoteColumnName(column) + "=" +
|
src/querybuilder.h | ||
---|---|---|
*/
|
||
void where(Query &query, QHash<QString, QVariant> conditions,
|
||
QString conjunction = "AND");
|
||
void where(Query &query, QString condition,QHash<QString, QVariant> values= QHash<QString, QVariant>());
|
||
void where(Query &query, QString condition,
|
||
QHash<QString, QVariant> values = QHash<QString, QVariant>());
|
||
//void where(Query &query,QHash<QString, QList<QVariant>> conditions, QString concat="AND");
|
||
void between(Query &query, QString column, QVariant firstValue,
|
||
QVariant secondValue);
|
||
... | ... | |
* @param column
|
||
* @param value
|
||
*/
|
||
void like(Query &q, QString column, QVariant value, JokerPosition jp = JokerPosition::BOTH, QChar wildcard ='%');
|
||
void like(Query &q, QString column, QVariant value,
|
||
JokerPosition jp = JokerPosition::BOTH, QChar wildcard = '%');
|
||
/**
|
||
* @brief like
|
||
* @param condition
|
||
* @param concat
|
||
*/
|
||
void like(Query &query, QHash<QString, QVariant> conditions, QString conjunction = "AND",
|
||
JokerPosition jp= JokerPosition::BOTH, QChar wildcard ='%');
|
||
void like(Query &query, QHash<QString, QVariant> conditions,
|
||
QString conjunction = "AND",
|
||
JokerPosition jp = JokerPosition::BOTH, QChar wildcard = '%');
|
||
|
||
protected:
|
||
class ClassAttributes {
|
||
... | ... | |
QString pk;
|
||
QHash<QString, QVariant> attributes;
|
||
};
|
||
QSqlQuery generateQuery(const Query &query) const;
|
||
|
||
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;
|
||
... | ... | |
QString leftJoin(const QString &foreignTable, const QString &tableName,
|
||
const QString &foreignKey = "id", const QString &primaryKey = "id") const;
|
||
QString superClassColumnName(const QMetaObject *&superMeta) const;
|
||
QString addWildcard(QVariant var, JokerPosition jp, QChar jokerChar = '%') const;
|
||
QString addWildcard(QVariant var, JokerPosition jp,
|
||
QChar jokerChar = '%') const;
|
||
|
||
QString joinSuperClasses(const QSharedPointer<Entity> &entity) const;
|
||
virtual QString selectBase(const QStringList &tables,
|
src/queryinterpreter.cpp | ||
---|---|---|
#include "queryinterpreter.h"
|
||
using namespace CuteEntityManager;
|
||
|
||
|
||
QueryInterpreter::QueryInterpreter(QSharedPointer<QueryBuilder> builder) {
|
||
this->builder = builder;
|
||
}
|
||
|
||
QSqlQuery QueryInterpreter::interpretQuery(Query &q) {
|
||
|
||
}
|
src/queryinterpreter.h | ||
---|---|---|
#ifndef QUERYINTERPRETER_H
|
||
#define QUERYINTERPRETER_H
|
||
|
||
#include <QSqlQuery>
|
||
#include <QSharedPointer>
|
||
namespace CuteEntityManager {
|
||
class Query;
|
||
class QueryBuilder;
|
||
class QueryInterpreter {
|
||
public:
|
||
QueryInterpreter(QSharedPointer<QueryBuilder> builder);
|
||
QSqlQuery interpretQuery(Query &q);
|
||
private:
|
||
QSharedPointer<QueryBuilder> builder;
|
||
};
|
||
}
|
||
|
||
#endif // QUERYINTERPRETER_H
|
Auch abrufbar als: Unified diff
query stuff