mirror of
https://github.com/silverqx/TinyORM.git
synced 2026-02-05 09:50:19 -06:00
passed clang-tidy portability-*, readability-*
Enhanced .clang-tidy files. - -readability-function-cognitive-complexity for all tests
This commit is contained in:
15
.clang-tidy
15
.clang-tidy
@@ -1,6 +1,11 @@
|
||||
---
|
||||
Checks: '-*,bugprone-*,clang-*,concurrency-*,cppcoreguidelines-init-variables,cppcoreguidelines-pro-type-member-init,cppcoreguidelines-slicing,google-build-*,google-explicit-constructor,google-global-names-in-headers,google-objc-*,google-readability-avoid-underscore-in-googletest-name,google-readability-casting,google-readability-function-size,google-readability-namespace-comments,google-runtime-*,google-upgrade-googletest-case,llvm-else-after-return,llvm-include-order,llvm-namespace-comment,llvm-prefer-*,llvm-qualified-auto,llvm-twine-local,misc-definitions-in-headers,misc-misplaced-const,misc-new-delete-overloads,misc-no-recursion,misc-non-copyable-objects,misc-redundant-expression,misc-static-assert,misc-throw-by-value-catch-by-reference,misc-unconventional-assign-operator,misc-uniqueptr-reset-release,misc-unused-*,modernize-avoid-*,modernize-concat-nested-namespaces,modernize-deprecated-*,modernize-loop-convert,modernize-make-*,modernize-pass-by-value,modernize-raw-string-literal,modernize-redundant-void-arg,modernize-replace-*,modernize-return-braced-init-list,modernize-shrink-to-fit,modernize-unary-static-assert,modernize-use-auto,modernize-use-bool-literals,modernize-use-default-member-init,modernize-use-emplace,modernize-use-equals-*,modernize-use-noexcept,modernize-use-nullptr,modernize-use-override,modernize-use-transparent-functors,modernize-use-uncaught-exceptions,modernize-use-using,performance-faster-string-find,performance-for-range-copy,performance-implicit-conversion-in-loop,performance-inefficient-*,performance-move-constructor-init,performance-no-*,performance-noexcept-move-constructor,performance-trivially-destructible,performance-type-promotion-in-math-fn,performance-unnecessary-*,portability-*'
|
||||
WarningsAsErrors: ''
|
||||
HeaderFilterRegex: ''
|
||||
FormatStyle: none
|
||||
CheckOptions: []
|
||||
Checks: '-*,bugprone-*,clang-*,concurrency-*,google-*,llvm-*,misc-*,modernize-*,performance-*,portability-*,readability-*,-bugprone-easily-swappable-parameters,cppcoreguidelines-init-variables,cppcoreguidelines-pro-type-member-init,cppcoreguidelines-slicing,-google-default-arguments,-google-readability-braces-around-statements,-google-readability-todo,-llvm-header-guard,-misc-non-private-member-variables-in-classes,-modernize-use-nodiscard,-modernize-use-trailing-return-type,-performance-move-const-arg,-readability-braces-around-statements,-readability-convert-member-functions-to-static,-readability-magic-numbers'
|
||||
WarningsAsErrors: ''
|
||||
HeaderFilterRegex: ''
|
||||
FormatStyle: none
|
||||
InheritParentConfig: false
|
||||
CheckOptions:
|
||||
- key: google-readability-namespace-comments.ShortNamespaceLines
|
||||
value: '5'
|
||||
- key: llvm-namespace-comment.ShortNamespaceLines
|
||||
value: '5'
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -33,6 +33,7 @@ Thumbs.db
|
||||
!/resources/*.rc
|
||||
/.qmake.cache
|
||||
/.qmake.stash
|
||||
*.tmp
|
||||
|
||||
# qtcreator generated files
|
||||
*.pro.user*
|
||||
|
||||
@@ -211,17 +211,16 @@ namespace Orm
|
||||
|
||||
/* Logging */
|
||||
/*! Log a query into the connection's query log. */
|
||||
void logQuery(const QSqlQuery &query,
|
||||
const std::optional<qint64> elapsed) const;
|
||||
void logQuery(const QSqlQuery &query, std::optional<qint64> elapsed) const;
|
||||
/*! Log a query into the connection's query log. */
|
||||
void logQuery(const std::tuple<int, QSqlQuery> &queryResult,
|
||||
const std::optional<qint64> elapsed) const;
|
||||
std::optional<qint64> elapsed) const;
|
||||
/*! Log a query into the connection's query log in the pretending mode. */
|
||||
void logQueryForPretend(const QString &query,
|
||||
const QVector<QVariant> &bindings) const;
|
||||
/*! Log a transaction query into the connection's query log. */
|
||||
void logTransactionQuery(const QString &query,
|
||||
const std::optional<qint64> elapsed) const;
|
||||
std::optional<qint64> elapsed) const;
|
||||
/*! Log a transaction query into the connection's query log
|
||||
in the pretending mode. */
|
||||
void logTransactionQueryForPretend(const QString &query) const;
|
||||
@@ -367,7 +366,7 @@ namespace Orm
|
||||
|
||||
/*! Count transactional queries execution time and statements counter. */
|
||||
std::optional<qint64>
|
||||
hitTransactionalCounters(const QElapsedTimer timer, bool countElapsed);
|
||||
hitTransactionalCounters(QElapsedTimer timer, bool countElapsed);
|
||||
/*! Convert a named bindings map to the positional bindings vector. */
|
||||
QVector<QVariant>
|
||||
convertNamedToPositionalBindings(QVariantMap &&bindings) const;
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace Orm
|
||||
static void disconnect(const QString &name = "");
|
||||
|
||||
/*! Get all of the support drivers. */
|
||||
static const QStringList supportedDrivers();
|
||||
static QStringList supportedDrivers();
|
||||
/*! Returns a list containing the names of all connections. */
|
||||
static QStringList connectionNames();
|
||||
/*! Returns a list containing the names of opened connections. */
|
||||
|
||||
@@ -209,7 +209,7 @@ namespace Orm::Query::Grammars
|
||||
|
||||
inline QString Grammar::compileInsertGetId(
|
||||
const QueryBuilder &query, const QVector<QVariantMap> &values,
|
||||
const QString &) const
|
||||
const QString &/*unused*/) const
|
||||
{
|
||||
return compileInsert(query, values);
|
||||
}
|
||||
|
||||
@@ -102,24 +102,24 @@ namespace Query
|
||||
|
||||
/* Select */
|
||||
/*! Retrieve the "count" result of the query. */
|
||||
quint64 count(const QVector<Column> &columns = {ASTERISK});
|
||||
quint64 count(const QVector<Column> &columns = {ASTERISK}) const;
|
||||
/*! Retrieve the "count" result of the query. */
|
||||
template<typename = void>
|
||||
quint64 count(const Column &column);
|
||||
/*! Retrieve the minimum value of a given column. */
|
||||
QVariant min(const Column &column);
|
||||
QVariant min(const Column &column) const;
|
||||
/*! Retrieve the maximum value of a given column. */
|
||||
QVariant max(const Column &column);
|
||||
QVariant max(const Column &column) const;
|
||||
/*! Retrieve the sum of the values of a given column. */
|
||||
QVariant sum(const Column &column);
|
||||
QVariant sum(const Column &column) const;
|
||||
/*! Retrieve the average of the values of a given column. */
|
||||
QVariant avg(const Column &column);
|
||||
QVariant avg(const Column &column) const;
|
||||
/*! Alias for the "avg" method. */
|
||||
QVariant average(const Column &column);
|
||||
QVariant average(const Column &column) const;
|
||||
|
||||
/*! Execute an aggregate function on the database. */
|
||||
QVariant aggregate(const QString &function,
|
||||
const QVector<Column> &columns = {ASTERISK});
|
||||
const QVector<Column> &columns = {ASTERISK}) const;
|
||||
|
||||
/*! Set the columns to be selected. */
|
||||
Builder &select(const QVector<Column> &columns = {ASTERISK});
|
||||
@@ -653,25 +653,25 @@ namespace Query
|
||||
/*! Indicates if the query returns distinct results. */
|
||||
std::variant<bool, QStringList> m_distinct = false;
|
||||
/*! The columns that should be returned. */
|
||||
QVector<Column> m_columns;
|
||||
QVector<Column> m_columns = {};
|
||||
/*! The table which the query is targeting. */
|
||||
FromClause m_from;
|
||||
FromClause m_from = {};
|
||||
/*! The table joins for the query. */
|
||||
QVector<QSharedPointer<JoinClause>> m_joins;
|
||||
QVector<QSharedPointer<JoinClause>> m_joins = {};
|
||||
/*! The where constraints for the query. */
|
||||
QVector<WhereConditionItem> m_wheres;
|
||||
QVector<WhereConditionItem> m_wheres = {};
|
||||
/*! The groupings for the query. */
|
||||
QVector<Column> m_groups;
|
||||
QVector<Column> m_groups = {};
|
||||
/*! The having constraints for the query. */
|
||||
QVector<HavingConditionItem> m_havings;
|
||||
QVector<HavingConditionItem> m_havings = {};
|
||||
/*! The orderings for the query. */
|
||||
QVector<OrderByItem> m_orders;
|
||||
QVector<OrderByItem> m_orders = {};
|
||||
/*! The maximum number of records to return. */
|
||||
int m_limit = -1;
|
||||
/*! The number of records to skip. */
|
||||
int m_offset = -1;
|
||||
/*! Indicates whether row locking is being used. */
|
||||
std::variant<std::monostate, bool, QString> m_lock;
|
||||
std::variant<std::monostate, bool, QString> m_lock = {};
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@@ -705,7 +705,7 @@ namespace Query
|
||||
return result;
|
||||
}
|
||||
|
||||
inline quint64 Builder::count(const QVector<Column> &columns)
|
||||
inline quint64 Builder::count(const QVector<Column> &columns) const
|
||||
{
|
||||
return aggregate(QStringLiteral("count"), columns).template value<quint64>();
|
||||
}
|
||||
@@ -716,17 +716,17 @@ namespace Query
|
||||
return aggregate(QStringLiteral("count"), {column}).template value<quint64>();
|
||||
}
|
||||
|
||||
inline QVariant Builder::min(const Column &column)
|
||||
inline QVariant Builder::min(const Column &column) const
|
||||
{
|
||||
return aggregate(QStringLiteral("min"), {column});
|
||||
}
|
||||
|
||||
inline QVariant Builder::max(const Column &column)
|
||||
inline QVariant Builder::max(const Column &column) const
|
||||
{
|
||||
return aggregate(QStringLiteral("max"), {column});
|
||||
}
|
||||
|
||||
inline QVariant Builder::sum(const Column &column)
|
||||
inline QVariant Builder::sum(const Column &column) const
|
||||
{
|
||||
auto result = aggregate(QStringLiteral("sum"), {column});
|
||||
|
||||
@@ -736,12 +736,12 @@ namespace Query
|
||||
return result;
|
||||
}
|
||||
|
||||
inline QVariant Builder::avg(const Column &column)
|
||||
inline QVariant Builder::avg(const Column &column) const
|
||||
{
|
||||
return aggregate(QStringLiteral("avg"), {column});
|
||||
}
|
||||
|
||||
inline QVariant Builder::average(const Column &column)
|
||||
inline QVariant Builder::average(const Column &column) const
|
||||
{
|
||||
return avg(column);
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace Concerns
|
||||
protected:
|
||||
/*! Constructor. */
|
||||
BaseRelationStore(HasRelationStore &hasRelationStore,
|
||||
const RelationStoreType storeType);
|
||||
RelationStoreType storeType);
|
||||
|
||||
public:
|
||||
/*! Virtual destructor. */
|
||||
@@ -91,7 +91,7 @@ namespace Concerns
|
||||
method, an enter point of the visitation. */
|
||||
template<typename Method>
|
||||
requires std::is_member_function_pointer_v<Method>
|
||||
void operator()(const Method method);
|
||||
void operator()(Method method);
|
||||
|
||||
protected:
|
||||
/*! Currently held store type. */
|
||||
@@ -119,7 +119,7 @@ namespace Concerns
|
||||
|
||||
/*! Method called after visitation. */
|
||||
template<typename Method>
|
||||
void visited(const Method method) const;
|
||||
void visited(Method method) const;
|
||||
|
||||
private:
|
||||
/*! The Tiny builder instance to which the visited relation will be
|
||||
@@ -145,7 +145,7 @@ namespace Concerns
|
||||
|
||||
/*! Method called after visitation. */
|
||||
template<typename Method>
|
||||
void visited(const Method) const;
|
||||
void visited(Method /*unused*/) const;
|
||||
|
||||
/*! Models to push, the reference to the relation in m_relations hash. */
|
||||
RelationsType<AllRelations...> &m_models;
|
||||
@@ -165,7 +165,7 @@ namespace Concerns
|
||||
|
||||
/*! Method called after visitation. */
|
||||
template<typename Method>
|
||||
void visited(const Method method) const;
|
||||
void visited(Method method) const;
|
||||
|
||||
/*! Models to touch timestamps for, the reference to the relation name/key
|
||||
in the m_relations hash. */
|
||||
@@ -184,7 +184,7 @@ namespace Concerns
|
||||
|
||||
/*! Method called after visitation. */
|
||||
template<typename Method>
|
||||
void visited(const Method method);
|
||||
void visited(Method method);
|
||||
|
||||
// TODO templated LazyRelationStore by Container too, QVector to Container silverqx
|
||||
/*! The result of lazy load. */
|
||||
@@ -202,7 +202,7 @@ namespace Concerns
|
||||
|
||||
/*! Method called after visitation. */
|
||||
template<typename Method>
|
||||
void visited(const Method);
|
||||
void visited(Method /*unused*/);
|
||||
|
||||
/*! The related table name result. */
|
||||
std::optional<QString> m_result = std::nullopt;
|
||||
@@ -222,12 +222,12 @@ namespace Concerns
|
||||
qint64 count, const QString &condition,
|
||||
const std::function<
|
||||
void(QueriesRelationshipsCallback<Related> &)> &callback,
|
||||
const std::optional<std::reference_wrapper<
|
||||
QStringList>> relations = std::nullopt);
|
||||
std::optional<std::reference_wrapper<
|
||||
QStringList>> relations = std::nullopt);
|
||||
|
||||
/*! Method called after visitation. */
|
||||
template<typename RelatedFromMethod, typename Method>
|
||||
void visited(const Method method);
|
||||
void visited(Method method);
|
||||
|
||||
protected:
|
||||
/*! Store type initializer. */
|
||||
@@ -278,7 +278,7 @@ namespace Concerns
|
||||
qint64 count, const QString &condition,
|
||||
const std::function<
|
||||
void(QueriesRelationshipsCallback<Related> &)> &callback,
|
||||
const std::optional<std::reference_wrapper<
|
||||
std::optional<std::reference_wrapper<
|
||||
QStringList>> relations = std::nullopt);
|
||||
|
||||
/*! Release the ownership and destroy the top relation store on the stack. */
|
||||
@@ -461,7 +461,7 @@ namespace Concerns
|
||||
template<typename Derived, typename ...AllRelations>
|
||||
template<typename Method>
|
||||
void HasRelationStore<Derived, AllRelations...>::PushRelationStore::visited(
|
||||
const Method) const
|
||||
const Method /*unused*/) const
|
||||
{
|
||||
using Related = typename std::invoke_result_t<Method, Derived>
|
||||
::element_type::RelatedType;
|
||||
@@ -524,7 +524,7 @@ namespace Concerns
|
||||
template<typename Derived, typename ...AllRelations>
|
||||
template<typename Method>
|
||||
void HasRelationStore<Derived, AllRelations...>::BelongsToManyRelatedTableStore
|
||||
::visited(const Method)
|
||||
::visited(const Method /*unused*/)
|
||||
{
|
||||
using Relation = typename std::invoke_result_t<Method, Derived>::element_type;
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace Private
|
||||
requires std::is_member_function_pointer_v<Method>
|
||||
#endif
|
||||
TinyBuilder<Model> &
|
||||
has(const Method relation, const QString &comparison = GE, qint64 count = 1,
|
||||
has(Method relation, const QString &comparison = GE, qint64 count = 1,
|
||||
const QString &condition = AND,
|
||||
const std::function<void(TinyBuilder<Related> &)> &callback = nullptr);
|
||||
|
||||
@@ -186,7 +186,7 @@ namespace Private
|
||||
requires std::is_member_function_pointer_v<Method>
|
||||
#endif
|
||||
TinyBuilder<Model> &
|
||||
whereHas(const Method relation,
|
||||
whereHas(Method relation,
|
||||
const std::function<void(TinyBuilder<Related> &)> &callback = nullptr,
|
||||
const QString &comparison = GE, qint64 count = 1);
|
||||
|
||||
@@ -202,7 +202,7 @@ namespace Private
|
||||
/*! Get the "has relation" base query instance. */
|
||||
template<typename Related, typename Method>
|
||||
std::unique_ptr<Relation<Related>>
|
||||
getRelationWithoutConstraints(const Method method);
|
||||
getRelationWithoutConstraints(Method method);
|
||||
|
||||
/*! Add the "has" condition where clause to the query. */
|
||||
template<typename Related>
|
||||
@@ -596,14 +596,14 @@ namespace Private
|
||||
// Ownership of a unique_ptr()
|
||||
const auto hasQuery = getHasQueryByExistenceCheck(comparison, count, *relation);
|
||||
|
||||
if (relations.size() >= 1)
|
||||
hasQuery->hasInternal(relations.takeFirst(), GE, 1, AND, relations);
|
||||
else
|
||||
if (relations.isEmpty())
|
||||
throw Orm::Exceptions::RuntimeError(
|
||||
QStringLiteral(
|
||||
"wtf, this should never happen :/, 'relations.size() == %1'.")
|
||||
.arg(relations.size()));
|
||||
|
||||
hasQuery->hasInternal(relations.takeFirst(), GE, 1, AND, relations);
|
||||
|
||||
addHasWhere(*hasQuery, *relation, comparison, count, condition);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Orm::Tiny::Exceptions
|
||||
/*! Get the affected TinyORM model. */
|
||||
const QString &getModel() const;
|
||||
/*! Get the affected TinyORM model IDs. */
|
||||
const QVector<QVariant> getIds() const;
|
||||
QVector<QVariant> getIds() const;
|
||||
|
||||
protected:
|
||||
/*! Name of the affected TinyORM model. */
|
||||
@@ -50,7 +50,7 @@ namespace Orm::Tiny::Exceptions
|
||||
return m_model;
|
||||
}
|
||||
|
||||
inline const QVector<QVariant>
|
||||
inline QVector<QVariant>
|
||||
ModelNotFoundError::getIds() const
|
||||
{
|
||||
return m_ids;
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Orm::Tiny::Exceptions
|
||||
private:
|
||||
/*! Format the error message. */
|
||||
QString formatMessage(const QString &model, const QString &relation,
|
||||
const From from) const;
|
||||
From from) const;
|
||||
};
|
||||
|
||||
inline const QString &
|
||||
|
||||
@@ -182,13 +182,12 @@ namespace Relations {
|
||||
|
||||
/* Operations on a model instance */
|
||||
/*! Save the model to the database. */
|
||||
bool save(const SaveOptions options = {});
|
||||
bool save(SaveOptions options = {});
|
||||
/*! Save the model and all of its relationships. */
|
||||
bool push();
|
||||
|
||||
/*! Update records in the database. */
|
||||
bool update(const QVector<AttributeItem> &attributes,
|
||||
const SaveOptions options = {});
|
||||
bool update(const QVector<AttributeItem> &attributes, SaveOptions options = {});
|
||||
|
||||
/*! Delete the model from the database. */
|
||||
bool remove();
|
||||
@@ -278,7 +277,7 @@ namespace Relations {
|
||||
/*! Get the value indicating whether the IDs are incrementing. */
|
||||
bool getIncrementing() const;
|
||||
/*! Set whether IDs are incrementing. */
|
||||
Derived &setIncrementing(const bool value);
|
||||
Derived &setIncrementing(bool value);
|
||||
|
||||
/* Others */
|
||||
/*! Qualify the given column name by the model's table. */
|
||||
@@ -664,7 +663,7 @@ namespace Relations {
|
||||
/*! Perform a model insert operation. */
|
||||
bool performUpdate(TinyBuilder<Derived> &query);
|
||||
/*! Perform any actions that are necessary after the model is saved. */
|
||||
void finishSave(const SaveOptions options = {});
|
||||
void finishSave(SaveOptions options = {});
|
||||
|
||||
/*! Insert the given attributes and set the ID on the model. */
|
||||
quint64 insertAndSetId(const TinyBuilder<Derived> &query,
|
||||
@@ -790,8 +789,8 @@ namespace Relations {
|
||||
/*! Throw exception if correct getRelation/Value() method was not used, to avoid
|
||||
std::bad_variant_access. */
|
||||
template<typename Result, typename Related, typename T>
|
||||
void checkRelationType(
|
||||
const T &result, const QString &relation, const QString &source) const;
|
||||
void checkRelationType(const T &relationVariant, const QString &relation,
|
||||
const QString &source) const;
|
||||
|
||||
/*! Guess the relationship name for belongsTo/belongsToMany. */
|
||||
template<typename Related>
|
||||
@@ -828,8 +827,8 @@ namespace Relations {
|
||||
const QString &relation, Concerns::QueriesRelationships<Derived> &origin,
|
||||
const QString &comparison, qint64 count, const QString &condition,
|
||||
const std::function<void(
|
||||
Concerns::QueriesRelationshipsCallback<Related> &)> &callback,
|
||||
const std::optional<std::reference_wrapper<
|
||||
Concerns::QueriesRelationshipsCallback<Related> &)> &callback,
|
||||
std::optional<std::reference_wrapper<
|
||||
QStringList>> relations = std::nullopt);
|
||||
|
||||
/* Others */
|
||||
@@ -1682,7 +1681,7 @@ namespace Relations {
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
template<typename Related, template<typename> typename Container>
|
||||
const Container<Related *>
|
||||
const Container<Related *> // NOLINT(readability-const-return-type)
|
||||
Model<Derived, AllRelations...>::getRelationValue(const QString &relation)
|
||||
{
|
||||
/*! If the key already exists in the relationships hash, it just means the
|
||||
@@ -1869,16 +1868,15 @@ namespace Relations {
|
||||
already contains any attributes. If it does we will just return that this
|
||||
count is greater than zero. Else, we need to check specific attributes. */
|
||||
if (attributes.isEmpty())
|
||||
return changes.size() > 0;
|
||||
return !changes.empty();
|
||||
|
||||
/* Here we will spin through every attribute and see if this is in the hash of
|
||||
dirty attributes. If it is, we will return true and if we make it through
|
||||
all of the attributes for the entire vector we will return false at end. */
|
||||
for (const auto &attribute : attributes)
|
||||
if (changes.contains(attribute))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
return std::ranges::any_of(attributes, [&changes](const auto &attribute)
|
||||
{
|
||||
return changes.contains(attribute);
|
||||
});
|
||||
}
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
@@ -2054,7 +2052,7 @@ namespace Relations {
|
||||
// TODO solve different behavior like Eloquent getRelation() silverqx
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
template<typename Related, template<typename> typename Container>
|
||||
const Container<Related *>
|
||||
const Container<Related *> // NOLINT(readability-const-return-type)
|
||||
Model<Derived, AllRelations...>::getRelation(const QString &relation)
|
||||
{
|
||||
if (!relationLoaded(relation))
|
||||
@@ -3276,14 +3274,10 @@ namespace Relations {
|
||||
template<typename ClassToCheck>
|
||||
bool Model<Derived, AllRelations...>::isIgnoringTouch()
|
||||
{
|
||||
if (!ClassToCheck().usesTimestamps()
|
||||
|| ClassToCheck::getUpdatedAtColumn().isEmpty()
|
||||
)
|
||||
return true;
|
||||
|
||||
// FUTURE implement withoutTouching() and related data member $ignoreOnTouch silverqx
|
||||
|
||||
return false;
|
||||
return !ClassToCheck().usesTimestamps()
|
||||
|| ClassToCheck::getUpdatedAtColumn().isEmpty();
|
||||
}
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
|
||||
@@ -609,7 +609,7 @@ namespace Relations
|
||||
requires std::is_member_function_pointer_v<Method>
|
||||
#endif
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
has(const Method relation, const QString &comparison = GE, qint64 count = 1,
|
||||
has(Method relation, const QString &comparison = GE, qint64 count = 1,
|
||||
const QString &condition = AND,
|
||||
const std::function<void(TinyBuilder<Related> &)> &callback = nullptr);
|
||||
|
||||
@@ -654,7 +654,7 @@ namespace Relations
|
||||
requires std::is_member_function_pointer_v<Method>
|
||||
#endif
|
||||
static std::unique_ptr<TinyBuilder<Derived>>
|
||||
whereHas(const Method relation,
|
||||
whereHas(Method relation,
|
||||
const std::function<void(TinyBuilder<Related> &)> &callback = nullptr,
|
||||
const QString &comparison = GE, qint64 count = 1);
|
||||
|
||||
|
||||
@@ -194,7 +194,7 @@ namespace Orm::Tiny::Relations
|
||||
// FEATURE events silverqx
|
||||
// fireModelEvent("deleted", false);
|
||||
|
||||
return affected > 0 ? true : false;
|
||||
return affected > 0;
|
||||
}
|
||||
|
||||
template<typename PivotModel>
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace Orm::Tiny::Relations
|
||||
buildDictionary(const QVector<Related> &results) const;
|
||||
|
||||
/*! Make a new related instance for the given model. */
|
||||
Related newRelatedInstanceFor(const Model &) const override;
|
||||
Related newRelatedInstanceFor(const Model &/*unused*/) const override;
|
||||
|
||||
/* Querying Relationship Existence/Absence */
|
||||
/*! Add the constraints for a relationship query. */
|
||||
@@ -313,7 +313,7 @@ namespace Orm::Tiny::Relations
|
||||
|
||||
template<class Model, class Related>
|
||||
inline Related
|
||||
BelongsTo<Model, Related>::newRelatedInstanceFor(const Model &) const
|
||||
BelongsTo<Model, Related>::newRelatedInstanceFor(const Model &/*unused*/) const
|
||||
{
|
||||
return this->m_related->newInstance();
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Orm::Tiny::Relations
|
||||
|
||||
protected:
|
||||
/*! Make a new related instance for the given model. */
|
||||
Related newRelatedInstanceFor(const Model &) const override;
|
||||
Related newRelatedInstanceFor(const Model &/*unused*/) const override;
|
||||
};
|
||||
|
||||
template<class Model, class Related>
|
||||
|
||||
@@ -297,7 +297,7 @@ namespace Orm::Tiny::Relations
|
||||
{
|
||||
QVector<Related> instances;
|
||||
|
||||
for (auto &record : records)
|
||||
for (const auto &record : records)
|
||||
instances << create(record);
|
||||
|
||||
return instances;
|
||||
|
||||
@@ -342,7 +342,7 @@ namespace Relations
|
||||
template<class Model, class Related>
|
||||
std::unique_ptr<Builder<Related>>
|
||||
Relation<Model, Related>::getRelationExistenceQuery(
|
||||
std::unique_ptr<Builder<Related>> &&query, const Builder<Model> &,
|
||||
std::unique_ptr<Builder<Related>> &&query, const Builder<Model> &/*unused*/,
|
||||
const QVector<Column> &columns) const
|
||||
{
|
||||
query->select(columns).whereColumnEq(getQualifiedParentKeyName(),
|
||||
|
||||
@@ -575,7 +575,7 @@ namespace Tiny::Relations
|
||||
requires std::is_member_function_pointer_v<Method>
|
||||
#endif
|
||||
const Relation<Model, Related> &
|
||||
has(const Method relation, const QString &comparison = GE, qint64 count = 1,
|
||||
has(Method relation, const QString &comparison = GE, qint64 count = 1,
|
||||
const QString &condition = AND,
|
||||
const std::function<void(
|
||||
TinyBuilder<HasRelated> &)> &callback = nullptr) const;
|
||||
@@ -622,7 +622,7 @@ namespace Tiny::Relations
|
||||
requires std::is_member_function_pointer_v<Method>
|
||||
#endif
|
||||
const Relation<Model, Related> &
|
||||
whereHas(const Method relation,
|
||||
whereHas(Method relation,
|
||||
const std::function<void(
|
||||
TinyBuilder<HasRelated> &)> &callback = nullptr,
|
||||
const QString &comparison = GE, qint64 count = 1) const;
|
||||
|
||||
@@ -44,14 +44,13 @@ bool DetectsLostConnections::causedByLostConnection(const Exceptions::SqlError &
|
||||
"SSL: Connection timed out",
|
||||
};
|
||||
|
||||
for (const auto databaseError = e.getSqlError().databaseText();
|
||||
const auto &lostMessage : lostMessagesCache
|
||||
)
|
||||
return std::ranges::any_of(lostMessagesCache,
|
||||
[databaseError = e.getSqlError().databaseText()]
|
||||
(const auto &lostMessage)
|
||||
{
|
||||
// found
|
||||
if (databaseError.indexOf(lostMessage, 0, Qt::CaseInsensitive) >= 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
return databaseError.indexOf(lostMessage, 0, Qt::CaseInsensitive) >= 0;
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace Orm::Concerns
|
||||
|
||||
@@ -59,7 +59,7 @@ PostgresConnector::getConnectorOptions() const
|
||||
return m_options;
|
||||
}
|
||||
|
||||
void PostgresConnector::parseConfigOptions(QVariantHash &) const
|
||||
void PostgresConnector::parseConfigOptions(QVariantHash &/*unused*/) const
|
||||
{}
|
||||
|
||||
void PostgresConnector::configureEncoding(const QSqlDatabase &connection,
|
||||
|
||||
@@ -58,7 +58,7 @@ SQLiteConnector::getConnectorOptions() const
|
||||
return m_options;
|
||||
}
|
||||
|
||||
void SQLiteConnector::parseConfigOptions(QVariantHash &) const
|
||||
void SQLiteConnector::parseConfigOptions(QVariantHash &/*unused*/) const
|
||||
{}
|
||||
|
||||
void SQLiteConnector::configureForeignKeyConstraints(
|
||||
|
||||
@@ -443,7 +443,7 @@ DatabaseConnection::affectingStatement(const QString &queryString,
|
||||
QSqlQuery DatabaseConnection::unprepared(const QString &queryString)
|
||||
{
|
||||
return run<QSqlQuery>(queryString, {},
|
||||
[this](const QString &queryString_, const QVector<QVariant> &)
|
||||
[this](const QString &queryString_, const QVector<QVariant> &/*unused*/)
|
||||
-> QSqlQuery
|
||||
{
|
||||
if (m_pretending)
|
||||
|
||||
@@ -184,12 +184,12 @@ size_t DatabaseManager::transactionLevel()
|
||||
|
||||
DatabaseManager *DatabaseManager::instance()
|
||||
{
|
||||
if (!m_instance)
|
||||
throw Exceptions::RuntimeError(
|
||||
"The DatabaseManager instance has not been created yet, create it "
|
||||
"by DB::create() method.");
|
||||
if (m_instance != nullptr)
|
||||
return m_instance;
|
||||
|
||||
return m_instance;
|
||||
throw Exceptions::RuntimeError(
|
||||
"The DatabaseManager instance has not been created yet, create it "
|
||||
"by DB::create() method.");
|
||||
}
|
||||
|
||||
ConnectionInterface &DatabaseManager::connection(const QString &name)
|
||||
@@ -287,7 +287,7 @@ QStringList DatabaseManager::openedConnectionNames() const
|
||||
// TODO overflow, add check code https://stackoverflow.com/questions/22184403/how-to-cast-the-size-t-to-double-or-int-c/22184657#22184657 silverqx
|
||||
names.reserve(static_cast<int>(m_connections.size()));
|
||||
|
||||
for (auto &connection : m_connections)
|
||||
for (const auto &connection : m_connections)
|
||||
names << connection.first;
|
||||
|
||||
return names;
|
||||
@@ -344,13 +344,11 @@ DatabaseConnection &DatabaseManager::resetElapsedCounter(const QString &connecti
|
||||
|
||||
bool DatabaseManager::anyCountingElapsed()
|
||||
{
|
||||
const auto connections = openedConnectionNames();
|
||||
|
||||
for (const auto &connectionName : connections)
|
||||
if (connection(connectionName).countingElapsed())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
return std::ranges::any_of(openedConnectionNames(),
|
||||
[this](const auto &connectionName)
|
||||
{
|
||||
return connection(connectionName).countingElapsed();
|
||||
});
|
||||
}
|
||||
|
||||
void DatabaseManager::enableAllElapsedCounters()
|
||||
@@ -466,13 +464,11 @@ DatabaseConnection &DatabaseManager::resetStatementsCounter(const QString &conne
|
||||
|
||||
bool DatabaseManager::anyCountingStatements()
|
||||
{
|
||||
const auto connections = openedConnectionNames();
|
||||
|
||||
for (const auto &connectionName : connections)
|
||||
if (connection(connectionName).countingStatements())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
return std::ranges::any_of(openedConnectionNames(),
|
||||
[this](const auto &connectionName)
|
||||
{
|
||||
return connection(connectionName).countingStatements();
|
||||
});
|
||||
}
|
||||
|
||||
void DatabaseManager::enableAllStatementCounters()
|
||||
|
||||
@@ -11,7 +11,7 @@ DatabaseManager *DB::m_manager = nullptr;
|
||||
|
||||
DatabaseManager &DB::manager()
|
||||
{
|
||||
if (!m_manager)
|
||||
if (m_manager == nullptr)
|
||||
m_manager = DatabaseManager::instance();
|
||||
|
||||
return *m_manager;
|
||||
@@ -55,7 +55,7 @@ void DB::disconnect(const QString &name)
|
||||
manager().disconnect(name);
|
||||
}
|
||||
|
||||
const QStringList DB::supportedDrivers()
|
||||
QStringList DB::supportedDrivers()
|
||||
{
|
||||
return manager().supportedDrivers();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ SqlError::SqlError(const QString &message, const QSqlError &error)
|
||||
{}
|
||||
|
||||
// NOLINTNEXTLINE(modernize-pass-by-value)
|
||||
SqlError::SqlError(const QString &message, const QSqlError &error, const int)
|
||||
SqlError::SqlError(const QString &message, const QSqlError &error, const int /*unused*/)
|
||||
: RuntimeError(message.toUtf8().constData())
|
||||
, m_sqlError(error)
|
||||
{}
|
||||
|
||||
@@ -46,8 +46,8 @@ QString Grammar::compileInsert(const QueryBuilder &query,
|
||||
compileInsertToVector(values).join(COMMA));
|
||||
}
|
||||
|
||||
QString Grammar::compileInsertOrIgnore(const QueryBuilder &,
|
||||
const QVector<QVariantMap> &) const
|
||||
QString Grammar::compileInsertOrIgnore(const QueryBuilder &/*unused*/,
|
||||
const QVector<QVariantMap> &/*unused*/) const
|
||||
{
|
||||
throw Exceptions::RuntimeError(
|
||||
"This database engine does not support inserting while ignoring "
|
||||
@@ -214,7 +214,7 @@ QString Grammar::compileWheres(const QueryBuilder &query) const
|
||||
{
|
||||
const auto sql = compileWheresToVector(query);
|
||||
|
||||
if (sql.size() > 0)
|
||||
if (!sql.isEmpty())
|
||||
return concatenateWhereClauses(query, sql);
|
||||
|
||||
return {};
|
||||
@@ -455,7 +455,7 @@ Grammar::compileUpdateColumns(const QVector<UpdateItem> &values) const
|
||||
}
|
||||
|
||||
QString
|
||||
Grammar::compileUpdateWithoutJoins(const QueryBuilder &, const QString &table,
|
||||
Grammar::compileUpdateWithoutJoins(const QueryBuilder &/*unused*/, const QString &table,
|
||||
const QString &columns, const QString &wheres) const
|
||||
{
|
||||
// The table argument is already wrapped
|
||||
@@ -473,7 +473,7 @@ Grammar::compileUpdateWithJoins(const QueryBuilder &query, const QString &table,
|
||||
}
|
||||
|
||||
QString
|
||||
Grammar::compileDeleteWithoutJoins(const QueryBuilder &, const QString &table,
|
||||
Grammar::compileDeleteWithoutJoins(const QueryBuilder &/*unused*/, const QString &table,
|
||||
const QString &wheres) const
|
||||
{
|
||||
// The table argument is already wrapped
|
||||
|
||||
@@ -42,7 +42,7 @@ SQLiteGrammar::compileTruncate(const QueryBuilder &query) const
|
||||
};
|
||||
}
|
||||
|
||||
QString SQLiteGrammar::compileLock(const QueryBuilder &) const
|
||||
QString SQLiteGrammar::compileLock(const QueryBuilder &/*unused*/) const
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ TINYORM_BEGIN_COMMON_NAMESPACE
|
||||
namespace Orm::Query::Processors
|
||||
{
|
||||
|
||||
QStringList Processor::processColumnListing(QSqlQuery &) const
|
||||
QStringList Processor::processColumnListing(QSqlQuery &/*unused*/) const
|
||||
{
|
||||
throw Exceptions::RuntimeError(QStringLiteral("Method %1() is not implemented.")
|
||||
.arg(__tiny_func__));
|
||||
|
||||
@@ -198,7 +198,8 @@ void Builder::truncate()
|
||||
m_connection.statement(sql, bindings);
|
||||
}
|
||||
|
||||
QVariant Builder::aggregate(const QString &function, const QVector<Column> &columns)
|
||||
QVariant Builder::aggregate(const QString &function,
|
||||
const QVector<Column> &columns) const
|
||||
{
|
||||
auto resultsQuery = cloneWithout({PropertyType::COLUMNS})
|
||||
.cloneWithoutBindings({BindingType::SELECT})
|
||||
@@ -751,7 +752,7 @@ Expression Builder::raw(const QVariant &value) const
|
||||
Builder &Builder::addNestedWhereQuery(const QSharedPointer<Builder> &query,
|
||||
const QString &condition)
|
||||
{
|
||||
if (!(query->m_wheres.size() > 0))
|
||||
if (query->m_wheres.isEmpty())
|
||||
return *this;
|
||||
|
||||
m_wheres.append({.column = {}, .condition = condition, .type = WhereType::NESTED,
|
||||
|
||||
@@ -5,7 +5,7 @@ TINYORM_BEGIN_COMMON_NAMESPACE
|
||||
namespace Orm::Schema::Grammars
|
||||
{
|
||||
|
||||
QString MySqlSchemaGrammar::compileColumnListing(const QString &) const
|
||||
QString MySqlSchemaGrammar::compileColumnListing(const QString &/*unused*/) const
|
||||
{
|
||||
return "select `column_name` as `column_name` "
|
||||
"from `information_schema`.`columns` "
|
||||
|
||||
@@ -5,7 +5,7 @@ TINYORM_BEGIN_COMMON_NAMESPACE
|
||||
namespace Orm::Schema::Grammars
|
||||
{
|
||||
|
||||
QString PostgresSchemaGrammar::compileColumnListing(const QString &) const
|
||||
QString PostgresSchemaGrammar::compileColumnListing(const QString &/*unused*/) const
|
||||
{
|
||||
return "select column_name "
|
||||
"from information_schema.columns "
|
||||
|
||||
3
tests/auto/.clang-tidy
Normal file
3
tests/auto/.clang-tidy
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
Checks: '-readability-function-cognitive-complexity'
|
||||
InheritParentConfig: true
|
||||
@@ -37,6 +37,7 @@ private slots:
|
||||
|
||||
void limit() const;
|
||||
|
||||
// NOLINTNEXTLINE(readability-redundant-access-specifiers)
|
||||
private:
|
||||
/*! Create QueryBuilder instance for the given connection. */
|
||||
[[nodiscard]] QSharedPointer<QueryBuilder>
|
||||
|
||||
@@ -1136,7 +1136,7 @@ void tst_Model::update() const
|
||||
|
||||
auto torrent = Torrent::find(4);
|
||||
|
||||
auto &updatedAtColumn = torrent->getUpdatedAtColumn();
|
||||
const auto &updatedAtColumn = torrent->getUpdatedAtColumn();
|
||||
|
||||
auto progressOriginal = torrent->getAttribute("progress");
|
||||
auto updatedAtOriginal = torrent->getAttribute(updatedAtColumn);
|
||||
@@ -1208,7 +1208,7 @@ void tst_Model::update_SameValue() const
|
||||
auto torrent = Torrent::find(3);
|
||||
QVERIFY(torrent->exists);
|
||||
|
||||
auto &updatedAtColumn = torrent->getUpdatedAtColumn();
|
||||
const auto &updatedAtColumn = torrent->getUpdatedAtColumn();
|
||||
auto updatedAt = torrent->getAttribute(updatedAtColumn);
|
||||
|
||||
/* Doesn't send update query to the database, this is different from
|
||||
|
||||
@@ -44,6 +44,7 @@ private slots:
|
||||
void with_WithSelectConstraint_QueryWithoutRelatedTable() const;
|
||||
void with_BelongsToMany_WithSelectConstraint_QualifiedColumnsForRelatedTable() const;
|
||||
|
||||
// NOLINTNEXTLINE(readability-redundant-access-specifiers)
|
||||
private:
|
||||
/*! Connection name used in this test case. */
|
||||
QString m_connection = {};
|
||||
|
||||
@@ -38,6 +38,7 @@ private slots:
|
||||
void update_Failed() const;
|
||||
void update_SameValue() const;
|
||||
|
||||
// NOLINTNEXTLINE(readability-redundant-access-specifiers)
|
||||
private:
|
||||
/*! Create the TinyBuilder by template parameter. */
|
||||
template<typename Model>
|
||||
@@ -175,7 +176,7 @@ void tst_TinyBuilder::incrementAndDecrement() const
|
||||
QVERIFY(torrent4_1);
|
||||
QVERIFY(torrent4_1->exists);
|
||||
|
||||
auto &updatedAtColumn = torrent4_1->getUpdatedAtColumn();
|
||||
const auto &updatedAtColumn = torrent4_1->getUpdatedAtColumn();
|
||||
|
||||
auto sizeOriginal = torrent4_1->getAttribute("size");
|
||||
auto progressOriginal = torrent4_1->getAttribute("progress");
|
||||
@@ -224,7 +225,7 @@ void tst_TinyBuilder::update() const
|
||||
|
||||
auto torrent = Torrent::find(4);
|
||||
|
||||
auto &updatedAtColumn = torrent->getUpdatedAtColumn();
|
||||
const auto &updatedAtColumn = torrent->getUpdatedAtColumn();
|
||||
|
||||
auto progressOriginal = torrent->getAttribute("progress");
|
||||
auto updatedAtOriginal = torrent->getAttribute(updatedAtColumn);
|
||||
|
||||
@@ -147,6 +147,7 @@ private slots:
|
||||
void remove() const;
|
||||
void remove_WithExpression() const;
|
||||
|
||||
// NOLINTNEXTLINE(readability-redundant-access-specifiers)
|
||||
private:
|
||||
/*! Create QueryBuilder instance for the given connection. */
|
||||
[[nodiscard]] QSharedPointer<QueryBuilder> createQuery() const;
|
||||
|
||||
@@ -109,6 +109,7 @@ private slots:
|
||||
void remove() const;
|
||||
void remove_WithExpression() const;
|
||||
|
||||
// NOLINTNEXTLINE(readability-redundant-access-specifiers)
|
||||
private:
|
||||
/*! Create QueryBuilder instance for the given connection. */
|
||||
[[nodiscard]] QSharedPointer<QueryBuilder> createQuery() const;
|
||||
@@ -398,7 +399,7 @@ void tst_PostgreSQL_QueryBuilder::distinct_on() const
|
||||
const QStringList distinctList {"location", "time"};
|
||||
builder->distinct(distinctList);
|
||||
|
||||
auto &distinct = std::get<QStringList>(builder->getDistinct());
|
||||
const auto &distinct = std::get<QStringList>(builder->getDistinct());
|
||||
QCOMPARE(distinct, distinctList);
|
||||
QCOMPARE(builder->toSql(),
|
||||
"select distinct on (\"location\", \"time\") * from \"torrents\"");
|
||||
|
||||
@@ -109,6 +109,7 @@ private slots:
|
||||
void remove() const;
|
||||
void remove_WithExpression() const;
|
||||
|
||||
// NOLINTNEXTLINE(readability-redundant-access-specifiers)
|
||||
private:
|
||||
/*! Create QueryBuilder instance for the given connection. */
|
||||
[[nodiscard]] QSharedPointer<QueryBuilder> createQuery() const;
|
||||
|
||||
@@ -68,6 +68,7 @@ private slots:
|
||||
void hasNested_Count_TinyBuilder_OnBelongsToMany_NestedAsLast() const;
|
||||
void hasNested_Count_TinyBuilder_OnBelongsToMany_NestedInMiddle() const;
|
||||
|
||||
// NOLINTNEXTLINE(readability-redundant-access-specifiers)
|
||||
private:
|
||||
/*! Create TinyBuilder instance for the given connection. */
|
||||
template<typename Model>
|
||||
|
||||
@@ -38,6 +38,7 @@ private slots:
|
||||
void checkFileVersion_TinyUtils() const;
|
||||
|
||||
#if defined(_WIN32) && defined(TINYTEST_VERSION_IS_SHARED_BUILD)
|
||||
// NOLINTNEXTLINE(readability-redundant-access-specifiers)
|
||||
private:
|
||||
/*! Return value for the getExeVersionString(). */
|
||||
struct FileVersions
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "models/torrent.hpp"
|
||||
#include "models/torrentpreviewablefileproperty.hpp"
|
||||
|
||||
using Orm::Constants::NAME;
|
||||
using Orm::Tiny::Relations::BelongsTo;
|
||||
using Orm::Tiny::Relations::HasOne;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user