diff --git a/src/query.h b/src/query.h index e7e121c..abe4f7e 100644 --- a/src/query.h +++ b/src/query.h @@ -80,6 +80,10 @@ public: QList toList(int count = -1); template QList select(const FieldPhrase f); + + template + QList select(const std::function allocator); + int count(); QVariant max(const FieldPhrase &f); QVariant min(const FieldPhrase &f); @@ -99,6 +103,33 @@ public: QString sqlCommand() const; }; +template +template +Q_OUTOFLINE_TEMPLATE QList Query::select(const std::function allocator) +{ + Q_D(Query); + QList ret; + + d->joins.prepend(d->tableName); + d->sql = d->database->sqlGenertor()->selectCommand( + d->tableName, + SqlGeneratorBase::SignleField, "*", + d->wherePhrase, + d->relations, + d->skip, d->take); + + QSqlQuery q = d->database->exec(d->sql); + + while (q.next()) { + O obj = allocator(q); + ret.append(obj); + } + + if (m_autoDelete) + deleteLater(); + return ret; +} + //template //inline Query *createQuery(TableSet *tableSet) //{