-
Notifications
You must be signed in to change notification settings - Fork 40
/
field.hpp
70 lines (53 loc) · 1.58 KB
/
field.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// The Art of C++ / PostgreSQL
// Copyright (c) 2016-2018 Daniel Frey
#ifndef TAO_POSTGRES_FIELD_HPP
#define TAO_POSTGRES_FIELD_HPP
#include <tao/postgres/null.hpp>
#include <tao/postgres/result_traits.hpp>
#include <optional>
#include <type_traits>
namespace tao
{
namespace postgres
{
class row;
class field
{
private:
friend class row;
const row& row_;
const std::size_t column_;
field( const row& row, const std::size_t column )
: row_( row ),
column_( column )
{
}
public:
std::string name() const;
bool is_null() const;
const char* get() const;
template< typename T >
typename std::enable_if_t< result_traits_size< T > != 1, T > as() const
{
static_assert( !std::is_same_v< T, T >, "tao::postgres::result_traits<T>::size does not yield exactly one column for T, which is required for field access" );
__builtin_unreachable();
}
template< typename T >
typename std::enable_if_t< result_traits_size< T > == 1, T > as() const; // implemented in row.hpp
template< typename T >
std::optional< T > optional() const
{
return as< std::optional< T > >();
}
};
inline bool operator==( const field& f, const null_t& )
{
return f.is_null();
}
inline bool operator!=( const field& f, const null_t& )
{
return !f.is_null();
}
} // namespace postgres
} // namespace tao
#endif