Lightweight 0.20260303.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 /// The underlying value type.
22 using value_type = std::string;
23
24 /// The text value.
26
27 /// Three-way comparison operator.
28 std::weak_ordering operator<=>(SqlText const&) const noexcept = default;
29};
30
31template <>
32struct SqlBasicStringOperations<SqlText>
33{
34 using Traits = SqlBasicStringOperations<SqlText::value_type>;
35
36 static constexpr auto ColumnType = SqlColumnTypeDefinitions::Text {};
37
38 // clang-format off
39 static LIGHTWEIGHT_FORCE_INLINE char const* Data(SqlText const* str) noexcept { return Traits::Data(&str->value); }
40 static LIGHTWEIGHT_FORCE_INLINE char* Data(SqlText* str) noexcept { return Traits::Data(&str->value); }
41 static LIGHTWEIGHT_FORCE_INLINE SQLULEN Size(SqlText const* str) noexcept { return Traits::Size(&str->value); }
42 static LIGHTWEIGHT_FORCE_INLINE void Clear(SqlText* str) noexcept { Traits::Clear(&str->value); }
43 static LIGHTWEIGHT_FORCE_INLINE void Reserve(SqlText* str, size_t capacity) noexcept { Traits::Reserve(&str->value, capacity); }
44 static LIGHTWEIGHT_FORCE_INLINE void Resize(SqlText* str, SQLLEN indicator) noexcept { Traits::Resize(&str->value, indicator); }
45 // clang-format on
46};
47
48} // namespace Lightweight
49
50template <>
51struct std::formatter<Lightweight::SqlText>: std::formatter<std::string>
52{
53 LIGHTWEIGHT_FORCE_INLINE auto format(Lightweight::SqlText const& text, format_context& ctx) const
54 -> format_context::iterator
55 {
56 return std::formatter<std::string>::format(text.value, ctx);
57 }
58};
value_type value
The text value.
Definition SqlText.hpp:25
std::string value_type
The underlying value type.
Definition SqlText.hpp:22
std::weak_ordering operator<=>(SqlText const &) const noexcept=default
Three-way comparison operator.