Module epgsql_binary

Interface to encoder/decoder for binary postgres data representation.

See also: epgsql_codec, epgsql_wire.

Description

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:
  1. 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 columns
  2. decode/2 is used to decode binary data to Erlang structures using decoder() structure
Encoding, on other hand, is normally only done once (you only encode placeholder parameters once for each query), so, it's done in one step using encode/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.

Data Types

codec()

abstract datatype: codec()

decoder()

abstract datatype: decoder()

encoder()

abstract datatype: encoder()

maybe_unknown_type()

maybe_unknown_type() = type() | {unknown_oid, epgsql_oid_db:oid()}

nulls()

nulls() = [any(), ...]

opts()

opts() = #{nulls => nulls()}

type()

type() = epgsql:type_name() | {array, epgsql:type_name()}

Function Index

decode/2decode single cell.
decode_array/3
decode_record/3
encode/2Encodes Erlang value to Postgres binary with prepared encoder().
encode/3Convert Erlang value to PG binary of type, specified by type name.
is_null/2Returns true if Value is a term representing NULL
new_codec/2
null/1Return the value that represents NULL (1st element of nulls list).
oid_to_decoder/3generate decoder to decode PG binary of datatype specified as OID.
oid_to_info/2
oid_to_name/2
supports/2
type_to_encoder/2Prepare 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

Function Details

decode/2

decode(Bin::binary(), X2::decoder()) -> any()

decode single cell

decode_array/3

decode_array(X1, X2, ArrayDecoder) -> any()

decode_record/3

decode_record(X1, X2, Codec) -> any()

encode/2

encode(Array::epgsql:bind_param(), X2::encoder()) -> iodata()

Encodes Erlang value to Postgres binary with prepared encoder()

See also: type_to_encoder/2.

encode/3

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/2

is_null(Value::any(), Codec::codec()) -> boolean()

Returns true if Value is a term representing NULL

new_codec/2

new_codec(PgSock::epgsql_sock:pg_sock(), Opts::opts()) -> codec()

null/1

null(Codec::codec()) -> any()

Return the value that represents NULL (1st element of nulls list)

oid_to_decoder/3

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/2

oid_to_info(Oid::epgsql_oid_db:oid(), Codec::codec()) -> epgsql_oid_db:type_info() | undefined

oid_to_name/2

oid_to_name(Oid::epgsql_oid_db:oid(), Codec::codec()) -> maybe_unknown_type()

supports/2

supports(RecOid, Codec) -> any()

type_to_encoder/2

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

To be used with encode/2. It only makes sense when you need to encode same PG type many times. Otherwise see encode/3

type_to_oid/2

type_to_oid(Name::type(), Codec::codec()) -> epgsql_oid_db:oid()

typeinfo_to_name_array/2

typeinfo_to_name_array(Unknown::Unknown | epgsql_oid_db:type_info(), X2::term()) -> Unknown | type()

typeinfo_to_oid_info/2

typeinfo_to_oid_info(Unknown::Unknown | epgsql_oid_db:type_info(), X2::term()) -> Unknown | epgsql_oid_db:oid_info()

update_codec/2

update_codec(TypeInfos::[epgsql_oid_db:type_info()], Codec::codec()) -> codec()


Generated by EDoc