Module dream_postgres_driver

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() = {dream_postgres_driver_error, #{error_field() => binary()}} | pg_types:encoding_error()

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(), type_info = tuple(), 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(), include_statement_span_attribute => boolean(), queue => boolean(), decode_opts => [decode_option()], pool_options => [pool_option()]}

pgsql_format()

pgsql_format() = text | binary

pool()

pool() = atom()

pool_config()

pool_config() = #{host => string(), port => integer(), user => string(), password => string() | fun(() -> iodata()), database => string(), application_name => atom() | iodata(), pool_size => integer(), queue_target => integer(), queue_interval => integer(), idle_interval => integer(), socket_options => [gen_tcp:connect_option()], queue => boolean(), trace => boolean(), decode_opts => [decode_option()], extra => term()} | [{atom(), string() | integer() | boolean()}]

pool_option()

pool_option() = queue | {queue, boolean()} | {timeout, timeout()} | {deadline, integer()}

result()

result() = #{command := atom(), num_rows := non_neg_integer() | table, rows := [row()]} | {error, error()} | {error, any()}

row()

row() = tuple() | 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
conn_extra/1Returns the extra value of the pool that the connection is from, or undefined if the pool config has no extra.
format_error/1
query/1Equivalent to query(Query, [], #{}).
query/2Equivalent to query(Query, Params, #{}).
query/3Executes an extended query either on a Pool or a provided connection.
query/4
start_pool/2Starts connection pool as a child of dream_postgres_driver_sup.
transaction/1Equivalent to transaction(dream_postgres_driver_default, Fun, #{}).
transaction/2Equivalent to transaction(dream_postgres_driver_default, Fun, Options).
transaction/3Runs a function, passing it a connection, in a SQL transaction.
with_conn/2

Function Details

break/1

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

Disconnects the socket held by this reference.

checkin/2

checkin(Ref::dream_postgres_driver_pool:ref(), Conn::dream_postgres_driver_pool:conn()) -> ok

Return a checked out connection to its pool

checkout/1

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

Returns a connection from the pool.

checkout/2

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

conn_extra/1

conn_extra(Conn::dream_postgres_driver_pool:conn()) -> term()

Returns the extra value of the pool that the connection is from, or undefined if the pool config has no extra.

format_error/1

format_error(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.

query/4

query(Query, Params, Options, Conn) -> any()

start_pool/2

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

Starts connection pool as a child of dream_postgres_driver_sup.

transaction/1

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

Equivalent to transaction(dream_postgres_driver_default, Fun, #{}).

transaction/2

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

Equivalent to transaction(dream_postgres_driver_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