Revision 975a7f96
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
samples/example/main.cpp | ||
---|---|---|
QSharedPointer<CuteEntityManager::Entity>(new Person("Max", "Mustermann",
|
||
Person::Gender::MALE, "", "", "",
|
||
QDate::currentDate()));
|
||
// qWarning() << "-----------------------------";
|
||
// qWarning() << "Persist Group with Relations";
|
||
// qWarning() << "-----------------------------";
|
||
// QSharedPointer<Group> gPtr = QSharedPointer<Group>(new Group());
|
||
// CreateFakeModelData::fillGroup(gPtr.data());
|
||
// gPtr->setName("9b");
|
||
// QSharedPointer<Entity> groupPtr = gPtr.objectCast<Entity>();
|
||
// QSharedPointer<Person> mainTeacher = QSharedPointer<Person>(new Person("Max",
|
||
// "Mustermann", Person::Gender::MALE));
|
||
// gPtr->setMainTeacher(mainTeacher);
|
||
// //Persons will also persisted
|
||
// if (e->count(groupPtr->getTablename()) <= 0) {
|
||
// e->create(groupPtr, true, true);
|
||
// }
|
||
// qWarning() << "-----------------------------";
|
||
// qWarning() << "Find All Groups";
|
||
// qWarning() << "-----------------------------";
|
||
// QList<QSharedPointer<Group>> groups = e->findAll<Group>();
|
||
// QSharedPointer<Group> groupFindPtr = groups.at(0);
|
||
// qWarning() << "Group:" << groupFindPtr->toString();
|
||
// qWarning() << "MainTeacher:" << groupFindPtr->getMainTeacher()->toString();
|
||
qWarning() << "-----------------------------";
|
||
qWarning() << "Persist Group with Relations";
|
||
qWarning() << "-----------------------------";
|
||
QSharedPointer<Group> gPtr = QSharedPointer<Group>(new Group());
|
||
CreateFakeModelData::fillGroup(gPtr.data());
|
||
gPtr->setName("9b");
|
||
QSharedPointer<Entity> groupPtr = gPtr.objectCast<Entity>();
|
||
QSharedPointer<Person> mainTeacher = QSharedPointer<Person>(new Person("Max",
|
||
"Mustermann", Person::Gender::MALE));
|
||
gPtr->setMainTeacher(mainTeacher);
|
||
//Persons will also persisted
|
||
if (e->count(groupPtr->getTablename()) <= 0) {
|
||
e->create(groupPtr, true, true);
|
||
}
|
||
qWarning() << "-----------------------------";
|
||
qWarning() << "Find All Groups";
|
||
qWarning() << "-----------------------------";
|
||
QList<QSharedPointer<Group>> groups = e->findAll<Group>();
|
||
QSharedPointer<Group> groupFindPtr = groups.at(0);
|
||
qWarning() << "Group:" << groupFindPtr->toString();
|
||
qWarning() << "MainTeacher:" << groupFindPtr->getMainTeacher()->toString();
|
||
|
||
// qWarning() << "-----------------------------";
|
||
// qWarning() << "Find Person By Id Version 1";
|
||
// qWarning() << "-----------------------------";
|
||
qWarning() << "-----------------------------";
|
||
qWarning() << "Find Person By Id Version 1";
|
||
qWarning() << "-----------------------------";
|
||
|
||
// QSharedPointer<Entity> personFindPtr = e->findById(1, QString("Person"));
|
||
// e->refresh(personFindPtr);
|
||
// QSharedPointer<Person> pers = personFindPtr.objectCast<Person>();
|
||
// qWarning() << "MainTeacher:" << personFindPtr->toString();
|
||
// qWarning() << "-----------------------------";
|
||
// qWarning() << "Find Person By Id Version 2";
|
||
// qWarning() << "-----------------------------";
|
||
QSharedPointer<Entity> personFindPtr = e->findById(1, QString("Person"));
|
||
e->refresh(personFindPtr);
|
||
QSharedPointer<Person> pers = personFindPtr.objectCast<Person>();
|
||
qWarning() << "MainTeacher:" << personFindPtr->toString();
|
||
qWarning() << "-----------------------------";
|
||
qWarning() << "Find Person By Id Version 2";
|
||
qWarning() << "-----------------------------";
|
||
|
||
// QSharedPointer<Person> foundMainTeacher = e->findById<Person>(1);
|
||
// qWarning() << "FoundMainTeacher:" << foundMainTeacher->toString();
|
||
QSharedPointer<Person> foundMainTeacher = e->findById<Person>(1);
|
||
qWarning() << "FoundMainTeacher:" << foundMainTeacher->toString();
|
||
|
||
// qWarning() << "-----------------------------";
|
||
// qWarning() << "Find Pupil with Query Class";
|
||
// qWarning() << "-----------------------------";
|
||
qWarning() << "-----------------------------";
|
||
qWarning() << "Find Pupil with Query Class";
|
||
qWarning() << "-----------------------------";
|
||
|
||
// 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<Pupil>> list = e->find<Pupil>(q);
|
||
// for (int i = 0; i < list.size(); ++i) {
|
||
// qWarning() << list.at(i)->toString();
|
||
// }
|
||
// qWarning() << "-----------------------------";
|
||
// qWarning() << "Find Pupil by Attributes";
|
||
// qWarning() << "-----------------------------";
|
||
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<Pupil>> list = e->find<Pupil>(q);
|
||
for (int i = 0; i < list.size(); ++i) {
|
||
qWarning() << list.at(i)->toString();
|
||
}
|
||
qWarning() << "-----------------------------";
|
||
qWarning() << "Find Pupil by Attributes";
|
||
qWarning() << "-----------------------------";
|
||
|
||
// QHash<QString, QVariant> attributes;
|
||
// attributes["familyName"] = QString("Dunst");
|
||
// QSharedPointer<Pupil> pupil = e->findEntityByAttributes<Pupil>
|
||
// (attributes, true);
|
||
// qWarning() << pupil->toString();
|
||
// qWarning() << "-----------------------------";
|
||
// qWarning() << "Merge Group";
|
||
// qWarning() << "-----------------------------";
|
||
// groupFindPtr->setName("10b");
|
||
// qWarning() << groupFindPtr->toString();
|
||
// QSharedPointer<Entity> entityGroupFindPtr = groupFindPtr.objectCast<Entity>();
|
||
// e->save(entityGroupFindPtr, false);
|
||
QHash<QString, QVariant> attributes;
|
||
attributes["familyName"] = QString("Dunst");
|
||
QSharedPointer<Pupil> pupil = e->findEntityByAttributes<Pupil>
|
||
(attributes, true);
|
||
qWarning() << pupil->toString();
|
||
qWarning() << "-----------------------------";
|
||
qWarning() << "Merge Group";
|
||
qWarning() << "-----------------------------";
|
||
groupFindPtr->setName("10b");
|
||
qWarning() << groupFindPtr->toString();
|
||
QSharedPointer<Entity> entityGroupFindPtr = groupFindPtr.objectCast<Entity>();
|
||
e->save(entityGroupFindPtr, false);
|
||
|
||
// qWarning() << "-----------------------------";
|
||
// qWarning() << "Remove Group";
|
||
// qWarning() << "-----------------------------";
|
||
// e->remove(entityGroupFindPtr);
|
||
qWarning() << "-----------------------------";
|
||
qWarning() << "Remove Group";
|
||
qWarning() << "-----------------------------";
|
||
e->remove(entityGroupFindPtr);
|
||
sqliteproc->sqliteDBMemFile(true, "db.sqlite");
|
||
qWarning() << "Duration:" << t.elapsed();
|
||
delete sqliteproc;
|
src/querybuilder.cpp | ||
---|---|---|
QString QueryBuilder::createTableQuery(const QString &tableName,
|
||
const QHash<QString, QString> &tableDefinition) const {
|
||
bool first = true;
|
||
QString s = "CREATE TABLE ";
|
||
s.append(this->schema->quoteTableName(tableName).append(" ("));
|
||
QString s = "CREATE TABLE " + this->schema->quoteTableName(tableName) + " (";
|
||
auto i = tableDefinition.constBegin();
|
||
while (i != tableDefinition.constEnd()) {
|
||
if (first) {
|
||
... | ... | |
}
|
||
|
||
QString QueryBuilder::getColumnType(const QString &type) const {
|
||
/**
|
||
* @WARNING
|
||
*/
|
||
auto tMap = this->schema->getTypeMap();
|
||
if (tMap->contains(type)) {
|
||
return this->transformAbstractTypeToRealDbType(type);
|
||
}
|
||
//cant believe that this could work in Qt
|
||
//https://github.com/yiisoft/yii2/blob/master/framework/db/QueryBuilder.php
|
||
QRegularExpression reg = QRegularExpression(
|
||
QRegularExpression::escape("/^(\\w+)\\((.+?)\\)(.*)$/"));
|
||
reg.optimize();
|
src/schema.h | ||
---|---|---|
const QString TYPE_BOOLEAN = "boolean";
|
||
const QString TYPE_MONEY = "money";
|
||
|
||
// QString primaryKey(int length = 0) const;
|
||
// QString bigPrimaryKey(int length = 0) const;
|
||
// QString string(int length = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString text(bool notNull = false, QString defaultValue = "",
|
||
// bool unique = false, QString checkConstraint = "") const;
|
||
// QString smallInteger(int length = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString integer(int length = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString bigInteger(int length = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString floatColumn(int precision = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString doubleColumn(int precision = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString decimal(int precision = 0, int scale = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString dateTime(int precision = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString timestamp(int precision = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString time(int precision = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString date( bool notNull = false, QString defaultValue = "") const;
|
||
// QString binary(int length = 0, bool notNull = false, bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString boolean(bool defaultValue = 0) const;
|
||
// QString money(int precision = 0, int scale = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
|
||
|
||
|
||
virtual QSharedPointer<QHash<QString, QString> >getTypeMap() = 0;
|
||
virtual QString quoteSimpleTableName(QString name);
|
||
virtual QString quoteTableName(QString name);
|
Auch abrufbar als: Unified diff
...