Lightweight 0.1.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
11/// Represents a TEXT field in a SQL database.
12///
13/// This is used for large texts, e.g. up to 65k characters.
14///
15/// @ingroup DataTypes
16struct SqlText
17{
18 using value_type = std::string;
19
20 value_type value;
21
22 std::weak_ordering operator<=>(SqlText const&) const noexcept = default;
23};
24
25template <>
26struct std::formatter<SqlText>: std::formatter<std::string>
27{
28 LIGHTWEIGHT_FORCE_INLINE auto format(SqlText const& text, format_context& ctx) const -> format_context::iterator
29 {
30 return std::formatter<std::string>::format(text.value, ctx);
31 }
32};
33
34template <>
35struct SqlBasicStringOperations<SqlText>
36{
37 using Traits = SqlBasicStringOperations<typename SqlText::value_type>;
38
39 static constexpr auto ColumnType = SqlColumnTypeDefinitions::Text {};
40
41 // clang-format off
42 static LIGHTWEIGHT_FORCE_INLINE char const* Data(SqlText const* str) noexcept { return Traits::Data(&str->value); }
43 static LIGHTWEIGHT_FORCE_INLINE char* Data(SqlText* str) noexcept { return Traits::Data(&str->value); }
44 static LIGHTWEIGHT_FORCE_INLINE SQLULEN Size(SqlText const* str) noexcept { return Traits::Size(&str->value); }
45 static LIGHTWEIGHT_FORCE_INLINE void Clear(SqlText* str) noexcept { Traits::Clear(&str->value); }
46 static LIGHTWEIGHT_FORCE_INLINE void Reserve(SqlText* str, size_t capacity) noexcept { Traits::Reserve(&str->value, capacity); }
47 static LIGHTWEIGHT_FORCE_INLINE void Resize(SqlText* str, SQLLEN indicator) noexcept { Traits::Resize(&str->value, indicator); }
48 // clang-format on
49};