Lightweight 0.1.0
Loading...
Searching...
No Matches
Delete.hpp
1// SPDX-License-Identifier: Apache-2.0
2
3#pragma once
4
5#include "Core.hpp"
6
7#include <string>
8
9/// @brief Query builder for building DELETE FROM ... queries.
10///
11/// @ingroup QueryBuilder
12class LIGHTWEIGHT_API SqlDeleteQueryBuilder final: public SqlWhereClauseBuilder<SqlDeleteQueryBuilder>
13{
14 public:
15 explicit SqlDeleteQueryBuilder(SqlQueryFormatter const& formatter,
16 std::string table,
17 std::string tableAlias) noexcept:
19 m_formatter { formatter }
20 {
21 m_searchCondition.tableName = std::move(table);
22 m_searchCondition.tableAlias = std::move(tableAlias);
23 }
24
25 SqlSearchCondition& SearchCondition() noexcept
26 {
27 return m_searchCondition;
28 }
29
30 [[nodiscard]] SqlQueryFormatter const& Formatter() const noexcept
31 {
32 return m_formatter;
33 }
34
35 // Finalizes building the query as DELETE FROM ... query.
36 [[nodiscard]] std::string ToSql() const;
37
38 private:
39 SqlQueryFormatter const& m_formatter;
40 SqlSearchCondition m_searchCondition;
41};
42
43inline LIGHTWEIGHT_FORCE_INLINE std::string SqlDeleteQueryBuilder::ToSql() const
44{
45 return m_formatter.Delete(m_searchCondition.tableName,
46 m_searchCondition.tableAlias,
47 m_searchCondition.tableJoins,
48 m_searchCondition.condition);
49}
Query builder for building DELETE FROM ... queries.
Definition Delete.hpp:13
API to format SQL queries for different SQL dialects.
virtual std::string Delete(std::string_view fromTable, std::string_view fromTableAlias, std::string_view tableJoins, std::string_view whereCondition) const =0
Constructs an SQL DELETE query.
LIGHTWEIGHT_API std::vector< std::string > ToSql(SqlQueryFormatter const &formatter, SqlMigrationPlanElement const &element)