See also: epgsql_codec, epgsql_wire.
Interface to encoder/decoder for binary postgres data representation
Because decoding is almost always done in batches (eg, query returns multiple rows of the same structure), decoding is organized in 2 phases:oid_to_decoder/3 builds an intermediate decoder() structure for a
particular column and they are organized in a list to decode a row of columnsdecode/2 is used to decode binary data to Erlang structures using
decoder() structureencode/3.
But 2-step encoder helpers also exist: type_to_encoder/2 and encode/2. They
are used by, eg, COPY .. FROM STDIN and epgsql_cmd_execute_batch.
abstract datatype: codec()
abstract datatype: decoder()
abstract datatype: encoder()
maybe_unknown_type() = type() | {unknown_oid, epgsql_oid_db:oid()}
nulls() = [any(), ...]
opts() = #{nulls => nulls()}
type() = epgsql:type_name() | {array, epgsql:type_name()}
| decode/2 | decode single cell. |
| decode_array/3 | |
| decode_record/3 | |
| encode/2 | Encodes Erlang value to Postgres binary with prepared encoder(). |
| encode/3 | Convert Erlang value to PG binary of type, specified by type name. |
| is_null/2 | Returns true if Value is a term representing NULL |
| new_codec/2 | |
| null/1 | Return the value that represents NULL (1st element of nulls list). |
| oid_to_decoder/3 | generate decoder to decode PG binary of datatype specified as OID. |
| oid_to_info/2 | |
| oid_to_name/2 | |
| supports/2 | |
| type_to_encoder/2 | Prepare encoder() structure that can convert Erlang types to PG binary. |
| type_to_oid/2 | |
| typeinfo_to_name_array/2 | |
| typeinfo_to_oid_info/2 | |
| update_codec/2 |
decode(Bin::binary(), X2::decoder()) -> any()
decode single cell
decode_array(X1, X2, ArrayDecoder) -> any()
decode_record(X1, X2, Codec) -> any()
encode(Array::epgsql:bind_param(), X2::encoder()) -> iodata()
Encodes Erlang value to Postgres binary with prepared encoder()
See also: type_to_encoder/2.
encode(TypeName::epgsql:type_name() | {array, epgsql:type_name()}, Value::epgsql:bind_param(), Codec::codec()) -> iodata()
Convert Erlang value to PG binary of type, specified by type name
is_null(Value::any(), Codec::codec()) -> boolean()
Returns true if Value is a term representing NULL
new_codec(PgSock::epgsql_sock:pg_sock(), Opts::opts()) -> codec()
null(Codec::codec()) -> any()
Return the value that represents NULL (1st element of nulls list)
oid_to_decoder(Oid::epgsql_oid_db:oid(), Format::binary | text, Codec::codec()) -> decoder()
generate decoder to decode PG binary of datatype specified as OID
oid_to_info(Oid::epgsql_oid_db:oid(), Codec::codec()) -> epgsql_oid_db:type_info() | undefined
oid_to_name(Oid::epgsql_oid_db:oid(), Codec::codec()) -> maybe_unknown_type()
supports(RecOid, Codec) -> any()
type_to_encoder(TypeName::epgsql:type_name() | {array, epgsql:type_name()}, Codec::codec()) -> encoder()
Prepare encoder() structure that can convert Erlang types to PG binary
encode/2.
It only makes sense when you need to encode same PG type many times. Otherwise see encode/3
type_to_oid(Name::type(), Codec::codec()) -> epgsql_oid_db:oid()
typeinfo_to_name_array(Unknown::Unknown | epgsql_oid_db:type_info(), X2::term()) -> Unknown | type()
Unknown = {unknown_oid, epgsql_oid_db:oid()}
typeinfo_to_oid_info(Unknown::Unknown | epgsql_oid_db:type_info(), X2::term()) -> Unknown | epgsql_oid_db:oid_info()
Unknown = {unknown_oid, epgsql_oid_db:oid()}
update_codec(TypeInfos::[epgsql_oid_db:type_info()], Codec::codec()) -> codec()
Generated by EDoc