11#include "syscache.hpp"
17 bool is(
const type &t) {
return t.oid == VOIDOID; }
18 constexpr type type_for() {
return type{.oid = VOIDOID}; }
22 static bool is(
const type &t) {
return t.oid == OIDOID; }
23 static constexpr type type_for() {
return type{.oid = OIDOID}; }
26template <
typename S>
struct type_traits<S, std::enable_if_t<utils::is_std_tuple<S>::value>> {
27 bool is(
const type &t) {
28 if (t.oid == RECORDOID) {
30 }
else if constexpr (std::tuple_size_v<S> == 1) {
36 constexpr type type_for() {
return type{.oid = RECORDOID}; }
42 bool is(
const type &t) {
return t.oid == BOOLOID; }
43 constexpr type type_for() {
return type{.oid = BOOLOID}; }
49 bool is(
const type &t) {
return t.oid == INT8OID || t.oid == INT4OID || t.oid == INT2OID; }
50 constexpr type type_for() {
return type{.oid = INT8OID}; }
56 bool is(
const type &t) {
return t.oid == INT4OID || t.oid == INT2OID; }
57 constexpr type type_for() {
return type{.oid = INT4OID}; }
63 bool is(
const type &t) {
return t.oid == INT2OID; }
64 constexpr type type_for() {
return type{.oid = INT2OID}; }
70 bool is(
const type &t) {
return t.oid == INT2OID; }
71 constexpr type type_for() {
return type{.oid = INT2OID}; }
77 bool is(
const type &t) {
return t.oid == FLOAT8OID || t.oid == FLOAT4OID; }
78 constexpr type type_for() {
return type{.oid = FLOAT8OID}; }
84 bool is(
const type &t) {
return t.oid == FLOAT4OID; }
85 constexpr type type_for() {
return type{.oid = FLOAT4OID}; }
91 bool is(
const type &t) {
return t.oid == TEXTOID; }
92 constexpr type type_for() {
return type{.oid = TEXTOID}; }
98 bool is(
const type &t) {
return t.oid == TEXTOID; }
99 constexpr type type_for() {
return type{.oid = TEXTOID}; }
105 bool is(
const type &t) {
return t.oid == TEXTOID; }
106 constexpr type type_for() {
return type{.oid = TEXTOID}; }
112 bool is(
const type &t) {
return t.oid == BYTEAOID; }
113 constexpr type type_for() {
return type{.oid = BYTEAOID}; }
119 bool is(
const type &t) {
return t.oid == BYTEAOID; }
120 constexpr type type_for() {
return type{.oid = BYTEAOID}; }
126 bool is(
const type &t) {
return t.oid == CSTRINGOID; }
127 constexpr type type_for() {
return type{.oid = CSTRINGOID}; }
133 bool is(
const type &t) {
return t.oid == CSTRINGOID; }
134 constexpr type type_for() {
return type{.oid = CSTRINGOID}; }
140 bool is(
const type &t) {
return t.oid == CSTRINGOID; }
141 constexpr type type_for() {
return type{.oid = CSTRINGOID}; }
147 bool is(
const type &t) {
return t.oid == F::type().oid; }
148 constexpr type type_for() {
return F::type(); }
167 return static_cast<oid>(d.operator const ::Datum &());
175 return static_cast<size_t>(d.operator const ::Datum &());
183 return static_cast<int64_t
>(d.operator const ::Datum &());
191 return static_cast<int32_t
>(d.operator const ::Datum &());
198 return static_cast<int16_t
>(d.operator const ::Datum &());
205 return static_cast<bool>(d.operator const ::Datum &());
212 return static_cast<double>(d.operator const ::Datum &());
220 return static_cast<float>(d.operator const ::Datum &());
237 return bytea{d, ctx};
244 static byte_array
from_datum(
const datum &d,
oid, std::optional<memory_context> ctx) {
245 return bytea{d, ctx};
264 size_t sz = t.size();
265 void *result =
ffi_guard{::palloc}(sz + VARHDRSZ);
266 SET_VARSIZE(result, t.size() + VARHDRSZ);
267 memcpy(VARDATA(result), t.data(), sz);
268 return datum(
reinterpret_cast<::Datum
>(result));
284 static const char *from_datum(
const datum &d,
oid, std::optional<memory_context> ctx) {
285 return DatumGetPointer(d);
288 static datum into_datum(
const char *
const &t) {
return datum(PointerGetDatum(t)); }
292 static const char *
from_datum(
const datum &d,
oid, std::optional<memory_context> ctx) {
293 return DatumGetPointer(d);
299template <
typename T>
struct datum_conversion<T, std::enable_if_t<expanded_varlena_type<T>>> {
300 static T
from_datum(
const datum &d,
oid, std::optional<memory_context> ctx) {
return {d, ctx}; }
325 :
type({.oid = ([&]() {
328 if (OidIsValid(nsoid)) {
330 TYPENAMENSP, std::string(
name).c_str(), nsoid))
A trait to convert from and into a cppgres::datum.
Definition: datum.hpp:115
static T from_datum(const datum &, const oid, std::optional< memory_context > context=std::nullopt)=delete
Convert from a datum.
static datum into_datum(const T &d)=delete
Convert datum into a type.
Definition: memory.hpp:61
Type identified by its name.
Definition: types.hpp:311
named_type(const std::string_view schema, const std::string_view name)
Type identified by a qualified name.
Definition: types.hpp:324
named_type(const std::string_view name)
Type identified by an unqualified name.
Definition: types.hpp:317
Definition: syscache.hpp:26
Postgres type.
Definition: type.hpp:20