mirror of
https://github.com/silverqx/TinyORM.git
synced 2026-05-23 02:08:48 -05:00
changed paging type to qint64
Changed in all paging related methods like chunk(), take(), ... - updated unit tests
This commit is contained in:
@@ -34,23 +34,24 @@ namespace Orm::Query::Concerns
|
||||
BuildsQueries &operator=(BuildsQueries &&) = delete;
|
||||
|
||||
/*! Chunk the results of the query. */
|
||||
bool chunk(int count,
|
||||
const std::function<bool(SqlQuery &results, int page)> &callback);
|
||||
bool chunk(qint64 count,
|
||||
const std::function<bool(SqlQuery &results, qint64 page)> &callback);
|
||||
/*! Execute a callback over each item while chunking. */
|
||||
bool each(const std::function<bool(SqlQuery &row, int index)> &callback,
|
||||
int count = 1000);
|
||||
bool each(const std::function<bool(SqlQuery &row, qint64 index)> &callback,
|
||||
qint64 count = 1000);
|
||||
|
||||
/*! Run a map over each item while chunking. */
|
||||
// QVector<QSqlQuery>
|
||||
// chunkMap(const std::function<void(QSqlQuery &row)> &callback, int count = 1000);
|
||||
// chunkMap(const std::function<void(QSqlQuery &row)> &callback, qint64 count = 1000);
|
||||
|
||||
/*! Chunk the results of a query by comparing IDs. */
|
||||
bool chunkById(int count,
|
||||
const std::function<bool(SqlQuery &results, int page)> &callback,
|
||||
bool chunkById(qint64 count,
|
||||
const std::function<
|
||||
bool(SqlQuery &results, qint64 page)> &callback,
|
||||
const QString &column = "", const QString &alias = "");
|
||||
/*! Execute a callback over each item while chunking by ID. */
|
||||
bool eachById(const std::function<bool(SqlQuery &row, int index)> &callback,
|
||||
int count = 1000, const QString &column = "",
|
||||
bool eachById(const std::function<bool(SqlQuery &row, qint64 index)> &callback,
|
||||
qint64 count = 1000, const QString &column = "",
|
||||
const QString &alias = "");
|
||||
|
||||
|
||||
|
||||
@@ -670,22 +670,22 @@ namespace Orm::Query
|
||||
Builder &reorder(const Column &column, const QString &direction = ASC);
|
||||
|
||||
/*! Set the "limit" value of the query. */
|
||||
Builder &limit(int value);
|
||||
Builder &limit(qint64 value);
|
||||
/*! Alias to set the "limit" value of the query. */
|
||||
Builder &take(int value);
|
||||
Builder &take(qint64 value);
|
||||
/*! Set the "offset" value of the query. */
|
||||
Builder &offset(int value);
|
||||
Builder &offset(qint64 value);
|
||||
/*! Alias to set the "offset" value of the query. */
|
||||
Builder &skip(int value);
|
||||
Builder &skip(qint64 value);
|
||||
/*! Set the limit and offset for a given page. */
|
||||
Builder &forPage(int page, int perPage = 30);
|
||||
Builder &forPage(qint64 page, qint64 perPage = 30);
|
||||
|
||||
/*! Constrain the query to the previous "page" of results before a given ID. */
|
||||
Builder &forPageBeforeId(int perPage = 30, const QVariant &lastId = {},
|
||||
Builder &forPageBeforeId(qint64 perPage = 30, const QVariant &lastId = {},
|
||||
const QString &column = Orm::Constants::ID,
|
||||
bool prependOrder = false);
|
||||
/*! Constrain the query to the next "page" of results after a given ID. */
|
||||
Builder &forPageAfterId(int perPage = 30, const QVariant &lastId = {},
|
||||
Builder &forPageAfterId(qint64 perPage = 30, const QVariant &lastId = {},
|
||||
const QString &column = Orm::Constants::ID,
|
||||
bool prependOrder = false);
|
||||
|
||||
@@ -784,9 +784,9 @@ namespace Orm::Query
|
||||
/*! Get the orderings for the query. */
|
||||
inline const QVector<OrderByItem> &getOrders() const noexcept;
|
||||
/*! Get the maximum number of records to return. */
|
||||
inline int getLimit() const noexcept;
|
||||
inline qint64 getLimit() const noexcept;
|
||||
/*! Get the number of records to skip. */
|
||||
inline int getOffset() const noexcept;
|
||||
inline qint64 getOffset() const noexcept;
|
||||
/*! Get the row locking. */
|
||||
inline const std::variant<std::monostate, bool, QString> &
|
||||
getLock() const noexcept;
|
||||
@@ -984,9 +984,9 @@ namespace Orm::Query
|
||||
/*! The orderings for the query. */
|
||||
QVector<OrderByItem> m_orders {};
|
||||
/*! The maximum number of records to return. */
|
||||
int m_limit = -1;
|
||||
qint64 m_limit = -1;
|
||||
/*! The number of records to skip. */
|
||||
int m_offset = -1;
|
||||
qint64 m_offset = -1;
|
||||
/*! Indicates whether row locking is being used. */
|
||||
std::variant<std::monostate, bool, QString> m_lock {};
|
||||
};
|
||||
@@ -1756,12 +1756,12 @@ namespace Orm::Query
|
||||
return m_orders;
|
||||
}
|
||||
|
||||
int Builder::getLimit() const noexcept
|
||||
qint64 Builder::getLimit() const noexcept
|
||||
{
|
||||
return m_limit;
|
||||
}
|
||||
|
||||
int Builder::getOffset() const noexcept
|
||||
qint64 Builder::getOffset() const noexcept
|
||||
{
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
@@ -44,29 +44,30 @@ namespace Concerns
|
||||
BuildsQueries &operator=(BuildsQueries &&) = delete;
|
||||
|
||||
/*! Chunk the results of the query. */
|
||||
bool chunk(int count,
|
||||
bool chunk(qint64 count,
|
||||
const std::function<
|
||||
bool(ModelsCollection<Model> &&models, int page)> &callback);
|
||||
bool(ModelsCollection<Model> &&models, qint64 page)> &callback);
|
||||
/*! Execute a callback over each item while chunking. */
|
||||
bool each(const std::function<bool(Model &&model, int index)> &callback,
|
||||
int count = 1000);
|
||||
bool each(const std::function<bool(Model &&model, qint64 index)> &callback,
|
||||
qint64 count = 1000);
|
||||
|
||||
/*! Run a map over each item while chunking. */
|
||||
ModelsCollection<Model>
|
||||
chunkMap(const std::function<Model(Model &&model)> &callback, int count = 1000);
|
||||
chunkMap(const std::function<Model(Model &&model)> &callback,
|
||||
qint64 count = 1000);
|
||||
/*! Run a map over each item while chunking. */
|
||||
template<typename T>
|
||||
QVector<T>
|
||||
chunkMap(const std::function<T(Model &&model)> &callback, int count = 1000);
|
||||
chunkMap(const std::function<T(Model &&model)> &callback, qint64 count = 1000);
|
||||
|
||||
/*! Chunk the results of a query by comparing IDs. */
|
||||
bool chunkById(int count,
|
||||
bool chunkById(qint64 count,
|
||||
const std::function<
|
||||
bool(ModelsCollection<Model> &&models, int page)> &callback,
|
||||
bool(ModelsCollection<Model> &&models, qint64 page)> &callback,
|
||||
const QString &column = "", const QString &alias = "");
|
||||
/*! Execute a callback over each item while chunking by ID. */
|
||||
bool eachById(const std::function<bool(Model &&model, int index)> &callback,
|
||||
int count = 1000, const QString &column = "",
|
||||
bool eachById(const std::function<bool(Model &&model, qint64 index)> &callback,
|
||||
qint64 count = 1000, const QString &column = "",
|
||||
const QString &alias = "");
|
||||
|
||||
/*! Execute the query and get the first result if it's the sole matching
|
||||
@@ -103,13 +104,13 @@ namespace Concerns
|
||||
|
||||
template<ModelConcept Model>
|
||||
bool BuildsQueries<Model>::chunk(
|
||||
const int count,
|
||||
const std::function<bool(ModelsCollection<Model> &&, int)> &callback)
|
||||
const qint64 count,
|
||||
const std::function<bool(ModelsCollection<Model> &&, qint64)> &callback)
|
||||
{
|
||||
builder().enforceOrderBy();
|
||||
|
||||
int page = 1;
|
||||
int countModels = 0;
|
||||
qint64 page = 1;
|
||||
qint64 countModels = 0;
|
||||
|
||||
do { // NOLINT(cppcoreguidelines-avoid-do-while)
|
||||
/* We'll execute the query for the given page and get the results. If there
|
||||
@@ -117,7 +118,7 @@ namespace Concerns
|
||||
we will call the callback with the current chunk of these results. */
|
||||
auto models = builder().forPage(page, count).get();
|
||||
|
||||
countModels = models.size();
|
||||
countModels = static_cast<qint64>(models.size());
|
||||
|
||||
if (countModels == 0)
|
||||
break;
|
||||
@@ -139,13 +140,13 @@ namespace Concerns
|
||||
}
|
||||
|
||||
template<ModelConcept Model>
|
||||
bool BuildsQueries<Model>::each(const std::function<bool(Model &&, int)> &callback,
|
||||
const int count)
|
||||
bool BuildsQueries<Model>::each(const std::function<bool(Model &&, qint64)> &callback,
|
||||
const qint64 count)
|
||||
{
|
||||
return chunk(count, [&callback]
|
||||
(ModelsCollection<Model> &&models, const int /*unused*/)
|
||||
(ModelsCollection<Model> &&models, const qint64 /*unused*/)
|
||||
{
|
||||
int index = 0;
|
||||
qint64 index = 0;
|
||||
|
||||
for (auto &&model : models)
|
||||
if (const auto result = std::invoke(callback, std::move(model), index++);
|
||||
@@ -160,14 +161,14 @@ namespace Concerns
|
||||
template<ModelConcept Model>
|
||||
ModelsCollection<Model>
|
||||
BuildsQueries<Model>::chunkMap(const std::function<Model(Model &&)> &callback,
|
||||
const int count)
|
||||
const qint64 count)
|
||||
{
|
||||
ModelsCollection<Model> result;
|
||||
// Reserve the first page, it can help reallocations at the beginning
|
||||
result.reserve(static_cast<ModelsCollection<Model>::size_type>(count));
|
||||
|
||||
chunk(count, [&result, &callback]
|
||||
(ModelsCollection<Model> &&models, const int /*unused*/)
|
||||
(ModelsCollection<Model> &&models, const qint64 /*unused*/)
|
||||
{
|
||||
for (auto &&model : models)
|
||||
result << std::invoke(callback, std::move(model));
|
||||
@@ -182,14 +183,14 @@ namespace Concerns
|
||||
template<typename T>
|
||||
QVector<T>
|
||||
BuildsQueries<Model>::chunkMap(const std::function<T(Model &&)> &callback,
|
||||
const int count)
|
||||
const qint64 count)
|
||||
{
|
||||
QVector<T> result;
|
||||
// Reserve the first page, it can help reallocations at the beginning
|
||||
result.reserve(static_cast<QVector<T>::size_type>(count));
|
||||
|
||||
chunk(count, [&result, &callback]
|
||||
(ModelsCollection<Model> &&models, const int /*unused*/)
|
||||
(ModelsCollection<Model> &&models, const qint64 /*unused*/)
|
||||
{
|
||||
for (auto &&model : models)
|
||||
result << std::invoke(callback, std::move(model));
|
||||
@@ -202,15 +203,15 @@ namespace Concerns
|
||||
|
||||
template<ModelConcept Model>
|
||||
bool BuildsQueries<Model>::chunkById(
|
||||
const int count,
|
||||
const std::function<bool(ModelsCollection<Model> &&, int)> &callback,
|
||||
const qint64 count,
|
||||
const std::function<bool(ModelsCollection<Model> &&, qint64)> &callback,
|
||||
const QString &column, const QString &alias)
|
||||
{
|
||||
const auto columnName = column.isEmpty() ? builder().defaultKeyName() : column;
|
||||
const auto aliasName = alias.isEmpty() ? columnName : alias;
|
||||
|
||||
int page = 1;
|
||||
int countModels = 0;
|
||||
qint64 page = 1;
|
||||
qint64 countModels = 0;
|
||||
|
||||
QVariant lastId;
|
||||
|
||||
@@ -222,7 +223,7 @@ namespace Concerns
|
||||
we will call the callback with the current chunk of these results. */
|
||||
auto models = clone.forPageAfterId(count, lastId, columnName, true).get();
|
||||
|
||||
countModels = models.size();
|
||||
countModels = static_cast<qint64>(models.size());
|
||||
|
||||
if (countModels == 0)
|
||||
break;
|
||||
@@ -259,13 +260,13 @@ namespace Concerns
|
||||
|
||||
template<ModelConcept Model>
|
||||
bool BuildsQueries<Model>::eachById(
|
||||
const std::function<bool(Model &&, int)> &callback,
|
||||
const int count, const QString &column, const QString &alias)
|
||||
const std::function<bool(Model &&, qint64)> &callback,
|
||||
const qint64 count, const QString &column, const QString &alias)
|
||||
{
|
||||
return chunkById(count, [&callback, count]
|
||||
(ModelsCollection<Model> &&models, const int page)
|
||||
(ModelsCollection<Model> &&models, const qint64 page)
|
||||
{
|
||||
int index = 0;
|
||||
qint64 index = 0;
|
||||
|
||||
for (auto &&model : models)
|
||||
if (const auto result = std::invoke(callback, std::move(model),
|
||||
|
||||
@@ -810,28 +810,28 @@ namespace Tiny
|
||||
|
||||
/*! Set the "limit" value of the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
limit(int value);
|
||||
limit(qint64 value);
|
||||
/*! Alias to set the "limit" value of the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
take(int value);
|
||||
take(qint64 value);
|
||||
/*! Set the "offset" value of the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
offset(int value);
|
||||
offset(qint64 value);
|
||||
/*! Alias to set the "offset" value of the query. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
skip(int value);
|
||||
skip(qint64 value);
|
||||
/*! Set the limit and offset for a given page. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
forPage(int page, int perPage = 30);
|
||||
forPage(qint64 page, qint64 perPage = 30);
|
||||
|
||||
/*! Constrain the query to the previous "page" of results before a given ID. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
forPageBeforeId(int perPage = 30, const QVariant &lastId = {},
|
||||
forPageBeforeId(qint64 perPage = 30, const QVariant &lastId = {},
|
||||
const QString &column = Orm::Constants::ID,
|
||||
bool prependOrder = false);
|
||||
/*! Constrain the query to the next "page" of results after a given ID. */
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
forPageAfterId(int perPage = 30, const QVariant &lastId = {},
|
||||
forPageAfterId(qint64 perPage = 30, const QVariant &lastId = {},
|
||||
const QString &column = Orm::Constants::ID,
|
||||
bool prependOrder = false);
|
||||
|
||||
@@ -858,33 +858,33 @@ namespace Tiny
|
||||
/* Builds Queries */
|
||||
/*! Chunk the results of the query. */
|
||||
static bool
|
||||
chunk(int count,
|
||||
chunk(qint64 count,
|
||||
const std::function<
|
||||
bool(ModelsCollection<Derived> &&models, int page)> &callback);
|
||||
bool(ModelsCollection<Derived> &&models, qint64 page)> &callback);
|
||||
/*! Execute a callback over each item while chunking. */
|
||||
static bool
|
||||
each(const std::function<bool(Derived &&model, int index)> &callback,
|
||||
int count = 1000);
|
||||
each(const std::function<bool(Derived &&model, qint64 index)> &callback,
|
||||
qint64 count = 1000);
|
||||
|
||||
/*! Run a map over each item while chunking. */
|
||||
static ModelsCollection<Derived>
|
||||
chunkMap(const std::function<Derived(Derived &&model)> &callback,
|
||||
int count = 1000);
|
||||
qint64 count = 1000);
|
||||
/*! Run a map over each item while chunking. */
|
||||
template<typename T>
|
||||
static QVector<T>
|
||||
chunkMap(const std::function<T(Derived &&model)> &callback, int count = 1000);
|
||||
chunkMap(const std::function<T(Derived &&model)> &callback, qint64 count = 1000);
|
||||
|
||||
/*! Chunk the results of a query by comparing IDs. */
|
||||
static bool
|
||||
chunkById(int count,
|
||||
chunkById(qint64 count,
|
||||
const std::function<
|
||||
bool(ModelsCollection<Derived> &&models, int page)> &callback,
|
||||
bool(ModelsCollection<Derived> &&models, qint64 page)> &callback,
|
||||
const QString &column = "", const QString &alias = "");
|
||||
/*! Execute a callback over each item while chunking by ID. */
|
||||
static bool
|
||||
eachById(const std::function<bool(Derived &&model, int index)> &callback,
|
||||
int count = 1000, const QString &column = "",
|
||||
eachById(const std::function<bool(Derived &&model, qint64 index)> &callback,
|
||||
qint64 count = 1000, const QString &column = "",
|
||||
const QString &alias = "");
|
||||
|
||||
/*! Execute the query and get the first result if it's the sole matching
|
||||
@@ -3177,7 +3177,7 @@ namespace Tiny
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
ModelProxies<Derived, AllRelations...>::limit(const int value)
|
||||
ModelProxies<Derived, AllRelations...>::limit(const qint64 value)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
@@ -3188,7 +3188,7 @@ namespace Tiny
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
ModelProxies<Derived, AllRelations...>::take(const int value)
|
||||
ModelProxies<Derived, AllRelations...>::take(const qint64 value)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
@@ -3199,7 +3199,7 @@ namespace Tiny
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
ModelProxies<Derived, AllRelations...>::offset(const int value)
|
||||
ModelProxies<Derived, AllRelations...>::offset(const qint64 value)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
@@ -3210,7 +3210,7 @@ namespace Tiny
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
ModelProxies<Derived, AllRelations...>::skip(const int value)
|
||||
ModelProxies<Derived, AllRelations...>::skip(const qint64 value)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
@@ -3221,7 +3221,8 @@ namespace Tiny
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
ModelProxies<Derived, AllRelations...>::forPage(const int page, const int perPage)
|
||||
ModelProxies<Derived, AllRelations...>::forPage(const qint64 page,
|
||||
const qint64 perPage)
|
||||
{
|
||||
auto builder = query();
|
||||
|
||||
@@ -3233,7 +3234,7 @@ namespace Tiny
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
ModelProxies<Derived, AllRelations...>::forPageBeforeId(
|
||||
const int perPage, const QVariant &lastId, const QString &column,
|
||||
const qint64 perPage, const QVariant &lastId, const QString &column,
|
||||
const bool prependOrder)
|
||||
{
|
||||
auto builder = query();
|
||||
@@ -3246,7 +3247,7 @@ namespace Tiny
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
ModelProxies<Derived, AllRelations...>::forPageAfterId(
|
||||
const int perPage, const QVariant &lastId, const QString &column,
|
||||
const qint64 perPage, const QVariant &lastId, const QString &column,
|
||||
const bool prependOrder)
|
||||
{
|
||||
auto builder = query();
|
||||
@@ -3328,15 +3329,15 @@ namespace Tiny
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
bool ModelProxies<Derived, AllRelations...>::chunk(
|
||||
const int count,
|
||||
const std::function<bool(ModelsCollection<Derived> &&, int)> &callback)
|
||||
const qint64 count,
|
||||
const std::function<bool(ModelsCollection<Derived> &&, qint64)> &callback)
|
||||
{
|
||||
return query()->chunk(count, callback);
|
||||
}
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
bool ModelProxies<Derived, AllRelations...>::each(
|
||||
const std::function<bool(Derived &&, int)> &callback, const int count)
|
||||
const std::function<bool(Derived &&, qint64)> &callback, const qint64 count)
|
||||
{
|
||||
return query()->each(callback, count);
|
||||
}
|
||||
@@ -3344,7 +3345,7 @@ namespace Tiny
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
ModelsCollection<Derived>
|
||||
ModelProxies<Derived, AllRelations...>::chunkMap(
|
||||
const std::function<Derived(Derived &&)> &callback, const int count)
|
||||
const std::function<Derived(Derived &&)> &callback, const qint64 count)
|
||||
{
|
||||
return query()->chunkMap(callback, count);
|
||||
}
|
||||
@@ -3353,15 +3354,15 @@ namespace Tiny
|
||||
template<typename T>
|
||||
QVector<T>
|
||||
ModelProxies<Derived, AllRelations...>::chunkMap(
|
||||
const std::function<T(Derived &&)> &callback, const int count)
|
||||
const std::function<T(Derived &&)> &callback, const qint64 count)
|
||||
{
|
||||
return query()->template chunkMap<T>(callback, count);
|
||||
}
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
bool ModelProxies<Derived, AllRelations...>::chunkById(
|
||||
const int count,
|
||||
const std::function<bool(ModelsCollection<Derived> &&, int)> &callback,
|
||||
const qint64 count,
|
||||
const std::function<bool(ModelsCollection<Derived> &&, qint64)> &callback,
|
||||
const QString &column, const QString &alias)
|
||||
{
|
||||
return query()->chunkById(count, callback, column, alias);
|
||||
@@ -3369,8 +3370,8 @@ namespace Tiny
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
bool ModelProxies<Derived, AllRelations...>::eachById(
|
||||
const std::function<bool(Derived &&, int)> &callback,
|
||||
const int count, const QString &column, const QString &alias)
|
||||
const std::function<bool(Derived &&, qint64)> &callback,
|
||||
const qint64 count, const QString &column, const QString &alias)
|
||||
{
|
||||
return query()->eachById(callback, count, column, alias);
|
||||
}
|
||||
|
||||
@@ -219,33 +219,34 @@ namespace Orm::Tiny::Relations
|
||||
|
||||
/* Builds Queries */
|
||||
/*! Chunk the results of the query. */
|
||||
bool chunk(int count,
|
||||
bool chunk(qint64 count,
|
||||
const std::function<
|
||||
bool(ModelsCollection<Related> &&models, int page)> &callback
|
||||
bool(ModelsCollection<Related> &&models, qint64 page)> &callback
|
||||
) const override;
|
||||
/*! Execute a callback over each item while chunking. */
|
||||
bool each(const std::function<bool(Related &&model, int index)> &callback,
|
||||
int count = 1000) const override;
|
||||
bool each(const std::function<bool(Related &&model, qint64 index)> &callback,
|
||||
qint64 count = 1000) const override;
|
||||
|
||||
/*! Run a map over each item while chunking. */
|
||||
ModelsCollection<Related>
|
||||
chunkMap(const std::function<Related(Related &&model)> &callback,
|
||||
int count = 1000) const override;
|
||||
qint64 count = 1000) const override;
|
||||
/*! Run a map over each item while chunking. */
|
||||
template<typename T>
|
||||
QVector<T>
|
||||
chunkMap(const std::function<T(Related &&model)> &callback,
|
||||
int count = 1000) const;
|
||||
qint64 count = 1000) const;
|
||||
|
||||
/*! Chunk the results of a query by comparing IDs. */
|
||||
bool chunkById(int count,
|
||||
const std::function<
|
||||
bool(ModelsCollection<Related> &&models, int page)> &callback,
|
||||
const QString &column = "",
|
||||
const QString &alias = "") const override;
|
||||
bool
|
||||
chunkById(qint64 count,
|
||||
const std::function<
|
||||
bool(ModelsCollection<Related> &&models, qint64 page)> &callback,
|
||||
const QString &column = "",
|
||||
const QString &alias = "") const override;
|
||||
/*! Execute a callback over each item while chunking by ID. */
|
||||
bool eachById(const std::function<bool(Related &&model, int index)> &callback,
|
||||
int count = 1000, const QString &column = "",
|
||||
bool eachById(const std::function<bool(Related &&model, qint64 index)> &callback,
|
||||
qint64 count = 1000, const QString &column = "",
|
||||
const QString &alias = "") const override;
|
||||
|
||||
/* Inserting/Updating operations on the relationship */
|
||||
@@ -953,12 +954,13 @@ namespace Orm::Tiny::Relations
|
||||
|
||||
template<class Model, class Related, class PivotType>
|
||||
bool BelongsToMany<Model, Related, PivotType>::chunk(
|
||||
const int count,
|
||||
const std::function<bool(ModelsCollection<Related> &&, int)> &callback) const
|
||||
const qint64 count,
|
||||
const std::function<
|
||||
bool(ModelsCollection<Related> &&, qint64)> &callback) const
|
||||
{
|
||||
return prepareQueryBuilder()
|
||||
.chunk(count, [this, &callback]
|
||||
(ModelsCollection<Related> &&models, const int page)
|
||||
(ModelsCollection<Related> &&models, const qint64 page)
|
||||
{
|
||||
hydratePivotRelation(models);
|
||||
|
||||
@@ -968,12 +970,13 @@ namespace Orm::Tiny::Relations
|
||||
|
||||
template<class Model, class Related, class PivotType>
|
||||
bool BelongsToMany<Model, Related, PivotType>::each(
|
||||
const std::function<bool(Related &&, int)> &callback, const int count) const
|
||||
const std::function<bool(Related &&, qint64)> &callback,
|
||||
const qint64 count) const
|
||||
{
|
||||
return chunk(count, [&callback]
|
||||
(ModelsCollection<Related> &&models, const int /*unused*/)
|
||||
(ModelsCollection<Related> &&models, const qint64 /*unused*/)
|
||||
{
|
||||
int index = 0;
|
||||
qint64 index = 0;
|
||||
|
||||
for (auto &&model : models)
|
||||
if (const auto result = std::invoke(callback, std::move(model), index++);
|
||||
@@ -988,14 +991,14 @@ namespace Orm::Tiny::Relations
|
||||
template<class Model, class Related, class PivotType>
|
||||
ModelsCollection<Related>
|
||||
BelongsToMany<Model, Related, PivotType>::chunkMap(
|
||||
const std::function<Related(Related &&)> &callback, const int count) const
|
||||
const std::function<Related(Related &&)> &callback, const qint64 count) const
|
||||
{
|
||||
ModelsCollection<Related> result;
|
||||
// Reserve the first page, it can help reallocations at the beginning
|
||||
result.reserve(static_cast<ModelsCollection<Related>::size_type>(count));
|
||||
|
||||
chunk(count, [&result, &callback]
|
||||
(ModelsCollection<Related> &&models, const int /*unused*/)
|
||||
(ModelsCollection<Related> &&models, const qint64 /*unused*/)
|
||||
{
|
||||
for (auto &&model : models)
|
||||
result << std::invoke(callback, std::move(model));
|
||||
@@ -1010,14 +1013,14 @@ namespace Orm::Tiny::Relations
|
||||
template<typename T>
|
||||
QVector<T>
|
||||
BelongsToMany<Model, Related, PivotType>::chunkMap(
|
||||
const std::function<T(Related &&)> &callback, const int count) const
|
||||
const std::function<T(Related &&)> &callback, const qint64 count) const
|
||||
{
|
||||
QVector<T> result;
|
||||
// Reserve the first page, it can help reallocations at the beginning
|
||||
result.reserve(static_cast<QVector<T>::size_type>(count));
|
||||
|
||||
chunk(count, [&result, &callback]
|
||||
(ModelsCollection<Related> &&models, const int /*unused*/)
|
||||
(ModelsCollection<Related> &&models, const qint64 /*unused*/)
|
||||
{
|
||||
for (auto &&model : models)
|
||||
result << std::invoke(callback, std::move(model));
|
||||
@@ -1030,8 +1033,8 @@ namespace Orm::Tiny::Relations
|
||||
|
||||
template<class Model, class Related, class PivotType>
|
||||
bool BelongsToMany<Model, Related, PivotType>::chunkById(
|
||||
const int count,
|
||||
const std::function<bool(ModelsCollection<Related> &&, int)> &callback,
|
||||
const qint64 count,
|
||||
const std::function<bool(ModelsCollection<Related> &&, qint64)> &callback,
|
||||
const QString &column, const QString &alias) const
|
||||
{
|
||||
const auto &relatedKeyName = this->getRelatedKeyName();
|
||||
@@ -1043,7 +1046,7 @@ namespace Orm::Tiny::Relations
|
||||
|
||||
return prepareQueryBuilder()
|
||||
.chunkById(count, [this, &callback]
|
||||
(ModelsCollection<Related> &&models, const int page)
|
||||
(ModelsCollection<Related> &&models, const qint64 page)
|
||||
{
|
||||
hydratePivotRelation(models);
|
||||
|
||||
@@ -1054,13 +1057,13 @@ namespace Orm::Tiny::Relations
|
||||
|
||||
template<class Model, class Related, class PivotType>
|
||||
bool BelongsToMany<Model, Related, PivotType>::eachById(
|
||||
const std::function<bool(Related &&, int)> &callback,
|
||||
const int count, const QString &column, const QString &alias) const
|
||||
const std::function<bool(Related &&, qint64)> &callback,
|
||||
const qint64 count, const QString &column, const QString &alias) const
|
||||
{
|
||||
return chunkById(count, [&callback, count]
|
||||
(ModelsCollection<Related> &&models, const int page)
|
||||
(ModelsCollection<Related> &&models, const qint64 page)
|
||||
{
|
||||
int index = 0;
|
||||
qint64 index = 0;
|
||||
|
||||
for (auto &&model : models)
|
||||
if (const auto result = std::invoke(callback, std::move(model),
|
||||
|
||||
@@ -795,24 +795,24 @@ namespace Tiny::Relations
|
||||
const Column &column, const QString &direction = ASC) const;
|
||||
|
||||
/*! Set the "limit" value of the query. */
|
||||
const Relation<Model, Related> &limit(int value) const;
|
||||
const Relation<Model, Related> &limit(qint64 value) const;
|
||||
/*! Alias to set the "limit" value of the query. */
|
||||
const Relation<Model, Related> &take(int value) const;
|
||||
const Relation<Model, Related> &take(qint64 value) const;
|
||||
/*! Set the "offset" value of the query. */
|
||||
const Relation<Model, Related> &offset(int value) const;
|
||||
const Relation<Model, Related> &offset(qint64 value) const;
|
||||
/*! Alias to set the "offset" value of the query. */
|
||||
const Relation<Model, Related> &skip(int value) const;
|
||||
const Relation<Model, Related> &skip(qint64 value) const;
|
||||
/*! Set the limit and offset for a given page. */
|
||||
const Relation<Model, Related> &forPage(int page, int perPage = 30) const;
|
||||
const Relation<Model, Related> &forPage(qint64 page, qint64 perPage = 30) const;
|
||||
|
||||
/*! Constrain the query to the previous "page" of results before a given ID. */
|
||||
const Relation<Model, Related> &
|
||||
forPageBeforeId(int perPage = 30, const QVariant &lastId = {},
|
||||
forPageBeforeId(qint64 perPage = 30, const QVariant &lastId = {},
|
||||
const QString &column = Orm::Constants::ID,
|
||||
bool prependOrder = false) const;
|
||||
/*! Constrain the query to the next "page" of results after a given ID. */
|
||||
const Relation<Model, Related> &
|
||||
forPageAfterId(int perPage = 30, const QVariant &lastId = {},
|
||||
forPageAfterId(qint64 perPage = 30, const QVariant &lastId = {},
|
||||
const QString &column = Orm::Constants::ID,
|
||||
bool prependOrder = false) const;
|
||||
|
||||
@@ -851,34 +851,34 @@ namespace Tiny::Relations
|
||||
/* Builds Queries */
|
||||
/*! Chunk the results of the query. */
|
||||
virtual bool
|
||||
chunk(int count,
|
||||
chunk(qint64 count,
|
||||
const std::function<
|
||||
bool(ModelsCollection<Related> &&models, int page)> &callback) const;
|
||||
bool(ModelsCollection<Related> &&models, qint64 page)> &callback) const;
|
||||
/*! Execute a callback over each item while chunking. */
|
||||
virtual bool
|
||||
each(const std::function<bool(Related &&model, int index)> &callback,
|
||||
int count = 1000) const;
|
||||
each(const std::function<bool(Related &&model, qint64 index)> &callback,
|
||||
qint64 count = 1000) const;
|
||||
|
||||
/*! Run a map over each item while chunking. */
|
||||
virtual ModelsCollection<Related>
|
||||
chunkMap(const std::function<Related(Related &&model)> &callback,
|
||||
int count = 1000) const;
|
||||
qint64 count = 1000) const;
|
||||
/*! Run a map over each item while chunking. */
|
||||
template<typename T>
|
||||
QVector<T>
|
||||
chunkMap(const std::function<T(Related &&model)> &callback,
|
||||
int count = 1000) const;
|
||||
qint64 count = 1000) const;
|
||||
|
||||
/*! Chunk the results of a query by comparing IDs. */
|
||||
virtual bool
|
||||
chunkById(int count,
|
||||
chunkById(qint64 count,
|
||||
const std::function<
|
||||
bool(ModelsCollection<Related> &&models, int page)> &callback,
|
||||
bool(ModelsCollection<Related> &&models, qint64 page)> &callback,
|
||||
const QString &column = "", const QString &alias = "") const;
|
||||
/*! Execute a callback over each item while chunking by ID. */
|
||||
virtual bool
|
||||
eachById(const std::function<bool(Related &&model, int index)> &callback,
|
||||
int count = 1000, const QString &column = "",
|
||||
eachById(const std::function<bool(Related &&model, qint64 index)> &callback,
|
||||
qint64 count = 1000, const QString &column = "",
|
||||
const QString &alias = "") const;
|
||||
|
||||
/*! Execute the query and get the first result if it's the sole matching
|
||||
@@ -2932,7 +2932,7 @@ namespace Tiny::Relations
|
||||
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
RelationProxies<Model, Related>::limit(const int value) const
|
||||
RelationProxies<Model, Related>::limit(const qint64 value) const
|
||||
{
|
||||
getQuery().limit(value);
|
||||
|
||||
@@ -2941,7 +2941,7 @@ namespace Tiny::Relations
|
||||
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
RelationProxies<Model, Related>::take(const int value) const
|
||||
RelationProxies<Model, Related>::take(const qint64 value) const
|
||||
{
|
||||
getQuery().take(value);
|
||||
|
||||
@@ -2950,7 +2950,7 @@ namespace Tiny::Relations
|
||||
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
RelationProxies<Model, Related>::offset(const int value) const
|
||||
RelationProxies<Model, Related>::offset(const qint64 value) const
|
||||
{
|
||||
getQuery().offset(value);
|
||||
|
||||
@@ -2959,7 +2959,7 @@ namespace Tiny::Relations
|
||||
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
RelationProxies<Model, Related>::skip(const int value) const
|
||||
RelationProxies<Model, Related>::skip(const qint64 value) const
|
||||
{
|
||||
getQuery().skip(value);
|
||||
|
||||
@@ -2968,7 +2968,8 @@ namespace Tiny::Relations
|
||||
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
RelationProxies<Model, Related>::forPage(const int page, const int perPage) const
|
||||
RelationProxies<Model, Related>::forPage(const qint64 page,
|
||||
const qint64 perPage) const
|
||||
{
|
||||
getQuery().forPage(page, perPage);
|
||||
|
||||
@@ -2978,7 +2979,7 @@ namespace Tiny::Relations
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
RelationProxies<Model, Related>::forPageBeforeId(
|
||||
const int perPage, const QVariant &lastId, const QString &column,
|
||||
const qint64 perPage, const QVariant &lastId, const QString &column,
|
||||
const bool prependOrder) const
|
||||
{
|
||||
getQuery().forPageBeforeId(perPage, lastId, column, prependOrder);
|
||||
@@ -2989,7 +2990,7 @@ namespace Tiny::Relations
|
||||
template<class Model, class Related>
|
||||
const Relation<Model, Related> &
|
||||
RelationProxies<Model, Related>::forPageAfterId(
|
||||
const int perPage, const QVariant &lastId, const QString &column,
|
||||
const qint64 perPage, const QVariant &lastId, const QString &column,
|
||||
const bool prependOrder) const
|
||||
{
|
||||
getQuery().forPageAfterId(perPage, lastId, column, prependOrder);
|
||||
@@ -3092,15 +3093,17 @@ namespace Tiny::Relations
|
||||
/* Builds Queries */
|
||||
template<class Model, class Related>
|
||||
bool RelationProxies<Model, Related>::chunk(
|
||||
const int count,
|
||||
const std::function<bool(ModelsCollection<Related> &&, int)> &callback) const
|
||||
const qint64 count,
|
||||
const std::function<
|
||||
bool(ModelsCollection<Related> &&, qint64)> &callback) const
|
||||
{
|
||||
return getQuery().chunk(count, callback);
|
||||
}
|
||||
|
||||
template<class Model, class Related>
|
||||
bool RelationProxies<Model, Related>::each(
|
||||
const std::function<bool(Related &&, int)> &callback, const int count) const
|
||||
const std::function<bool(Related &&, qint64)> &callback,
|
||||
const qint64 count) const
|
||||
{
|
||||
return getQuery().each(callback, count);
|
||||
}
|
||||
@@ -3108,7 +3111,7 @@ namespace Tiny::Relations
|
||||
template<class Model, class Related>
|
||||
ModelsCollection<Related>
|
||||
RelationProxies<Model, Related>::chunkMap(
|
||||
const std::function<Related(Related &&)> &callback, const int count) const
|
||||
const std::function<Related(Related &&)> &callback, const qint64 count) const
|
||||
{
|
||||
return getQuery().chunkMap(callback, count);
|
||||
}
|
||||
@@ -3117,15 +3120,15 @@ namespace Tiny::Relations
|
||||
template<typename T>
|
||||
QVector<T>
|
||||
RelationProxies<Model, Related>::chunkMap(
|
||||
const std::function<T(Related &&)> &callback, const int count) const
|
||||
const std::function<T(Related &&)> &callback, const qint64 count) const
|
||||
{
|
||||
return getQuery().template chunkMap<T>(callback, count);
|
||||
}
|
||||
|
||||
template<class Model, class Related>
|
||||
bool RelationProxies<Model, Related>::chunkById(
|
||||
const int count,
|
||||
const std::function<bool(ModelsCollection<Related> &&, int)> &callback,
|
||||
const qint64 count,
|
||||
const std::function<bool(ModelsCollection<Related> &&, qint64)> &callback,
|
||||
const QString &column, const QString &alias) const
|
||||
{
|
||||
return getQuery().chunkById(count, callback, column, alias);
|
||||
@@ -3133,8 +3136,8 @@ namespace Tiny::Relations
|
||||
|
||||
template<class Model, class Related>
|
||||
bool RelationProxies<Model, Related>::eachById(
|
||||
const std::function<bool(Related &&, int)> &callback,
|
||||
const int count, const QString &column, const QString &alias) const
|
||||
const std::function<bool(Related &&, qint64)> &callback,
|
||||
const qint64 count, const QString &column, const QString &alias) const
|
||||
{
|
||||
return getQuery().eachById(callback, count, column, alias);
|
||||
}
|
||||
|
||||
@@ -637,24 +637,24 @@ namespace Tiny
|
||||
const QString &direction = ASC);
|
||||
|
||||
/*! Set the "limit" value of the query. */
|
||||
TinyBuilder<Model> &limit(int value);
|
||||
TinyBuilder<Model> &limit(qint64 value);
|
||||
/*! Alias to set the "limit" value of the query. */
|
||||
TinyBuilder<Model> &take(int value);
|
||||
TinyBuilder<Model> &take(qint64 value);
|
||||
/*! Set the "offset" value of the query. */
|
||||
TinyBuilder<Model> &offset(int value);
|
||||
TinyBuilder<Model> &offset(qint64 value);
|
||||
/*! Alias to set the "offset" value of the query. */
|
||||
TinyBuilder<Model> &skip(int value);
|
||||
TinyBuilder<Model> &skip(qint64 value);
|
||||
/*! Set the limit and offset for a given page. */
|
||||
TinyBuilder<Model> &forPage(int page, int perPage = 30);
|
||||
TinyBuilder<Model> &forPage(qint64 page, qint64 perPage = 30);
|
||||
|
||||
/*! Constrain the query to the previous "page" of results before a given ID. */
|
||||
TinyBuilder<Model> &
|
||||
forPageBeforeId(int perPage = 30, const QVariant &lastId = {},
|
||||
forPageBeforeId(qint64 perPage = 30, const QVariant &lastId = {},
|
||||
const QString &column = Orm::Constants::ID,
|
||||
bool prependOrder = false);
|
||||
/*! Constrain the query to the next "page" of results after a given ID. */
|
||||
TinyBuilder<Model> &
|
||||
forPageAfterId(int perPage = 30, const QVariant &lastId = {},
|
||||
forPageAfterId(qint64 perPage = 30, const QVariant &lastId = {},
|
||||
const QString &column = Orm::Constants::ID,
|
||||
bool prependOrder = false);
|
||||
|
||||
@@ -2147,7 +2147,7 @@ namespace Tiny
|
||||
|
||||
template<typename Model>
|
||||
TinyBuilder<Model> &
|
||||
BuilderProxies<Model>::limit(const int value)
|
||||
BuilderProxies<Model>::limit(const qint64 value)
|
||||
{
|
||||
getQuery().limit(value);
|
||||
return builder();
|
||||
@@ -2155,14 +2155,14 @@ namespace Tiny
|
||||
|
||||
template<typename Model>
|
||||
TinyBuilder<Model> &
|
||||
BuilderProxies<Model>::take(const int value)
|
||||
BuilderProxies<Model>::take(const qint64 value)
|
||||
{
|
||||
return limit(value);
|
||||
}
|
||||
|
||||
template<typename Model>
|
||||
TinyBuilder<Model> &
|
||||
BuilderProxies<Model>::offset(const int value)
|
||||
BuilderProxies<Model>::offset(const qint64 value)
|
||||
{
|
||||
getQuery().offset(value);
|
||||
return builder();
|
||||
@@ -2170,14 +2170,14 @@ namespace Tiny
|
||||
|
||||
template<typename Model>
|
||||
TinyBuilder<Model> &
|
||||
BuilderProxies<Model>::skip(const int value)
|
||||
BuilderProxies<Model>::skip(const qint64 value)
|
||||
{
|
||||
return offset(value);
|
||||
}
|
||||
|
||||
template<typename Model>
|
||||
TinyBuilder<Model> &
|
||||
BuilderProxies<Model>::forPage(const int page, const int perPage)
|
||||
BuilderProxies<Model>::forPage(const qint64 page, const qint64 perPage)
|
||||
{
|
||||
getQuery().forPage(page, perPage);
|
||||
return builder();
|
||||
@@ -2185,7 +2185,7 @@ namespace Tiny
|
||||
|
||||
template<typename Model>
|
||||
TinyBuilder<Model> &
|
||||
BuilderProxies<Model>::forPageBeforeId(const int perPage, const QVariant &lastId,
|
||||
BuilderProxies<Model>::forPageBeforeId(const qint64 perPage, const QVariant &lastId,
|
||||
const QString &column, const bool prependOrder)
|
||||
{
|
||||
getQuery().forPageBeforeId(perPage, lastId, column, prependOrder);
|
||||
@@ -2194,7 +2194,7 @@ namespace Tiny
|
||||
|
||||
template<typename Model>
|
||||
TinyBuilder<Model> &
|
||||
BuilderProxies<Model>::forPageAfterId(const int perPage, const QVariant &lastId,
|
||||
BuilderProxies<Model>::forPageAfterId(const qint64 perPage, const QVariant &lastId,
|
||||
const QString &column, const bool prependOrder)
|
||||
{
|
||||
getQuery().forPageAfterId(perPage, lastId, column, prependOrder);
|
||||
|
||||
@@ -15,13 +15,13 @@ namespace Orm::Query::Concerns
|
||||
|
||||
/* public */
|
||||
|
||||
bool BuildsQueries::chunk(const int count,
|
||||
const std::function<bool(SqlQuery &, int)> &callback)
|
||||
bool BuildsQueries::chunk(const qint64 count,
|
||||
const std::function<bool(SqlQuery &, qint64)> &callback)
|
||||
{
|
||||
builder().enforceOrderBy();
|
||||
|
||||
int page = 1;
|
||||
int countResults = 0;
|
||||
qint64 page = 1;
|
||||
qint64 countResults = 0;
|
||||
|
||||
do { // NOLINT(cppcoreguidelines-avoid-do-while)
|
||||
/* We'll execute the query for the given page and get the results. If there are
|
||||
@@ -29,7 +29,7 @@ bool BuildsQueries::chunk(const int count,
|
||||
we will call the callback with the current chunk of these results here. */
|
||||
auto results = builder().forPage(page, count).get();
|
||||
|
||||
countResults = QueryUtils::queryResultSize(results);
|
||||
countResults = static_cast<qint64>(QueryUtils::queryResultSize(results));
|
||||
|
||||
if (countResults == 0)
|
||||
break;
|
||||
@@ -49,12 +49,12 @@ bool BuildsQueries::chunk(const int count,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BuildsQueries::each(const std::function<bool(SqlQuery &, int)> &callback,
|
||||
const int count)
|
||||
bool BuildsQueries::each(const std::function<bool(SqlQuery &, qint64)> &callback,
|
||||
const qint64 count)
|
||||
{
|
||||
return chunk(count, [&callback](SqlQuery &results, const int /*unused*/)
|
||||
return chunk(count, [&callback](SqlQuery &results, const qint64 /*unused*/)
|
||||
{
|
||||
int index = 0;
|
||||
qint64 index = 0;
|
||||
|
||||
while (results.next())
|
||||
if (const auto result = std::invoke(callback, results, index++);
|
||||
@@ -69,7 +69,7 @@ bool BuildsQueries::each(const std::function<bool(SqlQuery &, int)> &callback,
|
||||
/* This is trash as the QSqlQuery is passed to the callback, I need to pass something
|
||||
like std::map<std::pair<int, QString>, QVariant> so an user can modify it and return */
|
||||
//QVector<QSqlQuery>
|
||||
//BuildsQueries::chunkMap(const std::function<void(QSqlQuery &)> &callback, const int count)
|
||||
//BuildsQueries::chunkMap(const std::function<void(QSqlQuery &)> &callback, const qint64 count)
|
||||
//{
|
||||
// /* This method is weird, it should return one merged collection with all rows, but
|
||||
// it's impossible to merge more QSqlQuery-ies into the one QSqlQuery, so I have
|
||||
@@ -83,7 +83,7 @@ bool BuildsQueries::each(const std::function<bool(SqlQuery &, int)> &callback,
|
||||
// processed/looped then move a whole QSqlQuery into the result vector. */
|
||||
// QVector<QSqlQuery> result;
|
||||
|
||||
// chunk(count, [&result, &callback](QSqlQuery &results, const int /*unused*/)
|
||||
// chunk(count, [&result, &callback](QSqlQuery &results, const qint64 /*unused*/)
|
||||
// {
|
||||
// while (results.next())
|
||||
// std::invoke(callback, results);
|
||||
@@ -97,14 +97,14 @@ bool BuildsQueries::each(const std::function<bool(SqlQuery &, int)> &callback,
|
||||
//}
|
||||
|
||||
bool BuildsQueries::chunkById(
|
||||
const int count, const std::function<bool(SqlQuery &, int)> &callback,
|
||||
const qint64 count, const std::function<bool(SqlQuery &, qint64)> &callback,
|
||||
const QString &column, const QString &alias)
|
||||
{
|
||||
const auto columnName = column.isEmpty() ? builder().defaultKeyName() : column;
|
||||
const auto aliasName = alias.isEmpty() ? columnName : alias;
|
||||
|
||||
int page = 1;
|
||||
int countResults = 0;
|
||||
qint64 page = 1;
|
||||
qint64 countResults = 0;
|
||||
|
||||
QVariant lastId;
|
||||
|
||||
@@ -116,7 +116,7 @@ bool BuildsQueries::chunkById(
|
||||
we will call the callback with the current chunk of these results here. */
|
||||
auto results = clone.forPageAfterId(count, lastId, columnName, true).get();
|
||||
|
||||
countResults = QueryUtils::queryResultSize(results);
|
||||
countResults = static_cast<qint64>(QueryUtils::queryResultSize(results));
|
||||
|
||||
if (countResults == 0)
|
||||
break;
|
||||
@@ -153,12 +153,12 @@ bool BuildsQueries::chunkById(
|
||||
}
|
||||
|
||||
bool BuildsQueries::eachById(
|
||||
const std::function<bool(SqlQuery &, int)> &callback,
|
||||
const int count, const QString &column, const QString &alias)
|
||||
const std::function<bool(SqlQuery &, qint64)> &callback,
|
||||
const qint64 count, const QString &column, const QString &alias)
|
||||
{
|
||||
return chunkById(count, [&callback, count](SqlQuery &results, const int page)
|
||||
return chunkById(count, [&callback, count](SqlQuery &results, const qint64 page)
|
||||
{
|
||||
int index = 0;
|
||||
qint64 index = 0;
|
||||
|
||||
while (results.next())
|
||||
if (const auto result = std::invoke(callback, results,
|
||||
|
||||
@@ -1067,7 +1067,7 @@ Builder &Builder::reorder(const Column &column, const QString &direction)
|
||||
return orderBy(column, direction);
|
||||
}
|
||||
|
||||
Builder &Builder::limit(const int value)
|
||||
Builder &Builder::limit(const qint64 value)
|
||||
{
|
||||
/* I checked negative limit/offset, MySQL and PostgreSQL throws an error,
|
||||
SQLite accepts a negative value, but it has no effect and Microsoft SQL Server
|
||||
@@ -1081,12 +1081,12 @@ Builder &Builder::limit(const int value)
|
||||
return *this;
|
||||
}
|
||||
|
||||
Builder &Builder::take(const int value)
|
||||
Builder &Builder::take(const qint64 value)
|
||||
{
|
||||
return limit(value);
|
||||
}
|
||||
|
||||
Builder &Builder::offset(const int value)
|
||||
Builder &Builder::offset(const qint64 value)
|
||||
{
|
||||
Q_ASSERT(value >= 0);
|
||||
|
||||
@@ -1095,18 +1095,18 @@ Builder &Builder::offset(const int value)
|
||||
return *this;
|
||||
}
|
||||
|
||||
Builder &Builder::skip(const int value)
|
||||
Builder &Builder::skip(const qint64 value)
|
||||
{
|
||||
return offset(value);
|
||||
}
|
||||
|
||||
Builder &Builder::forPage(const int page, const int perPage)
|
||||
Builder &Builder::forPage(const qint64 page, const qint64 perPage)
|
||||
{
|
||||
return offset((page - 1) * perPage).limit(perPage);
|
||||
}
|
||||
|
||||
// NOTE api little different, added bool prependOrder parameter silverqx
|
||||
Builder &Builder::forPageBeforeId(const int perPage, const QVariant &lastId,
|
||||
Builder &Builder::forPageBeforeId(const qint64 perPage, const QVariant &lastId,
|
||||
const QString &column, const bool prependOrder)
|
||||
{
|
||||
m_orders = removeExistingOrdersFor(column);
|
||||
@@ -1123,7 +1123,7 @@ Builder &Builder::forPageBeforeId(const int perPage, const QVariant &lastId,
|
||||
}
|
||||
|
||||
// NOTE api little different, added bool prependOrder parameter silverqx
|
||||
Builder &Builder::forPageAfterId(const int perPage, const QVariant &lastId,
|
||||
Builder &Builder::forPageAfterId(const qint64 perPage, const QVariant &lastId,
|
||||
const QString &column, const bool prependOrder)
|
||||
{
|
||||
m_orders = removeExistingOrdersFor(column);
|
||||
|
||||
@@ -1635,13 +1635,14 @@ void tst_QueryBuilder::chunk() const
|
||||
QFETCH_GLOBAL(QString, connection);
|
||||
|
||||
// <page, chunk_rowsCount>
|
||||
const std::unordered_map<int, int> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
const std::unordered_map<qint64, qint64> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](SqlQuery &query, const int page)
|
||||
const auto compareResultSize = [&expectedRows](SqlQuery &query, const qint64 page)
|
||||
{
|
||||
QCOMPARE(QueryUtils::queryResultSize(query), expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(QueryUtils::queryResultSize(query)),
|
||||
expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -1649,7 +1650,8 @@ void tst_QueryBuilder::chunk() const
|
||||
|
||||
auto result = createQuery(connection)->from("file_property_properties")
|
||||
.orderBy(ID)
|
||||
.chunk(3, [&compareResultSize, &ids](SqlQuery &query, const int page)
|
||||
.chunk(3, [&compareResultSize, &ids]
|
||||
(SqlQuery &query, const qint64 page)
|
||||
{
|
||||
compareResultSize(query, page);
|
||||
|
||||
@@ -1672,13 +1674,14 @@ void tst_QueryBuilder::chunk_ReturnFalse() const
|
||||
QFETCH_GLOBAL(QString, connection);
|
||||
|
||||
// <page, chunk_rowsCount> (I leave it here also in this test, doesn't matter much
|
||||
const std::unordered_map<int, int> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
const std::unordered_map<qint64, qint64> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](SqlQuery &query, const int page)
|
||||
const auto compareResultSize = [&expectedRows](SqlQuery &query, const qint64 page)
|
||||
{
|
||||
QCOMPARE(QueryUtils::queryResultSize(query), expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(QueryUtils::queryResultSize(query)),
|
||||
expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -1686,7 +1689,8 @@ void tst_QueryBuilder::chunk_ReturnFalse() const
|
||||
|
||||
auto result = createQuery(connection)->from("file_property_properties")
|
||||
.orderBy(ID)
|
||||
.chunk(3, [&compareResultSize, &ids](SqlQuery &query, const int page)
|
||||
.chunk(3, [&compareResultSize, &ids]
|
||||
(SqlQuery &query, const qint64 page)
|
||||
{
|
||||
compareResultSize(query, page);
|
||||
|
||||
@@ -1715,11 +1719,11 @@ void tst_QueryBuilder::chunk_EnforceOrderBy() const
|
||||
QFETCH_GLOBAL(QString, connection);
|
||||
|
||||
QVERIFY_EXCEPTION_THROWN(createQuery(connection)->from("file_property_properties")
|
||||
.chunk(3, [](SqlQuery &/*unused*/, const int /*unused*/)
|
||||
.chunk(3, [](SqlQuery &/*unused*/, const qint64 /*unused*/)
|
||||
{
|
||||
return true;
|
||||
}),
|
||||
RuntimeError);
|
||||
RuntimeError);
|
||||
}
|
||||
|
||||
void tst_QueryBuilder::chunk_EmptyResult() const
|
||||
@@ -1732,7 +1736,7 @@ void tst_QueryBuilder::chunk_EmptyResult() const
|
||||
.whereEq(NAME, QStringLiteral("dummy-NON_EXISTENT"))
|
||||
.orderBy(ID)
|
||||
.chunk(3, [&callbackInvoked]
|
||||
(SqlQuery &/*unused*/, const int /*unused*/)
|
||||
(SqlQuery &/*unused*/, const qint64 /*unused*/)
|
||||
{
|
||||
callbackInvoked = true;
|
||||
|
||||
@@ -1747,14 +1751,14 @@ void tst_QueryBuilder::each() const
|
||||
{
|
||||
QFETCH_GLOBAL(QString, connection);
|
||||
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(8);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(8);
|
||||
|
||||
auto result = createQuery(connection)->from("file_property_properties")
|
||||
.orderBy(ID)
|
||||
.each([&indexes, &ids](SqlQuery &query, const int index)
|
||||
.each([&indexes, &ids](SqlQuery &query, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(query.value(ID).value<quint64>());
|
||||
@@ -1764,7 +1768,7 @@ void tst_QueryBuilder::each() const
|
||||
|
||||
QVERIFY(result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7};
|
||||
std::vector<qint64> expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7};
|
||||
std::vector<quint64> expectedIds {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -1777,14 +1781,14 @@ void tst_QueryBuilder::each_ReturnFalse() const
|
||||
{
|
||||
QFETCH_GLOBAL(QString, connection);
|
||||
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(5);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(5);
|
||||
|
||||
auto result = createQuery(connection)->from("file_property_properties")
|
||||
.orderBy(ID)
|
||||
.each([&indexes, &ids](SqlQuery &query, const int index)
|
||||
.each([&indexes, &ids](SqlQuery &query, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(query.value(ID).value<quint64>());
|
||||
@@ -1794,7 +1798,7 @@ void tst_QueryBuilder::each_ReturnFalse() const
|
||||
|
||||
QVERIFY(!result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1, 2, 3, 4};
|
||||
std::vector<qint64> expectedIndexes {0, 1, 2, 3, 4};
|
||||
std::vector<quint64> expectedIds {1, 2, 3, 4, 5};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -1808,11 +1812,11 @@ void tst_QueryBuilder::each_EnforceOrderBy() const
|
||||
QFETCH_GLOBAL(QString, connection);
|
||||
|
||||
QVERIFY_EXCEPTION_THROWN(createQuery(connection)->from("file_property_properties")
|
||||
.each([](SqlQuery &/*unused*/, const int /*unused*/)
|
||||
.each([](SqlQuery &/*unused*/, const qint64 /*unused*/)
|
||||
{
|
||||
return true;
|
||||
}),
|
||||
RuntimeError);
|
||||
RuntimeError);
|
||||
}
|
||||
|
||||
void tst_QueryBuilder::each_EmptyResult() const
|
||||
@@ -1825,7 +1829,7 @@ void tst_QueryBuilder::each_EmptyResult() const
|
||||
.whereEq(NAME, QStringLiteral("dummy-NON_EXISTENT"))
|
||||
.orderBy(ID)
|
||||
.each([&callbackInvoked]
|
||||
(SqlQuery &/*unused*/, const int /*unused*/)
|
||||
(SqlQuery &/*unused*/, const qint64 /*unused*/)
|
||||
{
|
||||
callbackInvoked = true;
|
||||
|
||||
@@ -1841,13 +1845,14 @@ void tst_QueryBuilder::chunkById() const
|
||||
QFETCH_GLOBAL(QString, connection);
|
||||
|
||||
// <page, chunk_rowsCount>
|
||||
const std::unordered_map<int, int> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
const std::unordered_map<qint64, qint64> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](SqlQuery &query, const int page)
|
||||
const auto compareResultSize = [&expectedRows](SqlQuery &query, const qint64 page)
|
||||
{
|
||||
QCOMPARE(QueryUtils::queryResultSize(query), expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(QueryUtils::queryResultSize(query)),
|
||||
expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -1856,7 +1861,7 @@ void tst_QueryBuilder::chunkById() const
|
||||
auto result = createQuery(connection)->from("file_property_properties")
|
||||
.orderBy(ID)
|
||||
.chunkById(3, [&compareResultSize, &ids]
|
||||
(SqlQuery &query, const int page)
|
||||
(SqlQuery &query, const qint64 page)
|
||||
{
|
||||
compareResultSize(query, page);
|
||||
|
||||
@@ -1879,13 +1884,14 @@ void tst_QueryBuilder::chunkById_ReturnFalse() const
|
||||
QFETCH_GLOBAL(QString, connection);
|
||||
|
||||
// <page, chunk_rowsCount> (I leave it here also in this test, doesn't matter much
|
||||
const std::unordered_map<int, int> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
const std::unordered_map<qint64, qint64> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](SqlQuery &query, const int page)
|
||||
const auto compareResultSize = [&expectedRows](SqlQuery &query, const qint64 page)
|
||||
{
|
||||
QCOMPARE(QueryUtils::queryResultSize(query), expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(QueryUtils::queryResultSize(query)),
|
||||
expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -1894,7 +1900,7 @@ void tst_QueryBuilder::chunkById_ReturnFalse() const
|
||||
auto result = createQuery(connection)->from("file_property_properties")
|
||||
.orderBy(ID)
|
||||
.chunkById(3, [&compareResultSize, &ids]
|
||||
(SqlQuery &query, const int page)
|
||||
(SqlQuery &query, const qint64 page)
|
||||
{
|
||||
compareResultSize(query, page);
|
||||
|
||||
@@ -1928,7 +1934,7 @@ void tst_QueryBuilder::chunkById_EmptyResult() const
|
||||
.whereEq(NAME, QStringLiteral("dummy-NON_EXISTENT"))
|
||||
.orderBy(ID)
|
||||
.chunkById(3, [&callbackInvoked]
|
||||
(SqlQuery &/*unused*/, const int /*unused*/)
|
||||
(SqlQuery &/*unused*/, const qint64 /*unused*/)
|
||||
{
|
||||
callbackInvoked = true;
|
||||
|
||||
@@ -1944,13 +1950,14 @@ void tst_QueryBuilder::chunkById_WithAlias() const
|
||||
QFETCH_GLOBAL(QString, connection);
|
||||
|
||||
// <page, chunk_rowsCount>
|
||||
const std::unordered_map<int, int> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
const std::unordered_map<qint64, qint64> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](SqlQuery &query, const int page)
|
||||
const auto compareResultSize = [&expectedRows](SqlQuery &query, const qint64 page)
|
||||
{
|
||||
QCOMPARE(QueryUtils::queryResultSize(query), expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(QueryUtils::queryResultSize(query)),
|
||||
expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -1960,7 +1967,7 @@ void tst_QueryBuilder::chunkById_WithAlias() const
|
||||
.select({ASTERISK, "id as id_as"})
|
||||
.orderBy(ID)
|
||||
.chunkById(3, [&compareResultSize, &ids]
|
||||
(SqlQuery &query, const int page)
|
||||
(SqlQuery &query, const qint64 page)
|
||||
{
|
||||
compareResultSize(query, page);
|
||||
|
||||
@@ -1969,7 +1976,7 @@ void tst_QueryBuilder::chunkById_WithAlias() const
|
||||
|
||||
return true;
|
||||
},
|
||||
ID, "id_as");
|
||||
ID, "id_as");
|
||||
|
||||
QVERIFY(result);
|
||||
|
||||
@@ -1984,13 +1991,14 @@ void tst_QueryBuilder::chunkById_ReturnFalse_WithAlias() const
|
||||
QFETCH_GLOBAL(QString, connection);
|
||||
|
||||
// <page, chunk_rowsCount> (I leave it here also in this test, doesn't matter much
|
||||
const std::unordered_map<int, int> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
const std::unordered_map<qint64, qint64> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](SqlQuery &query, const int page)
|
||||
const auto compareResultSize = [&expectedRows](SqlQuery &query, const qint64 page)
|
||||
{
|
||||
QCOMPARE(QueryUtils::queryResultSize(query), expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(QueryUtils::queryResultSize(query)),
|
||||
expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -2000,7 +2008,7 @@ void tst_QueryBuilder::chunkById_ReturnFalse_WithAlias() const
|
||||
.select({ASTERISK, "id as id_as"})
|
||||
.orderBy(ID)
|
||||
.chunkById(3, [&compareResultSize, &ids]
|
||||
(SqlQuery &query, const int page)
|
||||
(SqlQuery &query, const qint64 page)
|
||||
{
|
||||
compareResultSize(query, page);
|
||||
|
||||
@@ -2015,7 +2023,7 @@ void tst_QueryBuilder::chunkById_ReturnFalse_WithAlias() const
|
||||
|
||||
return true;
|
||||
},
|
||||
ID, "id_as");
|
||||
ID, "id_as");
|
||||
|
||||
QVERIFY(!result);
|
||||
|
||||
@@ -2036,13 +2044,13 @@ void tst_QueryBuilder::chunkById_EmptyResult_WithAlias() const
|
||||
.whereEq(NAME, QStringLiteral("dummy-NON_EXISTENT"))
|
||||
.orderBy(ID)
|
||||
.chunkById(3, [&callbackInvoked]
|
||||
(SqlQuery &/*unused*/, const int /*unused*/)
|
||||
(SqlQuery &/*unused*/, const qint64 /*unused*/)
|
||||
{
|
||||
callbackInvoked = true;
|
||||
|
||||
return true;
|
||||
},
|
||||
ID, "id_as");
|
||||
ID, "id_as");
|
||||
|
||||
QVERIFY(!callbackInvoked);
|
||||
QVERIFY(result);
|
||||
@@ -2052,14 +2060,14 @@ void tst_QueryBuilder::eachById() const
|
||||
{
|
||||
QFETCH_GLOBAL(QString, connection);
|
||||
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(8);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(8);
|
||||
|
||||
auto result = createQuery(connection)->from("file_property_properties")
|
||||
.orderBy(ID)
|
||||
.eachById([&indexes, &ids](SqlQuery &query, const int index)
|
||||
.eachById([&indexes, &ids](SqlQuery &query, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(query.value(ID).value<quint64>());
|
||||
@@ -2069,7 +2077,7 @@ void tst_QueryBuilder::eachById() const
|
||||
|
||||
QVERIFY(result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7};
|
||||
std::vector<qint64> expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7};
|
||||
std::vector<quint64> expectedIds {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -2082,14 +2090,14 @@ void tst_QueryBuilder::eachById_ReturnFalse() const
|
||||
{
|
||||
QFETCH_GLOBAL(QString, connection);
|
||||
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(5);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(5);
|
||||
|
||||
auto result = createQuery(connection)->from("file_property_properties")
|
||||
.orderBy(ID)
|
||||
.eachById([&indexes, &ids](SqlQuery &query, const int index)
|
||||
.eachById([&indexes, &ids](SqlQuery &query, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(query.value(ID).value<quint64>());
|
||||
@@ -2099,7 +2107,7 @@ void tst_QueryBuilder::eachById_ReturnFalse() const
|
||||
|
||||
QVERIFY(!result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1, 2, 3, 4};
|
||||
std::vector<qint64> expectedIndexes {0, 1, 2, 3, 4};
|
||||
std::vector<quint64> expectedIds {1, 2, 3, 4, 5};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -2118,7 +2126,7 @@ void tst_QueryBuilder::eachById_EmptyResult() const
|
||||
.whereEq(NAME, QStringLiteral("dummy-NON_EXISTENT"))
|
||||
.orderBy(ID)
|
||||
.eachById([&callbackInvoked]
|
||||
(SqlQuery &/*unused*/, const int /*unused*/)
|
||||
(SqlQuery &/*unused*/, const qint64 /*unused*/)
|
||||
{
|
||||
callbackInvoked = true;
|
||||
|
||||
@@ -2133,7 +2141,7 @@ void tst_QueryBuilder::eachById_WithAlias() const
|
||||
{
|
||||
QFETCH_GLOBAL(QString, connection);
|
||||
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(8);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(8);
|
||||
@@ -2141,18 +2149,18 @@ void tst_QueryBuilder::eachById_WithAlias() const
|
||||
auto result = createQuery(connection)->from("file_property_properties")
|
||||
.select({ASTERISK, "id as id_as"})
|
||||
.orderBy(ID)
|
||||
.eachById([&indexes, &ids](SqlQuery &query, const int index)
|
||||
.eachById([&indexes, &ids](SqlQuery &query, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(query.value(ID).value<quint64>());
|
||||
|
||||
return true;
|
||||
},
|
||||
1000, ID, "id_as");
|
||||
1000, ID, "id_as");
|
||||
|
||||
QVERIFY(result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7};
|
||||
std::vector<qint64> expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7};
|
||||
std::vector<quint64> expectedIds {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -2165,7 +2173,7 @@ void tst_QueryBuilder::eachById_ReturnFalse_WithAlias() const
|
||||
{
|
||||
QFETCH_GLOBAL(QString, connection);
|
||||
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(5);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(5);
|
||||
@@ -2173,18 +2181,18 @@ void tst_QueryBuilder::eachById_ReturnFalse_WithAlias() const
|
||||
auto result = createQuery(connection)->from("file_property_properties")
|
||||
.select({ASTERISK, "id as id_as"})
|
||||
.orderBy(ID)
|
||||
.eachById([&indexes, &ids](SqlQuery &query, const int index)
|
||||
.eachById([&indexes, &ids](SqlQuery &query, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(query.value(ID).value<quint64>());
|
||||
|
||||
return index != 4; // false/interrupt on 4
|
||||
},
|
||||
1000, ID, "id_as");
|
||||
1000, ID, "id_as");
|
||||
|
||||
QVERIFY(!result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1, 2, 3, 4};
|
||||
std::vector<qint64> expectedIndexes {0, 1, 2, 3, 4};
|
||||
std::vector<quint64> expectedIds {1, 2, 3, 4, 5};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -2204,13 +2212,13 @@ void tst_QueryBuilder::eachById_EmptyResult_WithAlias() const
|
||||
.whereEq(NAME, QStringLiteral("dummy-NON_EXISTENT"))
|
||||
.orderBy(ID)
|
||||
.eachById([&callbackInvoked]
|
||||
(SqlQuery &/*unused*/, const int /*unused*/)
|
||||
(SqlQuery &/*unused*/, const qint64 /*unused*/)
|
||||
{
|
||||
callbackInvoked = true;
|
||||
|
||||
return true;
|
||||
},
|
||||
1000, ID, "id_as");
|
||||
1000, ID, "id_as");
|
||||
|
||||
QVERIFY(!callbackInvoked);
|
||||
QVERIFY(result);
|
||||
|
||||
+70
-61
@@ -1304,13 +1304,14 @@ void tst_Model_Connection_Independent::chunk() const
|
||||
using SizeType = ModelsCollection<FilePropertyProperty>::size_type;
|
||||
|
||||
// <page, chunk_modelsCount>
|
||||
const std::unordered_map<int, SizeType> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
const std::unordered_map<qint64, SizeType> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](const SizeType size, const int page)
|
||||
const auto compareResultSize = [&expectedRows]
|
||||
(const SizeType size, const qint64 page)
|
||||
{
|
||||
QCOMPARE(size, expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(size), expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -1319,7 +1320,7 @@ void tst_Model_Connection_Independent::chunk() const
|
||||
auto result = FilePropertyProperty::orderBy(ID)
|
||||
->chunk(3, [&compareResultSize, &ids]
|
||||
(ModelsCollection<FilePropertyProperty> &&models,
|
||||
const int page)
|
||||
const qint64 page)
|
||||
{
|
||||
compareResultSize(models.size(), page);
|
||||
|
||||
@@ -1342,13 +1343,14 @@ void tst_Model_Connection_Independent::chunk_ReturnFalse() const
|
||||
using SizeType = ModelsCollection<FilePropertyProperty>::size_type;
|
||||
|
||||
// <page, chunk_modelsCount> (I leave it here also in this test, doesn't matter much)
|
||||
const std::unordered_map<int, SizeType> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
const std::unordered_map<qint64, SizeType> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](const SizeType size, const int page)
|
||||
const auto compareResultSize = [&expectedRows]
|
||||
(const SizeType size, const qint64 page)
|
||||
{
|
||||
QCOMPARE(size, expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(size), expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -1357,7 +1359,7 @@ void tst_Model_Connection_Independent::chunk_ReturnFalse() const
|
||||
auto result = FilePropertyProperty::orderBy(ID)
|
||||
->chunk(3, [&compareResultSize, &ids]
|
||||
(ModelsCollection<FilePropertyProperty> &&models,
|
||||
const int page)
|
||||
const qint64 page)
|
||||
{
|
||||
compareResultSize(models.size(), page);
|
||||
|
||||
@@ -1389,13 +1391,14 @@ void tst_Model_Connection_Independent::chunk_EnforceOrderBy() const
|
||||
using SizeType = ModelsCollection<FilePropertyProperty>::size_type;
|
||||
|
||||
// <page, chunk_modelsCount>
|
||||
const std::unordered_map<int, SizeType> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
const std::unordered_map<qint64, SizeType> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](const SizeType size, const int page)
|
||||
const auto compareResultSize = [&expectedRows]
|
||||
(const SizeType size, const qint64 page)
|
||||
{
|
||||
QCOMPARE(size, expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(size), expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -1404,7 +1407,7 @@ void tst_Model_Connection_Independent::chunk_EnforceOrderBy() const
|
||||
auto result = FilePropertyProperty::chunk(
|
||||
3, [&compareResultSize, &ids]
|
||||
(ModelsCollection<FilePropertyProperty> &&models,
|
||||
const int page)
|
||||
const qint64 page)
|
||||
{
|
||||
compareResultSize(models.size(), page);
|
||||
|
||||
@@ -1431,7 +1434,7 @@ void tst_Model_Connection_Independent::chunk_EmptyResult() const
|
||||
->orderBy(ID)
|
||||
.chunk(3, [&callbackInvoked]
|
||||
(ModelsCollection<FilePropertyProperty> &&/*unused*/,
|
||||
const int /*unused*/)
|
||||
const qint64 /*unused*/)
|
||||
{
|
||||
callbackInvoked = true;
|
||||
|
||||
@@ -1444,14 +1447,14 @@ void tst_Model_Connection_Independent::chunk_EmptyResult() const
|
||||
|
||||
void tst_Model_Connection_Independent::each() const
|
||||
{
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(8);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(8);
|
||||
|
||||
auto result = FilePropertyProperty::orderBy(ID)
|
||||
->each([&indexes, &ids]
|
||||
(FilePropertyProperty &&model, const int index)
|
||||
(FilePropertyProperty &&model, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(model.getAttribute(ID).template value<quint64>());
|
||||
@@ -1461,7 +1464,7 @@ void tst_Model_Connection_Independent::each() const
|
||||
|
||||
QVERIFY(result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7};
|
||||
std::vector<qint64> expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7};
|
||||
std::vector<quint64> expectedIds {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -1472,13 +1475,14 @@ void tst_Model_Connection_Independent::each() const
|
||||
|
||||
void tst_Model_Connection_Independent::each_ReturnFalse() const
|
||||
{
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(5);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(5);
|
||||
|
||||
auto result = FilePropertyProperty::orderBy(ID)
|
||||
->each([&indexes, &ids](FilePropertyProperty &&model, const int index)
|
||||
->each([&indexes, &ids]
|
||||
(FilePropertyProperty &&model, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(model.getAttribute(ID).template value<quint64>());
|
||||
@@ -1488,7 +1492,7 @@ void tst_Model_Connection_Independent::each_ReturnFalse() const
|
||||
|
||||
QVERIFY(!result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1, 2, 3, 4};
|
||||
std::vector<qint64> expectedIndexes {0, 1, 2, 3, 4};
|
||||
std::vector<quint64> expectedIds {1, 2, 3, 4, 5};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -1502,13 +1506,14 @@ void tst_Model_Connection_Independent::each_EnforceOrderBy() const
|
||||
/* The TinBuilder version doesn't throws exception if the 'order by' clause is not
|
||||
specified, instead it adds a generic 'order by' clause
|
||||
on the Model::getQualifiedKeyName() (it sorts by the primary key by default). */
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(8);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(8);
|
||||
|
||||
auto result = FilePropertyProperty::each(
|
||||
[&indexes, &ids](FilePropertyProperty &&model, const int index)
|
||||
[&indexes, &ids]
|
||||
(FilePropertyProperty &&model, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(model.getAttribute(ID).template value<quint64>());
|
||||
@@ -1518,7 +1523,7 @@ void tst_Model_Connection_Independent::each_EnforceOrderBy() const
|
||||
|
||||
QVERIFY(result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7};
|
||||
std::vector<qint64> expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7};
|
||||
std::vector<quint64> expectedIds {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -1535,7 +1540,7 @@ void tst_Model_Connection_Independent::each_EmptyResult() const
|
||||
QStringLiteral("dummy-NON_EXISTENT"))
|
||||
->orderBy(ID)
|
||||
.each([&callbackInvoked]
|
||||
(FilePropertyProperty &&/*unused*/, const int /*unused*/)
|
||||
(FilePropertyProperty &&/*unused*/, const qint64 /*unused*/)
|
||||
{
|
||||
callbackInvoked = true;
|
||||
|
||||
@@ -1739,13 +1744,14 @@ void tst_Model_Connection_Independent::chunkById() const
|
||||
using SizeType = ModelsCollection<FilePropertyProperty>::size_type;
|
||||
|
||||
// <page, chunk_modelsCount>
|
||||
const std::unordered_map<int, SizeType> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
const std::unordered_map<qint64, SizeType> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](const SizeType size, const int page)
|
||||
const auto compareResultSize = [&expectedRows]
|
||||
(const SizeType size, const qint64 page)
|
||||
{
|
||||
QCOMPARE(size, expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(size), expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -1754,7 +1760,7 @@ void tst_Model_Connection_Independent::chunkById() const
|
||||
auto result = FilePropertyProperty::orderBy(ID)
|
||||
->chunkById(3, [&compareResultSize, &ids]
|
||||
(ModelsCollection<FilePropertyProperty> &&models,
|
||||
const int page)
|
||||
const qint64 page)
|
||||
{
|
||||
compareResultSize(models.size(), page);
|
||||
|
||||
@@ -1777,13 +1783,14 @@ void tst_Model_Connection_Independent::chunkById_ReturnFalse() const
|
||||
using SizeType = ModelsCollection<FilePropertyProperty>::size_type;
|
||||
|
||||
// <page, chunk_modelsCount> (I leave it here also in this test, doesn't matter much
|
||||
const std::unordered_map<int, SizeType> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
const std::unordered_map<qint64, SizeType> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](const SizeType size, const int page)
|
||||
const auto compareResultSize = [&expectedRows]
|
||||
(const SizeType size, const qint64 page)
|
||||
{
|
||||
QCOMPARE(size, expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(size), expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -1792,7 +1799,7 @@ void tst_Model_Connection_Independent::chunkById_ReturnFalse() const
|
||||
auto result = FilePropertyProperty::orderBy(ID)
|
||||
->chunkById(3, [&compareResultSize, &ids]
|
||||
(ModelsCollection<FilePropertyProperty> &&models,
|
||||
const int page)
|
||||
const qint64 page)
|
||||
{
|
||||
compareResultSize(models.size(), page);
|
||||
|
||||
@@ -1825,7 +1832,7 @@ void tst_Model_Connection_Independent::chunkById_EmptyResult() const
|
||||
->orderBy(ID)
|
||||
.chunkById(3, [&callbackInvoked]
|
||||
(ModelsCollection<FilePropertyProperty> &&/*unused*/,
|
||||
const int /*unused*/)
|
||||
const qint64 /*unused*/)
|
||||
{
|
||||
callbackInvoked = true;
|
||||
|
||||
@@ -1841,13 +1848,14 @@ void tst_Model_Connection_Independent::chunkById_WithAlias() const
|
||||
using SizeType = ModelsCollection<FilePropertyProperty>::size_type;
|
||||
|
||||
// <page, chunk_modelsCount>
|
||||
const std::unordered_map<int, SizeType> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
const std::unordered_map<qint64, SizeType> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](const SizeType size, const int page)
|
||||
const auto compareResultSize = [&expectedRows]
|
||||
(const SizeType size, const qint64 page)
|
||||
{
|
||||
QCOMPARE(size, expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(size), expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -1857,7 +1865,7 @@ void tst_Model_Connection_Independent::chunkById_WithAlias() const
|
||||
->orderBy(ID)
|
||||
.chunkById(3, [&compareResultSize, &ids]
|
||||
(ModelsCollection<FilePropertyProperty> &&models,
|
||||
const int page)
|
||||
const qint64 page)
|
||||
{
|
||||
compareResultSize(models.size(), page);
|
||||
|
||||
@@ -1866,7 +1874,7 @@ void tst_Model_Connection_Independent::chunkById_WithAlias() const
|
||||
|
||||
return true;
|
||||
},
|
||||
ID, "id_as");
|
||||
ID, "id_as");
|
||||
|
||||
QVERIFY(result);
|
||||
|
||||
@@ -1881,13 +1889,14 @@ void tst_Model_Connection_Independent::chunkById_ReturnFalse_WithAlias() const
|
||||
using SizeType = ModelsCollection<FilePropertyProperty>::size_type;
|
||||
|
||||
// <page, chunk_modelsCount> (I leave it here also in this test, doesn't matter much
|
||||
const std::unordered_map<int, SizeType> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
const std::unordered_map<qint64, SizeType> expectedRows {{1, 3}, {2, 3}, {3, 2}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](const SizeType size, const int page)
|
||||
const auto compareResultSize = [&expectedRows]
|
||||
(const SizeType size, const qint64 page)
|
||||
{
|
||||
QCOMPARE(size, expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(size), expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -1897,7 +1906,7 @@ void tst_Model_Connection_Independent::chunkById_ReturnFalse_WithAlias() const
|
||||
->orderBy(ID)
|
||||
.chunkById(3, [&compareResultSize, &ids]
|
||||
(ModelsCollection<FilePropertyProperty> &&models,
|
||||
const int page)
|
||||
const qint64 page)
|
||||
{
|
||||
compareResultSize(models.size(), page);
|
||||
|
||||
@@ -1912,7 +1921,7 @@ void tst_Model_Connection_Independent::chunkById_ReturnFalse_WithAlias() const
|
||||
|
||||
return true;
|
||||
},
|
||||
ID, "id_as");
|
||||
ID, "id_as");
|
||||
|
||||
QVERIFY(!result);
|
||||
|
||||
@@ -1931,13 +1940,13 @@ void tst_Model_Connection_Independent::chunkById_EmptyResult_WithAlias() const
|
||||
.orderBy(ID)
|
||||
.chunkById(3, [&callbackInvoked]
|
||||
(ModelsCollection<FilePropertyProperty> &&/*unused*/,
|
||||
const int /*unused*/)
|
||||
const qint64 /*unused*/)
|
||||
{
|
||||
callbackInvoked = true;
|
||||
|
||||
return true;
|
||||
},
|
||||
ID, "id_as");
|
||||
ID, "id_as");
|
||||
|
||||
QVERIFY(!callbackInvoked);
|
||||
QVERIFY(result);
|
||||
@@ -1945,14 +1954,14 @@ void tst_Model_Connection_Independent::chunkById_EmptyResult_WithAlias() const
|
||||
|
||||
void tst_Model_Connection_Independent::eachById() const
|
||||
{
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(8);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(8);
|
||||
|
||||
auto result = FilePropertyProperty::orderBy(ID)
|
||||
->eachById([&indexes, &ids]
|
||||
(FilePropertyProperty &&model, const int index)
|
||||
(FilePropertyProperty &&model, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(model.getAttribute(ID).value<quint64>());
|
||||
@@ -1962,7 +1971,7 @@ void tst_Model_Connection_Independent::eachById() const
|
||||
|
||||
QVERIFY(result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7};
|
||||
std::vector<qint64> expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7};
|
||||
std::vector<quint64> expectedIds {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -1973,14 +1982,14 @@ void tst_Model_Connection_Independent::eachById() const
|
||||
|
||||
void tst_Model_Connection_Independent::eachById_ReturnFalse() const
|
||||
{
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(5);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(5);
|
||||
|
||||
auto result = FilePropertyProperty::orderBy(ID)
|
||||
->eachById([&indexes, &ids]
|
||||
(FilePropertyProperty &&model, const int index)
|
||||
(FilePropertyProperty &&model, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(model.getAttribute(ID).value<quint64>());
|
||||
@@ -1990,7 +1999,7 @@ void tst_Model_Connection_Independent::eachById_ReturnFalse() const
|
||||
|
||||
QVERIFY(!result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1, 2, 3, 4};
|
||||
std::vector<qint64> expectedIndexes {0, 1, 2, 3, 4};
|
||||
std::vector<quint64> expectedIds {1, 2, 3, 4, 5};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -2007,7 +2016,7 @@ void tst_Model_Connection_Independent::eachById_EmptyResult() const
|
||||
QStringLiteral("dummy-NON_EXISTENT"))
|
||||
->orderBy(ID)
|
||||
.eachById([&callbackInvoked]
|
||||
(FilePropertyProperty &&/*unused*/, const int /*unused*/)
|
||||
(FilePropertyProperty &&/*unused*/, const qint64 /*unused*/)
|
||||
{
|
||||
callbackInvoked = true;
|
||||
|
||||
@@ -2020,7 +2029,7 @@ void tst_Model_Connection_Independent::eachById_EmptyResult() const
|
||||
|
||||
void tst_Model_Connection_Independent::eachById_WithAlias() const
|
||||
{
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(8);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(8);
|
||||
@@ -2028,18 +2037,18 @@ void tst_Model_Connection_Independent::eachById_WithAlias() const
|
||||
auto result = FilePropertyProperty::select({ASTERISK, "id as id_as"})
|
||||
->orderBy(ID)
|
||||
.eachById([&indexes, &ids]
|
||||
(FilePropertyProperty &&model, const int index)
|
||||
(FilePropertyProperty &&model, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(model.getAttribute(ID).value<quint64>());
|
||||
|
||||
return true;
|
||||
},
|
||||
1000, ID, "id_as");
|
||||
1000, ID, "id_as");
|
||||
|
||||
QVERIFY(result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7};
|
||||
std::vector<qint64> expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7};
|
||||
std::vector<quint64> expectedIds {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -2050,7 +2059,7 @@ void tst_Model_Connection_Independent::eachById_WithAlias() const
|
||||
|
||||
void tst_Model_Connection_Independent::eachById_ReturnFalse_WithAlias() const
|
||||
{
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(5);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(5);
|
||||
@@ -2058,18 +2067,18 @@ void tst_Model_Connection_Independent::eachById_ReturnFalse_WithAlias() const
|
||||
auto result = FilePropertyProperty::select({ASTERISK, "id as id_as"})
|
||||
->orderBy(ID)
|
||||
.eachById([&indexes, &ids]
|
||||
(FilePropertyProperty &&model, const int index)
|
||||
(FilePropertyProperty &&model, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(model.getAttribute(ID).value<quint64>());
|
||||
|
||||
return index != 4; // false/interrupt on 4
|
||||
},
|
||||
1000, ID, "id_as");
|
||||
1000, ID, "id_as");
|
||||
|
||||
QVERIFY(!result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1, 2, 3, 4};
|
||||
std::vector<qint64> expectedIndexes {0, 1, 2, 3, 4};
|
||||
std::vector<quint64> expectedIds {1, 2, 3, 4, 5};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -2086,13 +2095,13 @@ void tst_Model_Connection_Independent::eachById_EmptyResult_WithAlias() const
|
||||
->whereEq(NAME, QStringLiteral("dummy-NON_EXISTENT"))
|
||||
.orderBy(ID)
|
||||
.eachById([&callbackInvoked]
|
||||
(FilePropertyProperty &&/*unused*/, const int /*unused*/)
|
||||
(FilePropertyProperty &&/*unused*/, const qint64 /*unused*/)
|
||||
{
|
||||
callbackInvoked = true;
|
||||
|
||||
return true;
|
||||
},
|
||||
1000, ID, "id_as");
|
||||
1000, ID, "id_as");
|
||||
|
||||
QVERIFY(!callbackInvoked);
|
||||
QVERIFY(result);
|
||||
|
||||
@@ -2317,13 +2317,14 @@ void tst_Model_Relations::chunk_Relation() const
|
||||
using SizeType = ModelsCollection<FilePropertyProperty>::size_type;
|
||||
|
||||
// <page, chunk_modelsCount>
|
||||
const std::unordered_map<int, SizeType> expectedRows {{1, 2}, {2, 1}};
|
||||
const std::unordered_map<qint64, SizeType> expectedRows {{1, 2}, {2, 1}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](const SizeType size, const int page)
|
||||
const auto compareResultSize = [&expectedRows]
|
||||
(const SizeType size, const qint64 page)
|
||||
{
|
||||
QCOMPARE(size, expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(size), expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -2333,7 +2334,7 @@ void tst_Model_Relations::chunk_Relation() const
|
||||
->orderBy(ID)
|
||||
.chunk(2, [&compareResultSize, &ids]
|
||||
(ModelsCollection<FilePropertyProperty> &&models,
|
||||
const int page)
|
||||
const qint64 page)
|
||||
{
|
||||
compareResultSize(models.size(), page);
|
||||
|
||||
@@ -2357,7 +2358,7 @@ void tst_Model_Relations::each_Relation() const
|
||||
|
||||
ConnectionOverride::connection = connection;
|
||||
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(3);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(3);
|
||||
@@ -2365,7 +2366,7 @@ void tst_Model_Relations::each_Relation() const
|
||||
auto result = TorrentPreviewableFileProperty::find(5)->filePropertyProperty()
|
||||
->orderBy(ID)
|
||||
.each([&indexes, &ids]
|
||||
(FilePropertyProperty &&model, const int index)
|
||||
(FilePropertyProperty &&model, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(model.getAttribute(ID).template value<quint64>());
|
||||
@@ -2375,7 +2376,7 @@ void tst_Model_Relations::each_Relation() const
|
||||
|
||||
QVERIFY(result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1, 2};
|
||||
std::vector<qint64> expectedIndexes {0, 1, 2};
|
||||
std::vector<quint64> expectedIds {6, 7, 8};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -2473,13 +2474,14 @@ void tst_Model_Relations::chunkById_Relation() const
|
||||
using SizeType = ModelsCollection<FilePropertyProperty>::size_type;
|
||||
|
||||
// <page, chunk_modelsCount>
|
||||
const std::unordered_map<int, SizeType> expectedRows {{1, 2}, {2, 1}};
|
||||
const std::unordered_map<qint64, SizeType> expectedRows {{1, 2}, {2, 1}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](const SizeType size, const int page)
|
||||
const auto compareResultSize = [&expectedRows]
|
||||
(const SizeType size, const qint64 page)
|
||||
{
|
||||
QCOMPARE(size, expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(size), expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -2489,7 +2491,7 @@ void tst_Model_Relations::chunkById_Relation() const
|
||||
->orderBy(ID)
|
||||
.chunkById(2, [&compareResultSize, &ids]
|
||||
(ModelsCollection<FilePropertyProperty> &&models,
|
||||
const int page)
|
||||
const qint64 page)
|
||||
{
|
||||
compareResultSize(models.size(), page);
|
||||
|
||||
@@ -2516,13 +2518,14 @@ void tst_Model_Relations::chunkById_WithAlias_Relation() const
|
||||
using SizeType = ModelsCollection<FilePropertyProperty>::size_type;
|
||||
|
||||
// <page, chunk_modelsCount>
|
||||
const std::unordered_map<int, SizeType> expectedRows {{1, 2}, {2, 1}};
|
||||
const std::unordered_map<qint64, SizeType> expectedRows {{1, 2}, {2, 1}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](const SizeType size, const int page)
|
||||
const auto compareResultSize = [&expectedRows]
|
||||
(const SizeType size, const qint64 page)
|
||||
{
|
||||
QCOMPARE(size, expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(size), expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -2533,7 +2536,7 @@ void tst_Model_Relations::chunkById_WithAlias_Relation() const
|
||||
.orderBy(ID)
|
||||
.chunkById(2, [&compareResultSize, &ids]
|
||||
(ModelsCollection<FilePropertyProperty> &&models,
|
||||
const int page)
|
||||
const qint64 page)
|
||||
{
|
||||
compareResultSize(models.size(), page);
|
||||
|
||||
@@ -2558,7 +2561,7 @@ void tst_Model_Relations::eachById_Relation() const
|
||||
|
||||
ConnectionOverride::connection = connection;
|
||||
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(3);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(3);
|
||||
@@ -2566,7 +2569,7 @@ void tst_Model_Relations::eachById_Relation() const
|
||||
auto result = TorrentPreviewableFileProperty::find(5)->filePropertyProperty()
|
||||
->orderBy(ID)
|
||||
.eachById([&indexes, &ids]
|
||||
(FilePropertyProperty &&model, const int index)
|
||||
(FilePropertyProperty &&model, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(model.getAttribute(ID).value<quint64>());
|
||||
@@ -2576,7 +2579,7 @@ void tst_Model_Relations::eachById_Relation() const
|
||||
|
||||
QVERIFY(result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1, 2};
|
||||
std::vector<qint64> expectedIndexes {0, 1, 2};
|
||||
std::vector<quint64> expectedIds {6, 7, 8};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -2591,7 +2594,7 @@ void tst_Model_Relations::eachById_WithAlias_Relation() const
|
||||
|
||||
ConnectionOverride::connection = connection;
|
||||
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(3);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(3);
|
||||
@@ -2600,7 +2603,7 @@ void tst_Model_Relations::eachById_WithAlias_Relation() const
|
||||
->select({ASTERISK, "id as id_as"})
|
||||
.orderBy(ID)
|
||||
.eachById([&indexes, &ids]
|
||||
(FilePropertyProperty &&model, const int index)
|
||||
(FilePropertyProperty &&model, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(model.getAttribute(ID).value<quint64>());
|
||||
@@ -2611,7 +2614,7 @@ void tst_Model_Relations::eachById_WithAlias_Relation() const
|
||||
|
||||
QVERIFY(result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1, 2};
|
||||
std::vector<qint64> expectedIndexes {0, 1, 2};
|
||||
std::vector<quint64> expectedIds {6, 7, 8};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -2867,13 +2870,14 @@ void tst_Model_Relations::chunk() const
|
||||
using SizeType = ModelsCollection<Tag>::size_type;
|
||||
|
||||
// <page, chunk_modelsCount>
|
||||
const std::unordered_map<int, SizeType> expectedRows {{1, 2}, {2, 2}};
|
||||
const std::unordered_map<qint64, SizeType> expectedRows {{1, 2}, {2, 2}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](const SizeType size, const int page)
|
||||
const auto compareResultSize = [&expectedRows]
|
||||
(const SizeType size, const qint64 page)
|
||||
{
|
||||
QCOMPARE(size, expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(size), expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -2881,7 +2885,7 @@ void tst_Model_Relations::chunk() const
|
||||
|
||||
auto result = Torrent::find(2)->tags()->orderBy(ID)
|
||||
.chunk(2, [&compareResultSize, &ids]
|
||||
(ModelsCollection<Tag> &&models, const int page)
|
||||
(ModelsCollection<Tag> &&models, const qint64 page)
|
||||
{
|
||||
compareResultSize(models.size(), page);
|
||||
|
||||
@@ -2911,13 +2915,14 @@ void tst_Model_Relations::chunk_ReturnFalse() const
|
||||
using SizeType = ModelsCollection<Tag>::size_type;
|
||||
|
||||
// <page, chunk_modelsCount> (I leave it here also in this test, doesn't matter much)
|
||||
const std::unordered_map<int, SizeType> expectedRows {{1, 2}, {2, 2}};
|
||||
const std::unordered_map<qint64, SizeType> expectedRows {{1, 2}, {2, 2}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](const SizeType size, const int page)
|
||||
const auto compareResultSize = [&expectedRows]
|
||||
(const SizeType size, const qint64 page)
|
||||
{
|
||||
QCOMPARE(size, expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(size), expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -2925,7 +2930,7 @@ void tst_Model_Relations::chunk_ReturnFalse() const
|
||||
|
||||
auto result = Torrent::find(2)->tags()->orderBy(ID)
|
||||
.chunk(2, [&compareResultSize, &ids]
|
||||
(ModelsCollection<Tag> &&models, const int page)
|
||||
(ModelsCollection<Tag> &&models, const qint64 page)
|
||||
{
|
||||
compareResultSize(models.size(), page);
|
||||
|
||||
@@ -2963,13 +2968,14 @@ void tst_Model_Relations::chunk_EnforceOrderBy() const
|
||||
using SizeType = ModelsCollection<Tag>::size_type;
|
||||
|
||||
// <page, chunk_modelsCount>
|
||||
const std::unordered_map<int, SizeType> expectedRows {{1, 2}, {2, 2}};
|
||||
const std::unordered_map<qint64, SizeType> expectedRows {{1, 2}, {2, 2}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](const SizeType size, const int page)
|
||||
const auto compareResultSize = [&expectedRows]
|
||||
(const SizeType size, const qint64 page)
|
||||
{
|
||||
QCOMPARE(size, expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(size), expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -2977,7 +2983,7 @@ void tst_Model_Relations::chunk_EnforceOrderBy() const
|
||||
|
||||
auto result = Torrent::find(2)->tags()
|
||||
->chunk(2, [&compareResultSize, &ids]
|
||||
(ModelsCollection<Tag> &&models, const int page)
|
||||
(ModelsCollection<Tag> &&models, const qint64 page)
|
||||
{
|
||||
compareResultSize(models.size(), page);
|
||||
|
||||
@@ -3010,7 +3016,7 @@ void tst_Model_Relations::chunk_EmptyResult() const
|
||||
QStringLiteral("dummy-NON_EXISTENT"))
|
||||
.orderBy(ID)
|
||||
.chunk(2, [&callbackInvoked]
|
||||
(ModelsCollection<Tag> &&/*unused*/, const int /*unused*/)
|
||||
(ModelsCollection<Tag> &&/*unused*/, const qint64 /*unused*/)
|
||||
{
|
||||
callbackInvoked = true;
|
||||
|
||||
@@ -3027,14 +3033,14 @@ void tst_Model_Relations::each() const
|
||||
|
||||
ConnectionOverride::connection = connection;
|
||||
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(4);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(4);
|
||||
|
||||
auto result = Torrent::find(2)->tags()->orderBy(ID)
|
||||
.each([&indexes, &ids]
|
||||
(Tag &&model, const int index)
|
||||
(Tag &&model, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(model.getAttribute(ID).template value<quint64>());
|
||||
@@ -3046,7 +3052,7 @@ void tst_Model_Relations::each() const
|
||||
|
||||
QVERIFY(result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1, 2, 3};
|
||||
std::vector<qint64> expectedIndexes {0, 1, 2, 3};
|
||||
std::vector<quint64> expectedIds {1, 2, 3, 4};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -3061,14 +3067,14 @@ void tst_Model_Relations::each_ReturnFalse() const
|
||||
|
||||
ConnectionOverride::connection = connection;
|
||||
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(2);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(2);
|
||||
|
||||
auto result = Torrent::find(2)->tags()->orderBy(ID)
|
||||
.each([&indexes, &ids]
|
||||
(Tag &&model, const int index)
|
||||
(Tag &&model, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(model.getAttribute(ID).template value<quint64>());
|
||||
@@ -3080,7 +3086,7 @@ void tst_Model_Relations::each_ReturnFalse() const
|
||||
|
||||
QVERIFY(!result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1};
|
||||
std::vector<qint64> expectedIndexes {0, 1};
|
||||
std::vector<quint64> expectedIds {1, 2};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -3098,14 +3104,14 @@ void tst_Model_Relations::each_EnforceOrderBy() const
|
||||
/* The TinBuilder version doesn't throws exception if the 'order by' clause is not
|
||||
specified, instead it adds a generic 'order by' clause
|
||||
on the Model::getQualifiedKeyName() (it sorts by the primary key by default). */
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(4);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(4);
|
||||
|
||||
auto result = Torrent::find(2)->tags()
|
||||
->each([&indexes, &ids]
|
||||
(Tag &&model, const int index)
|
||||
(Tag &&model, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(model.getAttribute(ID).template value<quint64>());
|
||||
@@ -3117,7 +3123,7 @@ void tst_Model_Relations::each_EnforceOrderBy() const
|
||||
|
||||
QVERIFY(result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1, 2, 3};
|
||||
std::vector<qint64> expectedIndexes {0, 1, 2, 3};
|
||||
std::vector<quint64> expectedIds {1, 2, 3, 4};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -3138,7 +3144,7 @@ void tst_Model_Relations::each_EmptyResult() const
|
||||
QStringLiteral("dummy-NON_EXISTENT"))
|
||||
.orderBy(ID)
|
||||
.each([&callbackInvoked]
|
||||
(Tag &&/*unused*/, const int /*unused*/)
|
||||
(Tag &&/*unused*/, const qint64 /*unused*/)
|
||||
{
|
||||
callbackInvoked = true;
|
||||
|
||||
@@ -3378,13 +3384,14 @@ void tst_Model_Relations::chunkById() const
|
||||
using SizeType = ModelsCollection<Tag>::size_type;
|
||||
|
||||
// <page, chunk_modelsCount>
|
||||
const std::unordered_map<int, SizeType> expectedRows {{1, 2}, {2, 2}};
|
||||
const std::unordered_map<qint64, SizeType> expectedRows {{1, 2}, {2, 2}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](const SizeType size, const int page)
|
||||
const auto compareResultSize = [&expectedRows]
|
||||
(const SizeType size, const qint64 page)
|
||||
{
|
||||
QCOMPARE(size, expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(size), expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -3392,7 +3399,7 @@ void tst_Model_Relations::chunkById() const
|
||||
|
||||
auto result = Torrent::find(2)->tags()->orderBy(ID)
|
||||
.chunkById(2, [&compareResultSize, &ids]
|
||||
(ModelsCollection<Tag> &&models, const int page)
|
||||
(ModelsCollection<Tag> &&models, const qint64 page)
|
||||
{
|
||||
compareResultSize(models.size(), page);
|
||||
|
||||
@@ -3422,13 +3429,14 @@ void tst_Model_Relations::chunkById_ReturnFalse() const
|
||||
using SizeType = ModelsCollection<Tag>::size_type;
|
||||
|
||||
// <page, chunk_modelsCount> (I leave it here also in this test, doesn't matter much
|
||||
const std::unordered_map<int, SizeType> expectedRows {{1, 2}, {2, 2}};
|
||||
const std::unordered_map<qint64, SizeType> expectedRows {{1, 2}, {2, 2}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](const SizeType size, const int page)
|
||||
const auto compareResultSize = [&expectedRows]
|
||||
(const SizeType size, const qint64 page)
|
||||
{
|
||||
QCOMPARE(size, expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(size), expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -3436,7 +3444,7 @@ void tst_Model_Relations::chunkById_ReturnFalse() const
|
||||
|
||||
auto result = Torrent::find(2)->tags()->orderBy(ID)
|
||||
.chunkById(2, [&compareResultSize, &ids]
|
||||
(ModelsCollection<Tag> &&models, const int page)
|
||||
(ModelsCollection<Tag> &&models, const qint64 page)
|
||||
{
|
||||
compareResultSize(models.size(), page);
|
||||
|
||||
@@ -3475,7 +3483,7 @@ void tst_Model_Relations::chunkById_EmptyResult() const
|
||||
.orderBy(ID)
|
||||
.chunkById(2, [&callbackInvoked]
|
||||
(ModelsCollection<Tag> &&/*unused*/,
|
||||
const int /*unused*/)
|
||||
const qint64 /*unused*/)
|
||||
{
|
||||
callbackInvoked = true;
|
||||
|
||||
@@ -3495,13 +3503,14 @@ void tst_Model_Relations::chunkById_WithAlias() const
|
||||
using SizeType = ModelsCollection<Tag>::size_type;
|
||||
|
||||
// <page, chunk_modelsCount>
|
||||
const std::unordered_map<int, SizeType> expectedRows {{1, 2}, {2, 2}};
|
||||
const std::unordered_map<qint64, SizeType> expectedRows {{1, 2}, {2, 2}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](const SizeType size, const int page)
|
||||
const auto compareResultSize = [&expectedRows]
|
||||
(const SizeType size, const qint64 page)
|
||||
{
|
||||
QCOMPARE(size, expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(size), expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -3511,7 +3520,7 @@ void tst_Model_Relations::chunkById_WithAlias() const
|
||||
->select({ASTERISK, "torrent_tags.id as id_as"})
|
||||
.orderBy(ID)
|
||||
.chunkById(2, [&compareResultSize, &ids]
|
||||
(ModelsCollection<Tag> &&models, const int page)
|
||||
(ModelsCollection<Tag> &&models, const qint64 page)
|
||||
{
|
||||
compareResultSize(models.size(), page);
|
||||
|
||||
@@ -3523,7 +3532,7 @@ void tst_Model_Relations::chunkById_WithAlias() const
|
||||
|
||||
return true;
|
||||
},
|
||||
ID, "id_as");
|
||||
ID, "id_as");
|
||||
|
||||
QVERIFY(result);
|
||||
|
||||
@@ -3542,13 +3551,14 @@ void tst_Model_Relations::chunkById_ReturnFalse_WithAlias() const
|
||||
using SizeType = ModelsCollection<Tag>::size_type;
|
||||
|
||||
// <page, chunk_modelsCount> (I leave it here also in this test, doesn't matter much
|
||||
const std::unordered_map<int, SizeType> expectedRows {{1, 2}, {2, 2}};
|
||||
const std::unordered_map<qint64, SizeType> expectedRows {{1, 2}, {2, 2}};
|
||||
|
||||
/* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;'
|
||||
and it causes compile error. */
|
||||
const auto compareResultSize = [&expectedRows](const SizeType size, const int page)
|
||||
const auto compareResultSize = [&expectedRows]
|
||||
(const SizeType size, const qint64 page)
|
||||
{
|
||||
QCOMPARE(size, expectedRows.at(page));
|
||||
QCOMPARE(static_cast<qint64>(size), expectedRows.at(page));
|
||||
};
|
||||
|
||||
std::vector<quint64> ids;
|
||||
@@ -3558,7 +3568,7 @@ void tst_Model_Relations::chunkById_ReturnFalse_WithAlias() const
|
||||
->select({ASTERISK, "torrent_tags.id as id_as"})
|
||||
.orderBy(ID)
|
||||
.chunkById(2, [&compareResultSize, &ids]
|
||||
(ModelsCollection<Tag> &&models, const int page)
|
||||
(ModelsCollection<Tag> &&models, const qint64 page)
|
||||
{
|
||||
compareResultSize(models.size(), page);
|
||||
|
||||
@@ -3575,7 +3585,7 @@ void tst_Model_Relations::chunkById_ReturnFalse_WithAlias() const
|
||||
|
||||
return true;
|
||||
},
|
||||
ID, "id_as");
|
||||
ID, "id_as");
|
||||
|
||||
QVERIFY(!result);
|
||||
|
||||
@@ -3599,13 +3609,13 @@ void tst_Model_Relations::chunkById_EmptyResult_WithAlias() const
|
||||
.orderBy(ID)
|
||||
.chunkById(2, [&callbackInvoked]
|
||||
(ModelsCollection<Tag> &&/*unused*/,
|
||||
const int /*unused*/)
|
||||
const qint64 /*unused*/)
|
||||
{
|
||||
callbackInvoked = true;
|
||||
|
||||
return true;
|
||||
},
|
||||
ID, "id_as");
|
||||
ID, "id_as");
|
||||
|
||||
QVERIFY(!callbackInvoked);
|
||||
QVERIFY(result);
|
||||
@@ -3617,7 +3627,7 @@ void tst_Model_Relations::eachById() const
|
||||
|
||||
ConnectionOverride::connection = connection;
|
||||
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(4);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(4);
|
||||
@@ -3625,7 +3635,7 @@ void tst_Model_Relations::eachById() const
|
||||
auto result = Torrent::find(2)->tags()
|
||||
->orderBy(ID)
|
||||
.eachById([&indexes, &ids]
|
||||
(Tag &&model, const int index)
|
||||
(Tag &&model, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(model.getAttribute(ID).value<quint64>());
|
||||
@@ -3637,7 +3647,7 @@ void tst_Model_Relations::eachById() const
|
||||
|
||||
QVERIFY(result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1, 2, 3};
|
||||
std::vector<qint64> expectedIndexes {0, 1, 2, 3};
|
||||
std::vector<quint64> expectedIds {1, 2, 3, 4};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -3652,7 +3662,7 @@ void tst_Model_Relations::eachById_ReturnFalse() const
|
||||
|
||||
ConnectionOverride::connection = connection;
|
||||
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(2);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(2);
|
||||
@@ -3660,7 +3670,7 @@ void tst_Model_Relations::eachById_ReturnFalse() const
|
||||
auto result = Torrent::find(2)->tags()
|
||||
->orderBy(ID)
|
||||
.eachById([&indexes, &ids]
|
||||
(Tag &&model, const int index)
|
||||
(Tag &&model, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(model.getAttribute(ID).value<quint64>());
|
||||
@@ -3672,7 +3682,7 @@ void tst_Model_Relations::eachById_ReturnFalse() const
|
||||
|
||||
QVERIFY(!result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1};
|
||||
std::vector<qint64> expectedIndexes {0, 1};
|
||||
std::vector<quint64> expectedIds {1, 2};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -3693,7 +3703,7 @@ void tst_Model_Relations::eachById_EmptyResult() const
|
||||
QStringLiteral("dummy-NON_EXISTENT"))
|
||||
.orderBy(ID)
|
||||
.eachById([&callbackInvoked]
|
||||
(Tag &&/*unused*/, const int /*unused*/)
|
||||
(Tag &&/*unused*/, const qint64 /*unused*/)
|
||||
{
|
||||
callbackInvoked = true;
|
||||
|
||||
@@ -3710,7 +3720,7 @@ void tst_Model_Relations::eachById_WithAlias() const
|
||||
|
||||
ConnectionOverride::connection = connection;
|
||||
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(4);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(4);
|
||||
@@ -3719,7 +3729,7 @@ void tst_Model_Relations::eachById_WithAlias() const
|
||||
->select({ASTERISK, "torrent_tags.id as id_as"})
|
||||
.orderBy(ID)
|
||||
.eachById([&indexes, &ids]
|
||||
(Tag &&model, const int index)
|
||||
(Tag &&model, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(model.getAttribute(ID).value<quint64>());
|
||||
@@ -3728,11 +3738,11 @@ void tst_Model_Relations::eachById_WithAlias() const
|
||||
|
||||
return true;
|
||||
},
|
||||
1000, ID, "id_as");
|
||||
1000, ID, "id_as");
|
||||
|
||||
QVERIFY(result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1, 2, 3};
|
||||
std::vector<qint64> expectedIndexes {0, 1, 2, 3};
|
||||
std::vector<quint64> expectedIds {1, 2, 3, 4};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -3747,7 +3757,7 @@ void tst_Model_Relations::eachById_ReturnFalse_WithAlias() const
|
||||
|
||||
ConnectionOverride::connection = connection;
|
||||
|
||||
std::vector<int> indexes;
|
||||
std::vector<qint64> indexes;
|
||||
indexes.reserve(2);
|
||||
std::vector<quint64> ids;
|
||||
ids.reserve(2);
|
||||
@@ -3756,7 +3766,7 @@ void tst_Model_Relations::eachById_ReturnFalse_WithAlias() const
|
||||
->select({ASTERISK, "torrent_tags.id as id_as"})
|
||||
.orderBy(ID)
|
||||
.eachById([&indexes, &ids]
|
||||
(Tag &&model, const int index)
|
||||
(Tag &&model, const qint64 index)
|
||||
{
|
||||
indexes.emplace_back(index);
|
||||
ids.emplace_back(model.getAttribute(ID).value<quint64>());
|
||||
@@ -3765,11 +3775,11 @@ void tst_Model_Relations::eachById_ReturnFalse_WithAlias() const
|
||||
|
||||
return index != 1; // false/interrupt on 1
|
||||
},
|
||||
1000, ID, "id_as");
|
||||
1000, ID, "id_as");
|
||||
|
||||
QVERIFY(!result);
|
||||
|
||||
std::vector<int> expectedIndexes {0, 1};
|
||||
std::vector<qint64> expectedIndexes {0, 1};
|
||||
std::vector<quint64> expectedIds {1, 2};
|
||||
|
||||
QVERIFY(indexes.size() == expectedIndexes.size());
|
||||
@@ -3791,13 +3801,13 @@ void tst_Model_Relations::eachById_EmptyResult_WithAlias() const
|
||||
.whereEq("torrent_tags.name", QStringLiteral("dummy-NON_EXISTENT"))
|
||||
.orderBy(ID)
|
||||
.eachById([&callbackInvoked]
|
||||
(Tag &&/*unused*/, const int /*unused*/)
|
||||
(Tag &&/*unused*/, const qint64 /*unused*/)
|
||||
{
|
||||
callbackInvoked = true;
|
||||
|
||||
return true;
|
||||
},
|
||||
1000, ID, "id_as");
|
||||
1000, ID, "id_as");
|
||||
|
||||
QVERIFY(!callbackInvoked);
|
||||
QVERIFY(result);
|
||||
|
||||
@@ -58,7 +58,7 @@ std::vector<MigrationItem> MigrationRepository::getMigrations(const int steps) c
|
||||
auto query = table()->where(batch_, GE, 1)
|
||||
.orderBy(batch_, DESC)
|
||||
.orderBy(migration_, DESC)
|
||||
.take(steps)
|
||||
.take(static_cast<qint64>(steps))
|
||||
.get();
|
||||
|
||||
return hydrateMigrations(query);
|
||||
|
||||
Reference in New Issue
Block a user