mirror of
https://github.com/silverqx/TinyORM.git
synced 2025-12-30 15:29:36 -06:00
used shared_ptr everywhere
Get rid of the QSharedPointer and use the std::shared_ptr everywhere.
This commit is contained in:
@@ -81,7 +81,7 @@ namespace SchemaNs
|
||||
inline ~DatabaseConnection() override = 0;
|
||||
|
||||
/*! Begin a fluent query against a database table. */
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
table(const QString &table, const QString &as = "");
|
||||
|
||||
/*! Get the table prefix for the connection. */
|
||||
@@ -92,7 +92,7 @@ namespace SchemaNs
|
||||
BaseGrammar &withTablePrefix(BaseGrammar &grammar) const;
|
||||
|
||||
/*! Get a new query builder instance. */
|
||||
QSharedPointer<QueryBuilder> query();
|
||||
std::shared_ptr<QueryBuilder> query();
|
||||
|
||||
/*! Get a new raw query expression. */
|
||||
inline Query::Expression raw(const QVariant &value) const;
|
||||
|
||||
@@ -50,15 +50,15 @@ namespace Query
|
||||
|
||||
/* Proxy methods to the DatabaseConnection */
|
||||
/*! Begin a fluent query against a database table for the connection. */
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
table(const QString &table, const QString &connection = "");
|
||||
/*! Begin a fluent query against a database table for the connection. */
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
tableAs(const QString &table, const QString &as = "",
|
||||
const QString &connection = "");
|
||||
|
||||
/*! Get a new query builder instance for the connection. */
|
||||
QSharedPointer<QueryBuilder> query(const QString &connection = "");
|
||||
std::shared_ptr<QueryBuilder> query(const QString &connection = "");
|
||||
/*! Get a new QSqlQuery instance for the connection. */
|
||||
QSqlQuery qtQuery(const QString &connection = "");
|
||||
|
||||
|
||||
@@ -100,15 +100,15 @@ namespace Orm
|
||||
|
||||
/* Proxy methods to the DatabaseConnection */
|
||||
/*! Begin a fluent query against a database table for the connection. */
|
||||
static QSharedPointer<QueryBuilder>
|
||||
static std::shared_ptr<QueryBuilder>
|
||||
table(const QString &table, const QString &connection = "");
|
||||
/*! Begin a fluent query against a database table for the connection. */
|
||||
static QSharedPointer<QueryBuilder>
|
||||
static std::shared_ptr<QueryBuilder>
|
||||
tableAs(const QString &table, const QString &as = "",
|
||||
const QString &connection = "");
|
||||
|
||||
/*! Get a new query builder instance for the connection. */
|
||||
static QSharedPointer<QueryBuilder> query(const QString &connection = "");
|
||||
static std::shared_ptr<QueryBuilder> query(const QString &connection = "");
|
||||
/*! Get a new QSqlQuery instance for the connection. */
|
||||
static QSqlQuery qtQuery(const QString &connection = "");
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
#include "orm/macros/systemheader.hpp"
|
||||
TINY_SYSTEM_HEADER
|
||||
|
||||
#include <QSharedPointer>
|
||||
#include <QVariant>
|
||||
#include <QVector>
|
||||
|
||||
#include <memory>
|
||||
#include <variant>
|
||||
|
||||
#include "orm/constants.hpp"
|
||||
@@ -83,15 +83,15 @@ namespace Query
|
||||
/*! Where clause item, primarily used in grammars to build sql query. */
|
||||
struct WhereConditionItem
|
||||
{
|
||||
Column column {};
|
||||
QVariant value {};
|
||||
QString comparison {Orm::Constants::EQ};
|
||||
QString condition {Orm::Constants::AND};
|
||||
WhereType type {WhereType::UNDEFINED};
|
||||
QSharedPointer<QueryBuilder> nestedQuery {nullptr};
|
||||
QVector<QVariant> values {};
|
||||
Column columnTwo {};
|
||||
QString sql {};
|
||||
Column column {};
|
||||
QVariant value {};
|
||||
QString comparison {Orm::Constants::EQ};
|
||||
QString condition {Orm::Constants::AND};
|
||||
WhereType type {WhereType::UNDEFINED};
|
||||
std::shared_ptr<QueryBuilder> nestedQuery {nullptr};
|
||||
QVector<QVariant> values {};
|
||||
Column columnTwo {};
|
||||
QString sql {};
|
||||
};
|
||||
|
||||
/*! Supported having types. */
|
||||
|
||||
@@ -55,11 +55,11 @@ namespace Orm::Query
|
||||
getTable() const;
|
||||
|
||||
/*! Get a new instance of the join clause builder. */
|
||||
QSharedPointer<Builder> newQuery() const final;
|
||||
std::shared_ptr<Builder> newQuery() const final;
|
||||
|
||||
protected:
|
||||
/*! Create a new query instance for a sub-query. */
|
||||
QSharedPointer<Builder> forSubQuery() const final;
|
||||
std::shared_ptr<Builder> forSubQuery() const final;
|
||||
|
||||
private:
|
||||
/*! The type of join being performed. */
|
||||
|
||||
@@ -499,7 +499,7 @@ namespace Orm::Query
|
||||
/*! Get the table associated with the query builder. */
|
||||
inline const FromClause &getFrom() const;
|
||||
/*! Get the table joins for the query. */
|
||||
inline const QVector<QSharedPointer<JoinClause>> &getJoins() const;
|
||||
inline const QVector<std::shared_ptr<JoinClause>> &getJoins() const;
|
||||
/*! Get the where constraints for the query. */
|
||||
inline const QVector<WhereConditionItem> &getWheres() const;
|
||||
/*! Get the groupings for the query. */
|
||||
@@ -517,18 +517,18 @@ namespace Orm::Query
|
||||
|
||||
/* Other methods */
|
||||
/*! Get a new instance of the query builder. */
|
||||
virtual QSharedPointer<Builder> newQuery() const;
|
||||
virtual std::shared_ptr<Builder> newQuery() const;
|
||||
/*! Create a new query instance for nested where condition. */
|
||||
QSharedPointer<Builder> forNestedWhere() const;
|
||||
std::shared_ptr<Builder> forNestedWhere() const;
|
||||
|
||||
/*! Create a raw database expression. */
|
||||
Expression raw(const QVariant &value) const;
|
||||
|
||||
/*! Add another query builder as a nested where to the query builder. */
|
||||
Builder &addNestedWhereQuery(const QSharedPointer<Builder> &query,
|
||||
Builder &addNestedWhereQuery(const std::shared_ptr<Builder> &query,
|
||||
const QString &condition);
|
||||
/*! Add an "exists" clause to the query. */
|
||||
Builder &addWhereExistsQuery(const QSharedPointer<Builder> &query,
|
||||
Builder &addWhereExistsQuery(const std::shared_ptr<Builder> &query,
|
||||
const QString &condition = AND, bool nope = false);
|
||||
|
||||
/*! Merge an array of where clauses and bindings. */
|
||||
@@ -567,11 +567,11 @@ namespace Orm::Query
|
||||
const QString &condition = AND);
|
||||
|
||||
/*! Get a new join clause. */
|
||||
QSharedPointer<JoinClause>
|
||||
std::shared_ptr<JoinClause>
|
||||
newJoinClause(const Builder &query, const QString &type,
|
||||
const QString &table) const;
|
||||
/*! Get a new join clause. */
|
||||
QSharedPointer<JoinClause>
|
||||
std::shared_ptr<JoinClause>
|
||||
newJoinClause(const Builder &query, const QString &type,
|
||||
Expression &&table) const;
|
||||
|
||||
@@ -602,7 +602,7 @@ namespace Orm::Query
|
||||
std::is_invocable_v<T, Orm::QueryBuilder &>;
|
||||
|
||||
/*! Create a new query instance for a sub-query. */
|
||||
inline virtual QSharedPointer<Builder> forSubQuery() const;
|
||||
inline virtual std::shared_ptr<Builder> forSubQuery() const;
|
||||
|
||||
/*! Prepend the database name if the given query is on another database. */
|
||||
Builder &prependDatabaseNameIfCrossDatabaseQuery(Builder &query) const;
|
||||
@@ -624,14 +624,14 @@ namespace Orm::Query
|
||||
|
||||
/*! Add a join clause to the query, common code. */
|
||||
Builder &joinInternal(
|
||||
QSharedPointer<JoinClause> &&join, const QString &first,
|
||||
std::shared_ptr<JoinClause> &&join, const QString &first,
|
||||
const QString &comparison, const QVariant &second, bool where);
|
||||
/*! Add an advanced join clause to the query, common code. */
|
||||
Builder &joinInternal(
|
||||
QSharedPointer<JoinClause> &&join,
|
||||
std::shared_ptr<JoinClause> &&join,
|
||||
const std::function<void(JoinClause &)> &callback);
|
||||
/*! Add a join clause to the query, common code for the above two methods. */
|
||||
Builder &joinInternal(QSharedPointer<JoinClause> &&join);
|
||||
Builder &joinInternal(std::shared_ptr<JoinClause> &&join);
|
||||
|
||||
/*! Add a subquery join clause to the query, common code. */
|
||||
Builder &joinSubInternal(
|
||||
@@ -682,7 +682,7 @@ namespace Orm::Query
|
||||
/*! The table which the query is targeting. */
|
||||
FromClause m_from {};
|
||||
/*! The table joins for the query. */
|
||||
QVector<QSharedPointer<JoinClause>> m_joins {};
|
||||
QVector<std::shared_ptr<JoinClause>> m_joins {};
|
||||
/*! The where constraints for the query. */
|
||||
QVector<WhereConditionItem> m_wheres {};
|
||||
/*! The groupings for the query. */
|
||||
@@ -841,7 +841,7 @@ namespace Orm::Query
|
||||
Builder::join(T &&table, const QString &first, const QString &comparison,
|
||||
const QVariant &second, const QString &type, const bool where)
|
||||
{
|
||||
// Ownership of the QSharedPointer<JoinClause>
|
||||
// Ownership of the std::shared_ptr<JoinClause>
|
||||
return joinInternal(newJoinClause(*this, type, std::forward<T>(table)),
|
||||
first, comparison, second, where);
|
||||
}
|
||||
@@ -852,7 +852,7 @@ namespace Orm::Query
|
||||
Builder::join(T &&table, const std::function<void(JoinClause &)> &callback,
|
||||
const QString &type)
|
||||
{
|
||||
// Ownership of the QSharedPointer<JoinClause>
|
||||
// Ownership of the std::shared_ptr<JoinClause>
|
||||
return joinInternal(newJoinClause(*this, type, std::forward<T>(table)),
|
||||
callback);
|
||||
}
|
||||
@@ -1176,7 +1176,7 @@ namespace Orm::Query
|
||||
return m_from;
|
||||
}
|
||||
|
||||
const QVector<QSharedPointer<JoinClause>> &
|
||||
const QVector<std::shared_ptr<JoinClause>> &
|
||||
Builder::getJoins() const
|
||||
{
|
||||
return m_joins;
|
||||
@@ -1224,7 +1224,7 @@ namespace Orm::Query
|
||||
|
||||
/* protected */
|
||||
|
||||
QSharedPointer<Builder>
|
||||
std::shared_ptr<Builder>
|
||||
Builder::forSubQuery() const
|
||||
{
|
||||
return newQuery();
|
||||
|
||||
@@ -219,7 +219,7 @@ namespace Private
|
||||
/*! Add a sub-query count clause to this query. */
|
||||
TinyBuilder<Model> &
|
||||
addWhereCountQuery(
|
||||
const QSharedPointer<QueryBuilder> &query,
|
||||
const std::shared_ptr<QueryBuilder> &query,
|
||||
const QString &comparison = GE, qint64 count = 1,
|
||||
const QString &condition = AND);
|
||||
|
||||
@@ -508,7 +508,7 @@ namespace Private
|
||||
template<typename Model>
|
||||
TinyBuilder<Model> &
|
||||
QueriesRelationships<Model>::addWhereCountQuery(
|
||||
const QSharedPointer<QueryBuilder> &query, const QString &comparison,
|
||||
const std::shared_ptr<QueryBuilder> &query, const QString &comparison,
|
||||
const qint64 count, const QString &condition)
|
||||
{
|
||||
this->query().getQuery().addBinding(query->getBindings(), BindingType::WHERE);
|
||||
|
||||
@@ -172,7 +172,7 @@ namespace Orm::Tiny
|
||||
std::unique_ptr<TinyBuilder<Derived>> newQueryWithoutRelationships();
|
||||
/*! Create a new Tiny query builder for the model. */
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
newTinyBuilder(const QSharedPointer<QueryBuilder> &query);
|
||||
newTinyBuilder(const std::shared_ptr<QueryBuilder> &query);
|
||||
|
||||
/*! Create a new model instance that is existing. */
|
||||
Derived newFromBuilder(const QVector<AttributeItem> &attributes = {},
|
||||
@@ -230,7 +230,7 @@ namespace Orm::Tiny
|
||||
protected:
|
||||
/* Model Instance methods */
|
||||
/*! Get a new query builder instance for the connection. */
|
||||
QSharedPointer<QueryBuilder> newBaseQueryBuilder() const;
|
||||
std::shared_ptr<QueryBuilder> newBaseQueryBuilder() const;
|
||||
|
||||
/* Operations on a model instance */
|
||||
/*! Perform the actual delete query on this model instance. */
|
||||
@@ -736,7 +736,7 @@ namespace Orm::Tiny
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::newModelQuery()
|
||||
{
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
const auto query = newBaseQueryBuilder();
|
||||
|
||||
/* Model is passed to the TinyBuilder ctor, because of that setModel()
|
||||
@@ -755,7 +755,7 @@ namespace Orm::Tiny
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
std::unique_ptr<TinyBuilder<Derived>>
|
||||
Model<Derived, AllRelations...>::newTinyBuilder(
|
||||
const QSharedPointer<QueryBuilder> &query)
|
||||
const std::shared_ptr<QueryBuilder> &query)
|
||||
{
|
||||
return std::make_unique<TinyBuilder<Derived>>(query, model());
|
||||
}
|
||||
@@ -965,7 +965,7 @@ namespace Orm::Tiny
|
||||
/* Model Instance methods */
|
||||
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
Model<Derived, AllRelations...>::newBaseQueryBuilder() const
|
||||
{
|
||||
return getConnection().query();
|
||||
|
||||
@@ -155,14 +155,14 @@ namespace Orm::Tiny::Relations
|
||||
bool exists = false) const;
|
||||
|
||||
/*! Create a new query builder for the pivot table. */
|
||||
QSharedPointer<QueryBuilder> newPivotQuery() const;
|
||||
std::shared_ptr<QueryBuilder> newPivotQuery() const;
|
||||
/*! Get a new plain query builder for the pivot table. */
|
||||
QSharedPointer<QueryBuilder> newPivotStatement() const;
|
||||
std::shared_ptr<QueryBuilder> newPivotStatement() const;
|
||||
/*! Get a new pivot statement for a given "other" / "related" ID. */
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
newPivotStatementForId(const QVector<QVariant> &ids) const;
|
||||
/*! Get a new pivot statement for a given "other" / "related" ID. */
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
inline newPivotStatementForId(const QVariant &id) const;
|
||||
|
||||
/* TinyBuilder proxy methods */
|
||||
@@ -838,10 +838,10 @@ namespace Orm::Tiny::Relations
|
||||
}
|
||||
|
||||
template<class Model, class Related, class PivotType>
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
BelongsToMany<Model, Related, PivotType>::newPivotQuery() const
|
||||
{
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
auto query = newPivotStatement();
|
||||
|
||||
// FEATURE relations, add support for BelongsToMany::where/whereIn/whereNull silverqx
|
||||
@@ -860,7 +860,7 @@ namespace Orm::Tiny::Relations
|
||||
}
|
||||
|
||||
template<class Model, class Related, class PivotType>
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
BelongsToMany<Model, Related, PivotType>::newPivotStatement() const
|
||||
{
|
||||
auto query = this->m_query->getQuery().newQuery();
|
||||
@@ -871,11 +871,11 @@ namespace Orm::Tiny::Relations
|
||||
}
|
||||
|
||||
template<class Model, class Related, class PivotType>
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
BelongsToMany<Model, Related, PivotType>::newPivotStatementForId(
|
||||
const QVector<QVariant> &ids) const
|
||||
{
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
auto query = newPivotQuery();
|
||||
|
||||
query->whereIn(m_relatedPivotKey, ids);
|
||||
@@ -884,7 +884,7 @@ namespace Orm::Tiny::Relations
|
||||
}
|
||||
|
||||
template<class Model, class Related, class PivotType>
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
BelongsToMany<Model, Related, PivotType>::newPivotStatementForId(
|
||||
const QVariant &id) const
|
||||
{
|
||||
@@ -1400,7 +1400,7 @@ namespace Orm::Tiny::Relations
|
||||
{
|
||||
QVector<QVariant> ids;
|
||||
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
auto query = newPivotQuery()->get({m_relatedPivotKey});
|
||||
|
||||
while (query.next())
|
||||
@@ -1841,7 +1841,7 @@ namespace Orm::Tiny::Relations
|
||||
affected = detachUsingCustomClass(ids);
|
||||
|
||||
else {
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
auto query = newPivotQuery();
|
||||
|
||||
/* If associated IDs were passed to the method we will only delete those
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Orm::Tiny
|
||||
|
||||
public:
|
||||
/*! Constructor. */
|
||||
Builder(const QSharedPointer<QueryBuilder> &query, Model &model);
|
||||
Builder(const std::shared_ptr<QueryBuilder> &query, Model &model);
|
||||
|
||||
/*! Get the SQL representation of the query. */
|
||||
inline QString toSql() const;
|
||||
@@ -158,8 +158,8 @@ namespace Orm::Tiny
|
||||
/*! Get the underlying query builder instance. */
|
||||
inline QueryBuilder &getQuery() const;
|
||||
// TODO now fix revisit silverqx
|
||||
/*! Get the underlying query builder instance as a QSharedPointer. */
|
||||
inline const QSharedPointer<QueryBuilder> &
|
||||
/*! Get the underlying query builder instance as a std::shared_ptr. */
|
||||
inline const std::shared_ptr<QueryBuilder> &
|
||||
getQuerySharedPointer() const;
|
||||
|
||||
/*! Get a database connection. */
|
||||
@@ -204,7 +204,7 @@ namespace Orm::Tiny
|
||||
// Args &&...parameters);
|
||||
|
||||
/*! The base query builder instance. */
|
||||
const QSharedPointer<QueryBuilder> m_query;
|
||||
const std::shared_ptr<QueryBuilder> m_query;
|
||||
/* This can't be a reference because the model is created on the stack
|
||||
in Model::query(), then copied here and the original is destroyed
|
||||
immediately. */
|
||||
@@ -215,7 +215,7 @@ namespace Orm::Tiny
|
||||
};
|
||||
|
||||
template<typename Model>
|
||||
Builder<Model>::Builder(const QSharedPointer<QueryBuilder> &query,
|
||||
Builder<Model>::Builder(const std::shared_ptr<QueryBuilder> &query,
|
||||
Model &model)
|
||||
: m_query(query)
|
||||
, m_model(model)
|
||||
@@ -690,7 +690,7 @@ namespace Orm::Tiny
|
||||
}
|
||||
|
||||
template<typename Model>
|
||||
const QSharedPointer<QueryBuilder> &
|
||||
const std::shared_ptr<QueryBuilder> &
|
||||
Builder<Model>::getQuerySharedPointer() const
|
||||
{
|
||||
return m_query;
|
||||
|
||||
@@ -425,7 +425,7 @@ namespace Tiny
|
||||
/* Others proxy methods, not added to the Model and Relation */
|
||||
/*! Add an "exists" clause to the query. */
|
||||
TinyBuilder<Model> &
|
||||
addWhereExistsQuery(const QSharedPointer<QueryBuilder> &query,
|
||||
addWhereExistsQuery(const std::shared_ptr<QueryBuilder> &query,
|
||||
const QString &condition = AND, bool nope = false);
|
||||
|
||||
/*! Merge an array of where clauses and bindings. */
|
||||
@@ -1412,7 +1412,7 @@ namespace Tiny
|
||||
template<typename Model>
|
||||
TinyBuilder<Model> &
|
||||
BuilderProxies<Model>::addWhereExistsQuery(
|
||||
const QSharedPointer<QueryBuilder> &query, const QString &condition,
|
||||
const std::shared_ptr<QueryBuilder> &query, const QString &condition,
|
||||
const bool nope)
|
||||
{
|
||||
toBase().addWhereExistsQuery(query, condition, nope);
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <QDebug>
|
||||
#include <QHash>
|
||||
#include <QMap>
|
||||
#include <QSharedPointer>
|
||||
#include <QStringList>
|
||||
#include <QTimer>
|
||||
#include <QVariant>
|
||||
|
||||
@@ -46,10 +46,10 @@ DatabaseConnection::DatabaseConnection(
|
||||
, m_hostName(getConfig(host_).value<QString>())
|
||||
{}
|
||||
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
DatabaseConnection::table(const QString &table, const QString &as)
|
||||
{
|
||||
auto builder = QSharedPointer<QueryBuilder>::create(*this, *m_queryGrammar);
|
||||
auto builder = std::make_shared<QueryBuilder>(*this, *m_queryGrammar);
|
||||
|
||||
builder->from(table, as);
|
||||
|
||||
@@ -72,9 +72,9 @@ BaseGrammar &DatabaseConnection::withTablePrefix(BaseGrammar &grammar) const
|
||||
return grammar;
|
||||
}
|
||||
|
||||
QSharedPointer<QueryBuilder> DatabaseConnection::query()
|
||||
std::shared_ptr<QueryBuilder> DatabaseConnection::query()
|
||||
{
|
||||
return QSharedPointer<QueryBuilder>::create(*this, *m_queryGrammar);
|
||||
return std::make_shared<QueryBuilder>(*this, *m_queryGrammar);
|
||||
}
|
||||
|
||||
/* Running SQL Queries */
|
||||
|
||||
@@ -83,20 +83,20 @@ DatabaseManager::create(const ConfigurationsType &configs,
|
||||
new DatabaseManager(configs, defaultConnection));
|
||||
}
|
||||
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
DatabaseManager::table(const QString &table, const QString &connection)
|
||||
{
|
||||
return this->connection(connection).table(table);
|
||||
}
|
||||
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
DatabaseManager::tableAs(const QString &table, const QString &as,
|
||||
const QString &connection)
|
||||
{
|
||||
return this->connection(connection).table(table, as);
|
||||
}
|
||||
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
DatabaseManager::query(const QString &connection)
|
||||
{
|
||||
return this->connection(connection).query();
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "orm/db.hpp"
|
||||
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include "orm/macros/likely.hpp"
|
||||
|
||||
TINYORM_BEGIN_COMMON_NAMESPACE
|
||||
@@ -138,19 +136,19 @@ DB::setReconnector(const ReconnectorType &reconnector)
|
||||
return manager().setReconnector(reconnector);
|
||||
}
|
||||
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
DB::table(const QString &table, const QString &connection)
|
||||
{
|
||||
return manager().connection(connection).table(table);
|
||||
}
|
||||
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
DB::tableAs(const QString &table, const QString &as, const QString &connection)
|
||||
{
|
||||
return manager().connection(connection).table(table, as);
|
||||
}
|
||||
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
DB::query(const QString &connection)
|
||||
{
|
||||
return manager().connection(connection).query();
|
||||
|
||||
@@ -58,12 +58,12 @@ JoinClause::orOn(const QString &first, const QString &comparison,
|
||||
return on(first, comparison, second, OR);
|
||||
}
|
||||
|
||||
QSharedPointer<Builder> JoinClause::newQuery() const
|
||||
std::shared_ptr<Builder> JoinClause::newQuery() const
|
||||
{
|
||||
return QSharedPointer<JoinClause>::create(*this, m_type, m_table);
|
||||
return std::make_shared<JoinClause>(*this, m_type, m_table);
|
||||
}
|
||||
|
||||
QSharedPointer<Builder> JoinClause::forSubQuery() const
|
||||
std::shared_ptr<Builder> JoinClause::forSubQuery() const
|
||||
{
|
||||
return Builder::newQuery();
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ Builder &Builder::fromRaw(const QString &expression, const QVector<QVariant> &bi
|
||||
Builder &Builder::where(const std::function<void(Builder &)> &callback,
|
||||
const QString &condition)
|
||||
{
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
const auto query = forNestedWhere();
|
||||
|
||||
std::invoke(callback, *query);
|
||||
@@ -750,15 +750,15 @@ Builder &Builder::setBindings(QVector<QVariant> &&bindings, const BindingType ty
|
||||
|
||||
/* Other methods */
|
||||
|
||||
// TODO next revisit QSharedPointer, after few weeks I'm pretty sure that this can/should be std::unique_pre, like in the TinyBuilder, I need to check if more instances need to save this pointer at once, if don't then I have to change it silverqx
|
||||
QSharedPointer<Builder> Builder::newQuery() const
|
||||
// TODO next revisit std::shared_ptr, after few weeks I'm pretty sure that this can/should be std::unique_pre, like in the TinyBuilder, I need to check if more instances need to save this pointer at once, if don't then I have to change it silverqx
|
||||
std::shared_ptr<Builder> Builder::newQuery() const
|
||||
{
|
||||
return QSharedPointer<Builder>::create(m_connection, m_grammar);
|
||||
return std::make_shared<Builder>(m_connection, m_grammar);
|
||||
}
|
||||
|
||||
QSharedPointer<Builder> Builder::forNestedWhere() const
|
||||
std::shared_ptr<Builder> Builder::forNestedWhere() const
|
||||
{
|
||||
// Ownership of the QSharedPointer
|
||||
// Ownership of the std::shared_ptr
|
||||
auto query = newQuery();
|
||||
|
||||
query->setFrom(m_from);
|
||||
@@ -772,7 +772,7 @@ Expression Builder::raw(const QVariant &value) const
|
||||
}
|
||||
|
||||
// TODO now, (still need to be revisited) it can be reference, shared owner will be callee, and copy will be made during m_wheres.append() silverqx
|
||||
Builder &Builder::addNestedWhereQuery(const QSharedPointer<Builder> &query,
|
||||
Builder &Builder::addNestedWhereQuery(const std::shared_ptr<Builder> &query,
|
||||
const QString &condition)
|
||||
{
|
||||
if (query->m_wheres.isEmpty())
|
||||
@@ -791,7 +791,7 @@ Builder &Builder::addNestedWhereQuery(const QSharedPointer<Builder> &query,
|
||||
|
||||
// CUR1 add whereExists() silverqx
|
||||
// CUR1 also add exists() silverqx
|
||||
Builder &Builder::addWhereExistsQuery(const QSharedPointer<Builder> &query,
|
||||
Builder &Builder::addWhereExistsQuery(const std::shared_ptr<Builder> &query,
|
||||
const QString &condition, const bool nope)
|
||||
{
|
||||
const auto type = nope ? WhereType::NOT_EXISTS : WhereType::EXISTS;
|
||||
@@ -908,20 +908,20 @@ Builder::addArrayOfWheres(const QVector<WhereColumnItem> &values,
|
||||
}, condition);
|
||||
}
|
||||
|
||||
QSharedPointer<JoinClause>
|
||||
std::shared_ptr<JoinClause>
|
||||
Builder::newJoinClause(const Builder &query, const QString &type,
|
||||
const QString &table) const
|
||||
{
|
||||
/* It has to be shared pointer, because it can not be passed down to joinInternal()
|
||||
in join() as incomplete type. */
|
||||
return QSharedPointer<JoinClause>::create(query, type, table);
|
||||
return std::make_shared<JoinClause>(query, type, table);
|
||||
}
|
||||
|
||||
QSharedPointer<JoinClause>
|
||||
std::shared_ptr<JoinClause>
|
||||
Builder::newJoinClause(const Builder &query, const QString &type,
|
||||
Expression &&table) const
|
||||
{
|
||||
return QSharedPointer<JoinClause>::create(query, type, std::move(table));
|
||||
return std::make_shared<JoinClause>(query, type, std::move(table));
|
||||
}
|
||||
|
||||
Builder &Builder::clearColumns()
|
||||
@@ -955,7 +955,7 @@ Builder::onceWithColumns(
|
||||
std::pair<QString, QVector<QVariant>>
|
||||
Builder::createSub(const std::function<void(Builder &)> &callback) const
|
||||
{
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
const auto query = forSubQuery();
|
||||
|
||||
std::invoke(callback, *query);
|
||||
@@ -1037,7 +1037,7 @@ QSqlQuery Builder::runSelect()
|
||||
}
|
||||
|
||||
Builder &Builder::joinInternal(
|
||||
QSharedPointer<JoinClause> &&join, const QString &first,
|
||||
std::shared_ptr<JoinClause> &&join, const QString &first,
|
||||
const QString &comparison, const QVariant &second, const bool where)
|
||||
{
|
||||
if (where)
|
||||
@@ -1049,7 +1049,7 @@ Builder &Builder::joinInternal(
|
||||
return joinInternal(std::move(join));
|
||||
}
|
||||
|
||||
Builder &Builder::joinInternal(QSharedPointer<JoinClause> &&join,
|
||||
Builder &Builder::joinInternal(std::shared_ptr<JoinClause> &&join,
|
||||
const std::function<void(JoinClause &)> &callback)
|
||||
{
|
||||
std::invoke(callback, *join);
|
||||
@@ -1058,7 +1058,7 @@ Builder &Builder::joinInternal(QSharedPointer<JoinClause> &&join,
|
||||
return joinInternal(std::move(join));
|
||||
}
|
||||
|
||||
Builder &Builder::joinInternal(QSharedPointer<JoinClause> &&join)
|
||||
Builder &Builder::joinInternal(std::shared_ptr<JoinClause> &&join)
|
||||
{
|
||||
// For convenience, I want to append first and afterwards add bindings
|
||||
const auto &joinRef = *join;
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
//#include <QDebug>
|
||||
#include <QHash>
|
||||
#include <QMap>
|
||||
#include <QSharedPointer>
|
||||
#include <QStringList>
|
||||
#include <QVariant>
|
||||
#include <QVector>
|
||||
|
||||
@@ -43,7 +43,7 @@ private Q_SLOTS:
|
||||
// NOLINTNEXTLINE(readability-redundant-access-specifiers)
|
||||
private:
|
||||
/*! Create QueryBuilder instance for the given connection. */
|
||||
[[nodiscard]] QSharedPointer<QueryBuilder>
|
||||
[[nodiscard]] std::shared_ptr<QueryBuilder>
|
||||
createQuery(const QString &connection) const;
|
||||
};
|
||||
|
||||
@@ -323,7 +323,7 @@ void tst_QueryBuilder::limit() const
|
||||
}
|
||||
}
|
||||
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
tst_QueryBuilder::createQuery(const QString &connection) const
|
||||
{
|
||||
return DB::connection(connection).query();
|
||||
|
||||
@@ -44,7 +44,7 @@ private Q_SLOTS:
|
||||
// NOLINTNEXTLINE(readability-redundant-access-specifiers)
|
||||
private:
|
||||
/*! Create QueryBuilder instance for the given connection. */
|
||||
[[nodiscard]] QSharedPointer<QueryBuilder>
|
||||
[[nodiscard]] std::shared_ptr<QueryBuilder>
|
||||
createQuery(const QString &connection) const;
|
||||
};
|
||||
|
||||
@@ -254,7 +254,7 @@ void tst_DatabaseConnection::transaction_Commit_Double() const
|
||||
}
|
||||
|
||||
// Clean up
|
||||
// Ownerships of the QSharedPointer<QueryBuilder>
|
||||
// Ownerships of the std::shared_ptr<QueryBuilder>
|
||||
createQuery(connection)->from("users").remove(id1);
|
||||
createQuery(connection)->from("users").remove(id2);
|
||||
}
|
||||
@@ -408,7 +408,7 @@ void tst_DatabaseConnection::transaction_Savepoints_Commit_AllSuccess() const
|
||||
|
||||
// Clean up
|
||||
while (query.next())
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
createQuery(connection)->from("users").remove(query.value(ID).value<quint64>());
|
||||
}
|
||||
|
||||
@@ -502,7 +502,7 @@ void tst_DatabaseConnection::transaction_Savepoints_Commit_OneFailed() const
|
||||
|
||||
// Clean up
|
||||
while (query.next())
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
createQuery(connection)->from("users").remove(query.value(ID).value<quint64>());
|
||||
}
|
||||
|
||||
@@ -778,7 +778,7 @@ void tst_DatabaseConnection::transaction_Savepoints_Commit_AllFailed_Double() co
|
||||
}
|
||||
}
|
||||
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
tst_DatabaseConnection::createQuery(const QString &connection) const
|
||||
{
|
||||
return DB::connection(connection).query();
|
||||
|
||||
@@ -153,7 +153,7 @@ private Q_SLOTS:
|
||||
// NOLINTNEXTLINE(readability-redundant-access-specifiers)
|
||||
private:
|
||||
/*! Create QueryBuilder instance for the given connection. */
|
||||
[[nodiscard]] QSharedPointer<QueryBuilder> createQuery() const;
|
||||
[[nodiscard]] std::shared_ptr<QueryBuilder> createQuery() const;
|
||||
|
||||
/*! Connection name used in this test case. */
|
||||
QString m_connection {};
|
||||
@@ -619,7 +619,7 @@ void tst_MySql_QueryBuilder::selectSub_QueryBuilderOverload_WithWhere() const
|
||||
{
|
||||
auto builder = createQuery();
|
||||
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
auto subQuery = createQuery();
|
||||
subQuery->from("torrents")
|
||||
.select(Raw("max(size)"))
|
||||
@@ -923,7 +923,7 @@ void tst_MySql_QueryBuilder::fromSub_QueryBuilderOverload_WithWhere() const
|
||||
{
|
||||
auto builder = createQuery();
|
||||
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
auto subQuery = createQuery();
|
||||
subQuery->from("user_sessions")
|
||||
.select({ID, NAME})
|
||||
@@ -980,7 +980,7 @@ void tst_MySql_QueryBuilder::joinSub_QueryBuilderOverload_WithWhere() const
|
||||
{
|
||||
auto builder = createQuery();
|
||||
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
auto subQuery = createQuery();
|
||||
subQuery->from("user_sessions")
|
||||
.select({"id as files_id", "user_id", NAME})
|
||||
@@ -2058,7 +2058,7 @@ void tst_MySql_QueryBuilder::remove_WithExpression() const
|
||||
QVERIFY(firstLog.boundValues.isEmpty());
|
||||
}
|
||||
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
tst_MySql_QueryBuilder::createQuery() const
|
||||
{
|
||||
return DB::connection(m_connection).query();
|
||||
|
||||
@@ -115,7 +115,7 @@ private Q_SLOTS:
|
||||
// NOLINTNEXTLINE(readability-redundant-access-specifiers)
|
||||
private:
|
||||
/*! Create QueryBuilder instance for the given connection. */
|
||||
[[nodiscard]] QSharedPointer<QueryBuilder> createQuery() const;
|
||||
[[nodiscard]] std::shared_ptr<QueryBuilder> createQuery() const;
|
||||
|
||||
/*! Connection name used in this test case. */
|
||||
QString m_connection {};
|
||||
@@ -663,7 +663,7 @@ void tst_PostgreSQL_QueryBuilder::fromSub_QueryBuilderOverload_WithWhere() const
|
||||
{
|
||||
auto builder = createQuery();
|
||||
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
auto subQuery = createQuery();
|
||||
subQuery->from("user_sessions")
|
||||
.select({ID, NAME})
|
||||
@@ -721,7 +721,7 @@ void tst_PostgreSQL_QueryBuilder::joinSub_QueryBuilderOverload_WithWhere() const
|
||||
{
|
||||
auto builder = createQuery();
|
||||
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
auto subQuery = createQuery();
|
||||
subQuery->from("user_sessions")
|
||||
.select({"id as files_id", "user_id", NAME})
|
||||
@@ -1648,7 +1648,7 @@ void tst_PostgreSQL_QueryBuilder::remove_WithExpression() const
|
||||
QVERIFY(firstLog.boundValues.isEmpty());
|
||||
}
|
||||
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
tst_PostgreSQL_QueryBuilder::createQuery() const
|
||||
{
|
||||
return DB::connection(m_connection).query();
|
||||
|
||||
@@ -114,7 +114,7 @@ private Q_SLOTS:
|
||||
// NOLINTNEXTLINE(readability-redundant-access-specifiers)
|
||||
private:
|
||||
/*! Create QueryBuilder instance for the given connection. */
|
||||
[[nodiscard]] QSharedPointer<QueryBuilder> createQuery() const;
|
||||
[[nodiscard]] std::shared_ptr<QueryBuilder> createQuery() const;
|
||||
|
||||
/*! Connection name used in this test case. */
|
||||
QString m_connection {};
|
||||
@@ -622,7 +622,7 @@ void tst_SQLite_QueryBuilder::fromSub_QueryBuilderOverload_WithWhere() const
|
||||
{
|
||||
auto builder = createQuery();
|
||||
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
auto subQuery = createQuery();
|
||||
subQuery->from("user_sessions")
|
||||
.select({ID, NAME})
|
||||
@@ -680,7 +680,7 @@ void tst_SQLite_QueryBuilder::joinSub_QueryBuilderOverload_WithWhere() const
|
||||
{
|
||||
auto builder = createQuery();
|
||||
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
auto subQuery = createQuery();
|
||||
subQuery->from("user_sessions")
|
||||
.select({"id as files_id", "user_id", NAME})
|
||||
@@ -1601,7 +1601,7 @@ void tst_SQLite_QueryBuilder::remove_WithExpression() const
|
||||
QVERIFY(firstLog.boundValues.isEmpty());
|
||||
}
|
||||
|
||||
QSharedPointer<QueryBuilder>
|
||||
std::shared_ptr<QueryBuilder>
|
||||
tst_SQLite_QueryBuilder::createQuery() const
|
||||
{
|
||||
return DB::connection(m_connection).query();
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
#ifndef TOM_MIGRATIONREPOSITORY_HPP
|
||||
#define TOM_MIGRATIONREPOSITORY_HPP
|
||||
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include <orm/connectionresolverinterface.hpp>
|
||||
|
||||
#include "tom/tomtypes.hpp"
|
||||
|
||||
class QSqlQuery;
|
||||
class QVariant;
|
||||
|
||||
TINYORM_BEGIN_COMMON_NAMESPACE
|
||||
|
||||
@@ -73,7 +74,7 @@ namespace Tom
|
||||
|
||||
protected:
|
||||
/*! Get a query builder for the migration table. */
|
||||
QSharedPointer<QueryBuilder> table() const;
|
||||
std::shared_ptr<QueryBuilder> table() const;
|
||||
|
||||
/*! Hydrate a vector of migration items from a raw QSqlQuery. */
|
||||
std::vector<MigrationItem> hydrateMigrations(QSqlQuery &query) const;
|
||||
|
||||
@@ -34,7 +34,7 @@ MigrationRepository::MigrationRepository(
|
||||
|
||||
QVector<QVariant> MigrationRepository::getRanSimple() const
|
||||
{
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
return table()
|
||||
->orderBy(batch_, ASC)
|
||||
.orderBy(migration_, ASC)
|
||||
@@ -43,7 +43,7 @@ QVector<QVariant> MigrationRepository::getRanSimple() const
|
||||
|
||||
std::vector<MigrationItem> MigrationRepository::getRan(const QString &order) const
|
||||
{
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
auto query = table()
|
||||
->orderBy(batch_, order)
|
||||
.orderBy(migration_, order)
|
||||
@@ -54,7 +54,7 @@ std::vector<MigrationItem> MigrationRepository::getRan(const QString &order) con
|
||||
|
||||
std::vector<MigrationItem> MigrationRepository::getMigrations(const int steps) const
|
||||
{
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
auto query = table()->where(batch_, GE, 1)
|
||||
.orderBy(batch_, DESC)
|
||||
.orderBy(migration_, DESC)
|
||||
@@ -66,7 +66,7 @@ std::vector<MigrationItem> MigrationRepository::getMigrations(const int steps) c
|
||||
|
||||
std::vector<MigrationItem> MigrationRepository::getLast() const
|
||||
{
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
auto query = table()->whereEq(batch_, getLastBatchNumber())
|
||||
.orderBy(migration_, DESC)
|
||||
.get();
|
||||
@@ -76,7 +76,7 @@ std::vector<MigrationItem> MigrationRepository::getLast() const
|
||||
|
||||
std::map<QString, QVariant> MigrationRepository::getMigrationBatches() const
|
||||
{
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
return table()
|
||||
->orderBy(batch_, ASC)
|
||||
.orderBy(migration_, ASC)
|
||||
@@ -85,13 +85,13 @@ std::map<QString, QVariant> MigrationRepository::getMigrationBatches() const
|
||||
|
||||
void MigrationRepository::log(const QString &file, const int batch) const
|
||||
{
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
table()->insert({{migration_, file}, {batch_, batch}});
|
||||
}
|
||||
|
||||
void MigrationRepository::deleteMigration(const quint64 id) const
|
||||
{
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
table()->deleteRow(id);
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ int MigrationRepository::getNextBatchNumber() const
|
||||
|
||||
int MigrationRepository::getLastBatchNumber() const
|
||||
{
|
||||
// Ownership of the QSharedPointer<QueryBuilder>
|
||||
// Ownership of the std::shared_ptr<QueryBuilder>
|
||||
// Will be 0 on empty migrations table
|
||||
return table()->max(batch_).value<int>();
|
||||
}
|
||||
@@ -144,7 +144,7 @@ DatabaseConnection &MigrationRepository::connection() const
|
||||
|
||||
/* protected */
|
||||
|
||||
QSharedPointer<QueryBuilder> MigrationRepository::table() const
|
||||
std::shared_ptr<QueryBuilder> MigrationRepository::table() const
|
||||
{
|
||||
return connection().table(m_table);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user