Module pgo

Postgres driver and pool for Erlang.

Authors: Tristan Sloughter (t@crashfast.com).

Description

Postgres driver and pool for Erlang.

This module provides functions for interacting with a pool and querying the database.

Data Types

decode_fun()

decode_fun() = fun((row(), fields()) -> row()) | undefined

decode_option()

decode_option() = return_rows_as_maps | {return_rows_as_maps, boolean()} | column_name_as_atom | {column_name_as_atom, boolean()} | {decode_fun, decode_fun()}

error()

error() = {pgo_error, #{error_field() => binary()}}

error_field()

error_field() = severity | code | message | detail | hint | position | internal_position | internal_query | where | file | line | routine | schema | table | column | data_type | constraint | {unknown, byte()}

fields()

fields() = [#row_description_field{name = iodata(), table_oid = oid(), attr_number = integer(), data_type_oid = oid(), data_type_size = integer(), type_modifier = integer(), format = pgsql_format()}]

oid()

oid() = pos_integer()

options()

options() = #{pool => atom(), trace => boolean(), queue => boolean(), decode_opts => [decode_option()]}

pgsql_format()

pgsql_format() = text | binary

pool()

pool() = atom()

pool_config()

pool_config() = #{host => string(), port => integer(), user => string(), password => string(), database => string(), pool_size => integer(), queue_target => integer(), queue_interval => integer(), idle_interval => integer(), queue => boolean(), trace => boolean(), decode_opts => [decode_option()]}

pool_option()

pool_option() = queue | {queue, boolean()}

result()

result() = #{command := atom(), num_rows := integer(), rows := list()} | {error, error()} | {error, any()}

row()

row() = list() | map()

Function Index

break/1Disconnects the socket held by this reference.
checkin/2Return a checked out connection to its pool.
checkout/1Returns a connection from the pool.
checkout/2
query/1Equivalent to query(Query, [], #{}).
query/2Equivalent to query(Query, Params, #{}).
query/3Executes an extended query either on a Pool or a provided connection.
start_pool/2Starts connection pool as a child of pgo_sup.
transaction/1Equivalent to transaction(default, Fun, []).
transaction/2Equivalent to transaction(default, Fun, Options).
transaction/3Runs a function, passing it a connection, in a SQL transaction.
with_conn/2

Function Details

break/1

break(Conn::pgo_pool:conn()) -> ok

Disconnects the socket held by this reference.

checkin/2

checkin(Ref::pgo_pool:pool_ref(), Conn::pgo_pool:conn()) -> ok

Return a checked out connection to its pool

checkout/1

checkout(Pool::atom()) -> {ok, pgo_pool:pool_ref(), pgo_pool:conn()} | {error, any()}

Returns a connection from the pool.

checkout/2

checkout(Pool::atom(), Options::[pool_option()]) -> {ok, pgo_pool:pool_ref(), pgo_pool:conn()} | {error, any()}

query/1

query(Query::iodata()) -> result()

Equivalent to query(Query, [], #{}).

query/2

query(Query::iodata(), Params::list()) -> result()

Equivalent to query(Query, Params, #{}).

query/3

query(Query::iodata(), Params::list(), Options::options()) -> result()

Executes an extended query either on a Pool or a provided connection.

start_pool/2

start_pool(Name::pool(), PoolConfig::pool_config()) -> {ok, pid()}

Starts connection pool as a child of pgo_sup.

transaction/1

transaction(Fun::fun(() -> any())) -> any() | {error, any()}

Equivalent to transaction(default, Fun, []).

transaction/2

transaction(Fun::fun(() -> any()), Options::options()) -> any() | {error, any()}

Equivalent to transaction(default, Fun, Options).

transaction/3

transaction(Pool::pool(), Fun::fun(() -> any()), Options::options()) -> any() | {error, any()}

Runs a function, passing it a connection, in a SQL transaction.

with_conn/2

with_conn(Conn, Fun) -> any()


Generated by EDoc