Lightweight 0.20250904.0
Loading...
Searching...
No Matches
SqlText.hpp
1// SPDX-License-Identifier: Apache-2.0
2
3#pragma once
4
5#include "../SqlColumnTypeDefinitions.hpp"
6#include "Core.hpp"
7#include "StdString.hpp"
8
9#include <string>
10
11namespace Lightweight
12{
13
14/// Represents a TEXT field in a SQL database.
15///
16/// This is used for large texts, e.g. up to 65k characters.
17///
18/// @ingroup DataTypes
19struct SqlText
20{
21 using value_type = std::string;
22
23 value_type value;
24
25 std::weak_ordering operator<=>(SqlText const&) const noexcept = default;
26};
27
28template <>
29struct SqlBasicStringOperations<SqlText>
30{
31 using Traits = SqlBasicStringOperations<typename SqlText::value_type>;
32
33 static constexpr auto ColumnType = SqlColumnTypeDefinitions::Text {};
34
35 // clang-format off
36 static LIGHTWEIGHT_FORCE_INLINE char const* Data(SqlText const* str) noexcept { return Traits::Data(&str->value); }
37 static LIGHTWEIGHT_FORCE_INLINE char* Data(SqlText* str) noexcept { return Traits::Data(&str->value); }
38 static LIGHTWEIGHT_FORCE_INLINE SQLULEN Size(SqlText const* str) noexcept { return Traits::Size(&str->value); }
39 static LIGHTWEIGHT_FORCE_INLINE void Clear(SqlText* str) noexcept { Traits::Clear(&str->value); }
40 static LIGHTWEIGHT_FORCE_INLINE void Reserve(SqlText* str, size_t capacity) noexcept { Traits::Reserve(&str->value, capacity); }
41 static LIGHTWEIGHT_FORCE_INLINE void Resize(SqlText* str, SQLLEN indicator) noexcept { Traits::Resize(&str->value, indicator); }
42 // clang-format on
43};
44
45} // namespace Lightweight
46
47template <>
48struct std::formatter<Lightweight::SqlText>: std::formatter<std::string>
49{
50 LIGHTWEIGHT_FORCE_INLINE auto format(Lightweight::SqlText const& text, format_context& ctx) const
51 -> format_context::iterator
52 {
53 return std::formatter<std::string>::format(text.value, ctx);
54 }
55};