userver: userver/storages/postgres/null.hpp Source File
Loading...
Searching...
No Matches
null.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/postgres/null.hpp
4/// @brief NULL type
5
6#include <userver/storages/postgres/io/nullable_traits.hpp>
7#include <userver/storages/postgres/io/traits.hpp>
8#include <userver/storages/postgres/io/type_mapping.hpp>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace storages::postgres {
13
14/// @brief Type to represent a null value
15template <typename T>
16struct Null {};
17
18/// @brief Template variable to use with query parameters.
19/// @code
20/// trx->Execute("update a_table set val = $1 where val = $2", null<int>, 0)
21/// @endcode
22template <typename T>
23inline constexpr Null<T> null{};
24
25namespace io {
26namespace traits {
27
28template <typename T>
29struct IsNullable<Null<T>> : std::true_type {};
30
31template <typename T>
32struct GetSetNull<Null<T>> {
33 inline static bool IsNull(const Null<T>&) { return true; }
34 static void SetNull(T&) {}
35};
36
37template <typename T>
39template <typename T>
41
42} // namespace traits
43
44template <typename T>
45struct CppToPg<Null<T>> : CppToPg<T> {};
46
47template <typename T>
49 explicit BufferFormatter(const Null<T>&) {}
50
51 template <typename Buffer>
52 void operator()(const UserTypes&, Buffer&) const {}
53};
54
55} // namespace io
56
57} // namespace storages::postgres
58
59USERVER_NAMESPACE_END