mirror of
https://github.com/silverqx/TinyORM.git
synced 2026-02-12 05:19:15 -06:00
added new joinSub() overload
With the callback for join on clause.
This commit is contained in:
@@ -203,14 +203,27 @@ namespace Query
|
||||
Builder &joinSub(T &&query, const QString &as, const QString &first,
|
||||
const QString &comparison, const QVariant &second,
|
||||
const QString &type = "inner", bool where = false);
|
||||
/*! Add a subquery join clause to the query. */
|
||||
template<SubQuery T>
|
||||
Builder &joinSub(T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback,
|
||||
const QString &type = "inner");
|
||||
/*! Add a subquery left join to the query. */
|
||||
template<SubQuery T>
|
||||
Builder &leftJoinSub(T &&query, const QString &as, const QString &first,
|
||||
const QString &comparison, const QVariant &second);
|
||||
/*! Add a subquery left join to the query. */
|
||||
template<SubQuery T>
|
||||
Builder &leftJoinSub(T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback);
|
||||
/*! Add a subquery right join to the query. */
|
||||
template<SubQuery T>
|
||||
Builder &rightJoinSub(T &&query, const QString &as, const QString &first,
|
||||
const QString &comparison, const QVariant &second);
|
||||
/*! Add a subquery right join to the query. */
|
||||
template<SubQuery T>
|
||||
Builder &rightJoinSub(T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback);
|
||||
|
||||
/*! Add a basic where clause to the query. */
|
||||
Builder &where(const Column &column, const QString &comparison,
|
||||
@@ -525,6 +538,11 @@ namespace Query
|
||||
std::pair<QString, QVector<QVariant>> &&subQuery, const QString &as,
|
||||
const QString &first, const QString &comparison, const QVariant &second,
|
||||
const QString &type, bool where);
|
||||
/*! Add a subquery join clause to the query, common code. */
|
||||
Builder &joinSubInternal(
|
||||
std::pair<QString, QVector<QVariant>> &&subQuery, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback,
|
||||
const QString &type);
|
||||
|
||||
/*! All of the available clause operators. */
|
||||
const QVector<QString> m_operators {
|
||||
@@ -673,6 +691,7 @@ namespace Query
|
||||
first, comparison, second, where);
|
||||
}
|
||||
|
||||
// FUTURE joinSub, missing where param, also in joinSub silverqx
|
||||
template<JoinTable T>
|
||||
inline Builder &
|
||||
Builder::join(T &&table, const std::function<void(JoinClause &)> &callback,
|
||||
@@ -767,6 +786,15 @@ namespace Query
|
||||
as, first, comparison, second, type, where);
|
||||
}
|
||||
|
||||
template<SubQuery T>
|
||||
inline Builder &
|
||||
Builder::joinSub(T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback,
|
||||
const QString &type)
|
||||
{
|
||||
return joinSubInternal(createSub(std::forward<T>(query)), as, callback, type);
|
||||
}
|
||||
|
||||
template<SubQuery T>
|
||||
inline Builder &
|
||||
Builder::leftJoinSub(T &&query, const QString &as, const QString &first,
|
||||
@@ -776,6 +804,14 @@ namespace Query
|
||||
QStringLiteral("left"));
|
||||
}
|
||||
|
||||
template<SubQuery T>
|
||||
inline Builder &
|
||||
Builder::leftJoinSub(T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback)
|
||||
{
|
||||
return joinSub(std::forward<T>(query), as, callback, QStringLiteral("left"));
|
||||
}
|
||||
|
||||
template<SubQuery T>
|
||||
inline Builder &
|
||||
Builder::rightJoinSub(T &&query, const QString &as, const QString &first,
|
||||
@@ -785,6 +821,14 @@ namespace Query
|
||||
QStringLiteral("right"));
|
||||
}
|
||||
|
||||
template<SubQuery T>
|
||||
inline Builder &
|
||||
Builder::rightJoinSub(T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback)
|
||||
{
|
||||
return joinSub(std::forward<T>(query), as, callback, QStringLiteral("right"));
|
||||
}
|
||||
|
||||
template<ColumnConcept ...Args>
|
||||
inline Builder &Builder::groupBy(Args &&...groups)
|
||||
{
|
||||
|
||||
@@ -373,16 +373,32 @@ namespace Relations {
|
||||
joinSub(T &&query, const QString &as, const QString &first,
|
||||
const QString &comparison, const QVariant &second,
|
||||
const QString &type = "inner", bool where = false);
|
||||
/*! Add a subquery join clause to the query. */
|
||||
template<SubQuery T>
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
joinSub(T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback,
|
||||
const QString &type = "inner");
|
||||
/*! Add a subquery left join to the query. */
|
||||
template<SubQuery T>
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
leftJoinSub(T &&query, const QString &as, const QString &first,
|
||||
const QString &comparison, const QVariant &second);
|
||||
/*! Add a subquery left join to the query. */
|
||||
template<SubQuery T>
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
leftJoinSub(T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback);
|
||||
/*! Add a subquery right join to the query. */
|
||||
template<SubQuery T>
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
rightJoinSub(T &&query, const QString &as, const QString &first,
|
||||
const QString &comparison, const QVariant &second);
|
||||
/*! Add a subquery right join to the query. */
|
||||
template<SubQuery T>
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
rightJoinSub(T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback);
|
||||
|
||||
/*! Add a basic where clause to the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
@@ -1978,6 +1994,21 @@ namespace Relations {
|
||||
return builder;
|
||||
}
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
template<SubQuery T>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::joinSub(
|
||||
T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback,
|
||||
const QString &type)
|
||||
{
|
||||
auto builder = Derived::query();
|
||||
|
||||
builder->joinSub(std::forward<T>(query), as, callback, type);
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
template<SubQuery T>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
@@ -1992,6 +2023,20 @@ namespace Relations {
|
||||
return builder;
|
||||
}
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
template<SubQuery T>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::leftJoinSub(
|
||||
T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback)
|
||||
{
|
||||
auto builder = Derived::query();
|
||||
|
||||
builder->joinSub(std::forward<T>(query), as, callback, QStringLiteral("left"));
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
template<SubQuery T>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
@@ -2006,6 +2051,20 @@ namespace Relations {
|
||||
return builder;
|
||||
}
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
template<SubQuery T>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::rightJoinSub(
|
||||
T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback)
|
||||
{
|
||||
auto builder = Derived::query();
|
||||
|
||||
builder->joinSub(std::forward<T>(query), as, callback, QStringLiteral("right"));
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::where(
|
||||
|
||||
@@ -331,16 +331,32 @@ namespace Relations
|
||||
T &&query, const QString &as, const QString &first,
|
||||
const QString &comparison, const QVariant &second,
|
||||
const QString &type = "inner", bool where = false) const;
|
||||
/*! Add a subquery join clause to the query. */
|
||||
template<SubQuery T>
|
||||
const Relation &joinSub(
|
||||
T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback,
|
||||
const QString &type = "inner") const;
|
||||
/*! Add a subquery left join to the query. */
|
||||
template<SubQuery T>
|
||||
const Relation &leftJoinSub(
|
||||
T &&query, const QString &as, const QString &first,
|
||||
const QString &comparison, const QVariant &second) const;
|
||||
/*! Add a subquery left join to the query. */
|
||||
template<SubQuery T>
|
||||
const Relation &leftJoinSub(
|
||||
T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback) const;
|
||||
/*! Add a subquery right join to the query. */
|
||||
template<SubQuery T>
|
||||
const Relation &rightJoinSub(
|
||||
T &&query, const QString &as, const QString &first,
|
||||
const QString &comparison, const QVariant &second) const;
|
||||
/*! Add a subquery right join to the query. */
|
||||
template<SubQuery T>
|
||||
const Relation &rightJoinSub(
|
||||
T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback) const;
|
||||
|
||||
/*! Add a basic where clause to the query. */
|
||||
const Relation &where(
|
||||
@@ -1130,6 +1146,19 @@ namespace Relations
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class Model, class Related>
|
||||
template<SubQuery T>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::joinSub(
|
||||
T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback,
|
||||
const QString &type) const
|
||||
{
|
||||
m_query->joinSub(std::forward<T>(query), as, callback, type);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class Model, class Related>
|
||||
template<SubQuery T>
|
||||
const Relation<Model, Related> &
|
||||
@@ -1142,6 +1171,18 @@ namespace Relations
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class Model, class Related>
|
||||
template<SubQuery T>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::leftJoinSub(
|
||||
T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback) const
|
||||
{
|
||||
m_query->joinSub(std::forward<T>(query), as, callback, QStringLiteral("left"));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class Model, class Related>
|
||||
template<SubQuery T>
|
||||
const Relation<Model, Related> &
|
||||
@@ -1154,6 +1195,18 @@ namespace Relations
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class Model, class Related>
|
||||
template<SubQuery T>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::rightJoinSub(
|
||||
T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback) const
|
||||
{
|
||||
m_query->joinSub(std::forward<T>(query), as, callback, QStringLiteral("right"));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
Relation<Model, Related>::where(const Column &column, const QString &comparison,
|
||||
|
||||
@@ -246,14 +246,27 @@ namespace Relations
|
||||
Builder &joinSub(T &&query, const QString &as, const QString &first,
|
||||
const QString &comparison, const QVariant &second,
|
||||
const QString &type = "inner", bool where = false);
|
||||
/*! Add a subquery join clause to the query. */
|
||||
template<SubQuery T>
|
||||
Builder &joinSub(T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback,
|
||||
const QString &type = "inner");
|
||||
/*! Add a subquery left join to the query. */
|
||||
template<SubQuery T>
|
||||
Builder &leftJoinSub(T &&query, const QString &as, const QString &first,
|
||||
const QString &comparison, const QVariant &second);
|
||||
/*! Add a subquery left join to the query. */
|
||||
template<SubQuery T>
|
||||
Builder &leftJoinSub(T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback);
|
||||
/*! Add a subquery right join to the query. */
|
||||
template<SubQuery T>
|
||||
Builder &rightJoinSub(T &&query, const QString &as, const QString &first,
|
||||
const QString &comparison, const QVariant &second);
|
||||
/*! Add a subquery right join to the query. */
|
||||
template<SubQuery T>
|
||||
Builder &rightJoinSub(T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback);
|
||||
|
||||
/*! Add a basic where clause to the query. */
|
||||
Builder &where(const Column &column, const QString &comparison,
|
||||
@@ -1095,6 +1108,17 @@ namespace Relations
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename Model>
|
||||
template<SubQuery T>
|
||||
Builder<Model> &
|
||||
Builder<Model>::joinSub(T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback,
|
||||
const QString &type)
|
||||
{
|
||||
toBase().joinSub(std::forward<T>(query), as, callback, type);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename Model>
|
||||
template<SubQuery T>
|
||||
Builder<Model> &
|
||||
@@ -1105,6 +1129,16 @@ namespace Relations
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename Model>
|
||||
template<SubQuery T>
|
||||
Builder<Model> &
|
||||
Builder<Model>::leftJoinSub(T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback)
|
||||
{
|
||||
toBase().joinSub(std::forward<T>(query), as, callback, QStringLiteral("left"));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename Model>
|
||||
template<SubQuery T>
|
||||
Builder<Model> &
|
||||
@@ -1115,6 +1149,16 @@ namespace Relations
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename Model>
|
||||
template<SubQuery T>
|
||||
Builder<Model> &
|
||||
Builder<Model>::rightJoinSub(T &&query, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback)
|
||||
{
|
||||
toBase().joinSub(std::forward<T>(query), as, callback, QStringLiteral("right"));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model> &
|
||||
Builder<Model>::where(const Column &column, const QString &comparison,
|
||||
|
||||
@@ -944,6 +944,20 @@ Builder &Builder::joinSubInternal(
|
||||
first, comparison, second, type, where);
|
||||
}
|
||||
|
||||
Builder &Builder::joinSubInternal(
|
||||
std::pair<QString, QVector<QVariant>> &&subQuery, const QString &as,
|
||||
const std::function<void(JoinClause &)> &callback,
|
||||
const QString &type)
|
||||
{
|
||||
auto &[queryString, bindings] = subQuery;
|
||||
|
||||
addBinding(std::move(bindings), BindingType::JOIN);
|
||||
|
||||
return join(Expression(QStringLiteral("(%1) as %2").arg(queryString,
|
||||
m_grammar.wrapTable(as))),
|
||||
callback, type);
|
||||
}
|
||||
|
||||
} // namespace Orm
|
||||
#ifdef TINYORM_COMMON_NAMESPACE
|
||||
} // namespace TINYORM_COMMON_NAMESPACE
|
||||
|
||||
Reference in New Issue
Block a user