Revision 0e3a3d7f
Von Christian Ehringfeld vor mehr als 10 Jahren hinzugefügt
| src/querybuilder.cpp | ||
|---|---|---|
|
return q;
|
||
|
}
|
||
|
|
||
|
//@TODO Looks like create() - Refactor code
|
||
|
QList<QSqlQuery> QueryBuilder::merge(const QSharedPointer<Entity> &entity)
|
||
|
const {
|
||
|
return this->createOrMerge(entity, false);
|
||
|
}
|
||
|
|
||
|
|
||
|
QList<QSqlQuery> QueryBuilder::createOrMerge(const QSharedPointer<Entity>
|
||
|
&entity, bool insert) const {
|
||
|
auto attrs = this->inheritedAttributes(entity);
|
||
|
auto queries = QList<QSqlQuery>();
|
||
|
for (int var = 0; var < attrs.size(); ++var) {
|
||
|
auto attr = attrs.at(var);
|
||
|
auto attrHash = attr.getAttributes();
|
||
|
queries.append(this->update(attr.getName(), attrHash, attr.getPk()));
|
||
|
queries.append(insert ? this->insert(attr.getName(), attrHash,
|
||
|
attr.getPk()) : this->update(attr.getName(), attrHash, attr.getPk()));
|
||
|
}
|
||
|
return queries;
|
||
|
}
|
||
|
|
||
|
QList<QSqlQuery> QueryBuilder::create(const QSharedPointer<Entity> &entity)
|
||
|
const {
|
||
|
auto attrs = this->inheritedAttributes(entity);
|
||
|
auto queries = QList<QSqlQuery>();
|
||
|
for (int var = 0; var < attrs.size(); ++var) {
|
||
|
auto attr = attrs.at(var);
|
||
|
auto attrHash = attr.getAttributes();
|
||
|
queries.append(this->insert(attr.getName(), attrHash, attr.getPk()));
|
||
|
}
|
||
|
return queries;
|
||
|
return this->createOrMerge(entity, true);
|
||
|
}
|
||
|
|
||
|
QSqlQuery QueryBuilder::insert(const QString &tableName,
|
||
| ... | ... | |
|
void QueryBuilder::ClassAttributes::setPk(const QString &value) {
|
||
|
pk = value;
|
||
|
}
|
||
|
|
||
| src/querybuilder.h | ||
|---|---|---|
|
const QString &primaryKey = "id") const;
|
||
|
QSqlQuery update(const QString &tableName, QHash<QString, QVariant> &attributes,
|
||
|
const QString &primaryKey = "id") const;
|
||
|
QList<QSqlQuery> createOrMerge(const QSharedPointer<Entity> &entity, bool insert) const;
|
||
|
virtual void createRelationFK(QStringList &queries,
|
||
|
const QSharedPointer<Entity> &entity, const Relation &relation,
|
||
|
const QMetaProperty &metaProperty, const QString &update,
|
||
Auch abrufbar als: Unified diff
refactoring