Lightweight 0.20251201.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
9namespace Lightweight
10{
11
12/// @brief Query builder for building DELETE FROM ... queries.
13///
14/// @ingroup QueryBuilder
15class LIGHTWEIGHT_API SqlDeleteQueryBuilder final: public SqlWhereClauseBuilder<SqlDeleteQueryBuilder>
16{
17 public:
18 explicit SqlDeleteQueryBuilder(SqlQueryFormatter const& formatter, std::string table, std::string tableAlias) noexcept:
19 SqlWhereClauseBuilder<SqlDeleteQueryBuilder> {},
20 m_formatter { formatter }
21 {
22 m_searchCondition.tableName = std::move(table);
23 m_searchCondition.tableAlias = std::move(tableAlias);
24 }
25
26 SqlSearchCondition& SearchCondition() noexcept // NOLINT(bugprone-derived-method-shadowing-base-method)
27 {
28 return m_searchCondition;
29 }
30
31 // clang-format off
32 [[nodiscard]] SqlQueryFormatter const& Formatter() const noexcept // NOLINT(bugprone-derived-method-shadowing-base-method)
33 {
34 // clang-format on
35 return m_formatter;
36 }
37
38 // Finalizes building the query as DELETE FROM ... query.
39 [[nodiscard]] std::string ToSql() const;
40
41 private:
42 SqlQueryFormatter const& m_formatter;
43 SqlSearchCondition m_searchCondition;
44};
45
46inline LIGHTWEIGHT_FORCE_INLINE std::string SqlDeleteQueryBuilder::ToSql() const
47{
48 return m_formatter.Delete(m_searchCondition.tableName,
49 m_searchCondition.tableAlias,
50 m_searchCondition.tableJoins,
51 m_searchCondition.condition);
52}
53
54} // namespace Lightweight
Query builder for building DELETE FROM ... queries.
Definition Delete.hpp:16
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.