OZO 「お象」
Boost.Asio and libpq based asynchronous PostgreSQL unofficial header-only C++17 client library.

Description

Types mapping C++ to PostgreSQL.

Macros

#define OZO_PG_BIND_TYPE(CppType, PgTypeName)
 Helper macro to define type mapping between C++ type and PostgreSQL type. More...
 
#define OZO_PG_DEFINE_TYPE_AND_ARRAY(Type, Name, Oid, ArrayOid, Size)
 [[DEPRECATED]] Helper macro to define type mapping More...
 
#define OZO_PG_DEFINE_CUSTOM_TYPE(Type, Name, Size)
 Helper macro to define custom type mapping. More...
 

Macro Definition Documentation

◆ OZO_PG_BIND_TYPE

#define OZO_PG_BIND_TYPE (   CppType,
  PgTypeName 
)

Helper macro to define type mapping between C++ type and PostgreSQL type.

In general type mapping is provided via ozo::definitions::type and ozo::definitions::array specialization. The library has all the necessary information (like OID, size and so on) about built-in types of PostgreSQL. To make C++ types binding easer and reduce a boilerplate code the macro exists.

Note
This macro should be called in the global namespace only
Parameters
CppType— C++ type to be mapped to database type
PgTypeName— string with name of database type

Example

E.g. a definition of std::string as PostgreSQL text type may look like this:

#include <ozo/pg/definitions.h>
#include <string>
OZO_PG_BIND_TYPE(std::string, "text")
See also
OZO_PG_DEFINE_CUSTOM_TYPE

Known Types

Type Size Has Array Short Description
null none no OZO pseudo-type definition for null representation
aclitem 12 bytes yes access control list
any 4 bytes no pseudo-type representing any type
anyarray dynamic size no pseudo-type representing a polymorphic array type
anyelement 4 bytes no pseudo-type representing a polymorphic base type
anyenum 4 bytes no pseudo-type representing a polymorphic base type that is an enum
anynonarray 4 bytes no pseudo-type representing a polymorphic base type that is not an array
anyrange dynamic size no pseudo-type representing a polymorphic base type that is a range
bit dynamic size yes fixed-length bit string
bool 1 bytes yes boolean, 'true'/'false'
box 32 bytes yes geometric box '(lower left,upper right)'
bpchar dynamic size yes char(length), blank-padded string, fixed storage length
bytea dynamic size yes variable-length string, binary values escaped
char 1 bytes yes single character
cid 4 bytes yes command identifier type, sequence in transaction id
cidr dynamic size yes network IP address/netmask, network address
circle 24 bytes yes geometric circle '(center,radius)'
cstring dynamic size yes C-style string
date 4 bytes yes date
daterange dynamic size yes range of dates
event_trigger 4 bytes no pseudo-type for the result of an event trigger function
fdw_handler 4 bytes no pseudo-type for the result of an FDW handler function
float4 4 bytes yes single-precision floating point number, 4-byte storage
float8 8 bytes yes double-precision floating point number, 8-byte storage
gtsvector dynamic size yes GiST index internal text representation for text search
index_am_handler 4 bytes no pseudo-type for the result of an index AM handler function
inet dynamic size yes IP address/netmask, host address, netmask optional
int2 2 bytes yes -32 thousand to 32 thousand, 2-byte storage
int2vector dynamic size yes array of int2, used in system tables
int4 4 bytes yes -2 billion to 2 billion integer, 4-byte storage
int4range dynamic size yes range of integers
int8 8 bytes yes ~18 digit integer, 8-byte storage
int8range dynamic size yes range of bigints
interval 16 bytes yes @ <number> <units>, time interval
json dynamic size yes JSON stored as text
jsonb dynamic size yes Binary JSON
jsonpath dynamic size yes JSON path
language_handler 4 bytes no pseudo-type for the result of a language handler function
line 24 bytes yes geometric line
lseg 32 bytes yes geometric line segment '(pt1,pt2)'
macaddr 6 bytes yes XX:XX:XX:XX:XX:XX, MAC address
macaddr8 8 bytes yes XX:XX:XX:XX:XX:XX:XX:XX, MAC address
money 8 bytes yes monetary amounts, $d,ddd.cc
name dynamic size yes 63-byte type for storing system identifiers
numeric dynamic size yes numeric(precision, decimal), arbitrary precision number
numrange dynamic size yes range of numerics
oid 4 bytes yes object identifier(oid), maximum 4 billion
oidvector dynamic size yes array of oids, used in system tables
opaque 4 bytes no obsolete, deprecated pseudo-type
path dynamic size yes geometric path '(pt1,...)'
pg_attribute dynamic size no
pg_class dynamic size no
pg_dependencies dynamic size no multivariate dependencies
pg_lsn 8 bytes yes PostgreSQL LSN datatype
pg_mcv_list dynamic size no multivariate MCV list
pg_ndistinct dynamic size no multivariate ndistinct coefficients
pg_node_tree dynamic size no string representing an internal node tree
pg_proc dynamic size no
pg_type dynamic size no
point 16 bytes yes geometric point '(x, y)'
polygon dynamic size yes geometric polygon '(pt1,...)'
record dynamic size yes pseudo-type representing any composite type
refcursor dynamic size yes reference to cursor (portal name)
regclass 4 bytes yes registered class
regconfig 4 bytes yes registered text search configuration
regdictionary 4 bytes yes registered text search dictionary
regnamespace 4 bytes yes registered namespace
regoper 4 bytes yes registered operator
regoperator 4 bytes yes registered operator (with args)
regproc 4 bytes yes registered procedure
regprocedure 4 bytes yes registered procedure (with args)
regrole 4 bytes yes registered role
regtype 4 bytes yes registered type
table_am_handler 4 bytes no
text dynamic size yes variable-length string, no limit specified
tid 6 bytes yes (block, offset), physical location of tuple
time 8 bytes yes time of day
timestamp 8 bytes yes date and time
timestamptz 8 bytes yes date and time with time zone
timetz 12 bytes yes time of day with time zone
trigger 4 bytes no pseudo-type for the result of a trigger function
tsm_handler 4 bytes no pseudo-type for the result of a tablesample method function
tsquery dynamic size yes query representation for text search
tsrange dynamic size yes range of timestamps without time zone
tstzrange dynamic size yes range of timestamps with time zone
tsvector dynamic size yes text representation for text search
txid_snapshot dynamic size yes txid snapshot
unknown dynamic size no pseudo-type representing an undetermined type
uuid 16 bytes yes UUID datatype
varbit dynamic size yes variable-length bit string
varchar dynamic size yes varchar(length), non-blank-padded string, variable storage length
void 4 bytes no pseudo-type for the result of a function with no real result
xid 4 bytes yes transaction id
xml dynamic size yes XML content

◆ OZO_PG_DEFINE_CUSTOM_TYPE

#define OZO_PG_DEFINE_CUSTOM_TYPE (   Type,
  Name,
  Size 
)

Helper macro to define custom type mapping.

In general type mapping is provided via ozo::definitions::type and ozo::definitions::array specialization.

Note
This macro can be called in the global namespace only
Parameters
Type— C++ type to be mapped to database type
Name— string with name of database type
Size— optional parameter, bytes<N> for fixed-size type (like integer, bigint and so on), there N - size of the type in database, dynamic_type for dynamic size types (like text bytea and so on), if parameter not pointed size type will be evaluated basing on C++ type size.

Example

Definition of user defined composite type may look like this:

BOOST_FUSION_DEFINE_STRUCT((smtp), message,
(std::int64_t, id)
(std::string, from)
(std::vector<std::string>, to)
(std::optional<std::string>, subject)
(std::optional<std::string>, text)
);
//...
OZO_PG_DEFINE_CUSTOM_TYPE(smtp::message, "code.message")
See also
OZO_PG_BIND_TYPE

◆ OZO_PG_DEFINE_TYPE_AND_ARRAY

#define OZO_PG_DEFINE_TYPE_AND_ARRAY (   Type,
  Name,
  Oid,
  ArrayOid,
  Size 
)

[[DEPRECATED]] Helper macro to define type mapping

In general type mapping is provided via ozo::definitions::type and ozo::definitions::array specialization. To reduce the boilerplate code the macro exists.

Note
This macro is deprecated, use OZO_PG_BIND_TYPE instead. This macro should be called in the global namespace only.
Parameters
Type— C++ type to be mapped to database type
Name— string with name of database type
Oid— oid for built-in type and void for custom type
ArrayOid— oid for an array of built-in type and void for custom type
Sizebytes<N> for fixed-size type (like integer, bigint and so on), there N - size of the type in database, dynamic_type for dynamic size types (like text bytea and so on)
OZO_PG_DEFINE_CUSTOM_TYPE
#define OZO_PG_DEFINE_CUSTOM_TYPE(Type, Name, Size)
Helper macro to define custom type mapping.
Definition: type_traits.h:455
OZO_PG_BIND_TYPE
#define OZO_PG_BIND_TYPE(CppType, PgTypeName)
Helper macro to define type mapping between C++ type and PostgreSQL type.
Definition: definitions.h:140