Copyright © 2009-2021 Marc Worrell
Authors: Marc Worrell (marc@worrell.nl).
id() = pos_integer()
parameter() = tuple() | calendar:datetime() | atom() | string() | binary() | integer() | boolean() | float() | list()
parameters() = [parameter()]
prop_key() = binary() | atom()
props() = proplists:proplist() | props_map()
props_map() = #{prop_key() => term()}
qmap_option() = {keys, binary | atom} | {timeout, non_neg_integer()}
qmap_options() = [qmap_option()]
query_error() = nodb | enoent | epgsql:query_error() | term()
query_result() = {ok, Columns::list(), Rows::list()} | {ok, Count::non_neg_integer(), Columns::list(), Rows::list()} | {ok, Count::non_neg_integer()} | {error, term()}
query_timeout() = integer()
schema_name() = default | atom() | string()
sql() = string() | iodata()
table_name() = atom() | string()
transaction_fun() = fun((z:context()) -> term())
assert_table_name/1 | Check if a name is a valid SQL table name. |
assoc/2 | Return property lists of the results of a query on the database in the Context. |
assoc/3 | |
assoc/4 | |
assoc_props/2 | |
assoc_props/3 | |
assoc_props/4 | |
assoc_props_row/2 | |
assoc_props_row/3 | |
assoc_row/2 | |
assoc_row/3 | |
column/3 | |
column_names/2 | Return a list with the column names of a table. |
column_names_bin/2 | |
columns/2 | Return a property list with all columns of the table. |
create_table/3 | Ensure that a table with the given columns exists, alter any existing table to add, modify or drop columns. |
delete/3 | Delete a row from a table, the row must have a column with the name 'id'. |
drop_schema/1 | |
drop_table/2 | Make sure that a table is dropped, only when the table exists. |
ensure_database/2 | |
ensure_schema/2 | |
equery/2 | |
equery/3 | |
equery/4 | |
flush/1 | Flush all cached information about the database. |
get_current_props/3 | |
has_connection/1 | Check if we have database connection up and runnng. |
insert/2 | Insert a new row in a table, use only default values. |
insert/3 | Insert a row, setting the fields to the props. |
prepare_cols/2 | Check if all cols are valid columns in the target table, move unknown properties to the props column (if exists). |
prepare_database/1 | Create database and schema if they do not yet exist. |
q/2 | |
q/3 | |
q/4 | |
q1/2 | |
q1/3 | |
q1/4 | |
q_row/2 | |
q_row/3 | |
qmap/2 | |
qmap/3 | |
qmap/4 | |
qmap_props/2 | |
qmap_props/3 | |
qmap_props/4 | |
qmap_props_row/2 | |
qmap_props_row/3 | |
qmap_props_row/4 | |
qmap_row/2 | |
qmap_row/3 | |
qmap_row/4 | |
quoted_table_name/1 | |
schema_exists_conn/2 | Check whether schema exists. |
select/3 | Read a row from a table, the row must have a column with the name 'id'. |
squery/2 | |
squery/3 | |
table_exists/2 | Check the information schema if a certain table exists in the context database. |
transaction/2 | Perform a function inside a transaction, do a rollback on exceptions. |
transaction/3 | Perform a transaction with extra options. |
transaction_clear/1 | Clear any transaction in the context, useful when starting a thread with this context. |
update/4 | Update a row in a table, merging the props list with any new props values. |
update_sequence/3 | Update the sequence of the ids in the table. |
assert_table_name(A::table_name()) -> true
Check if a name is a valid SQL table name. Crashes when invalid
assoc(Sql::sql(), Context::z:context()) -> [proplists:proplist()]
Return property lists of the results of a query on the database in the Context
assoc(Sql::sql(), Parameters::list(), Context::z:context()) -> [proplists:proplist()]
assoc(Sql::sql(), Parameters::list(), Context::z:context(), Timeout::integer()) -> [proplists:proplist()]
assoc_props(Sql::sql(), Context::z:context()) -> [proplists:proplist()]
assoc_props(Sql::sql(), Parameters::list(), Context::z:context()) -> [proplists:proplist()]
assoc_props(Sql::sql(), Parameters::list(), Context::z:context(), Timeout::integer()) -> [proplists:proplist()]
assoc_props_row(Sql::string(), Context::z:context()) -> proplists:proplist() | undefined
assoc_props_row(Sql::string(), Parameters::list(), Context::z:context()) -> proplists:proplist() | undefined
assoc_row(Sql::string(), Context::z:context()) -> proplists:proplist()
assoc_row(Sql::string(), Parameters::parameters(), Context::z:context()) -> proplists:proplist() | undefined
column(Table::table_name(), Column::atom() | string(), Context::z:context()) -> {ok, #column_def{}} | {error, enoent}
column_names(Table::table_name(), Context::z:context()) -> [atom()]
Return a list with the column names of a table. The names are sorted.
column_names_bin(Table::table_name(), Context::z:context()) -> [binary()]
columns(Table::table_name(), Context::z:context()) -> [#column_def{}]
Return a property list with all columns of the table. (example: [{id,int4,modifier},...])
create_table(Table::table_name(), Cols::list(), Context::z:context()) -> ok
Ensure that a table with the given columns exists, alter any existing table to add, modify or drop columns. The 'id' (with type serial) column _must_ be defined when creating the table.
delete(Table::table_name(), Id::integer(), Context::z:context()) -> {ok, RowsDeleted::non_neg_integer()} | {error, term()}
Delete a row from a table, the row must have a column with the name 'id'
drop_schema(Context) -> any()
drop_table(Table::table_name(), Context::z:context()) -> ok
Make sure that a table is dropped, only when the table exists
ensure_database(Site, Options) -> any()
ensure_schema(Site, Options) -> any()
equery(Sql, Context) -> any()
equery(Sql, Parameters, Context) -> any()
equery(Sql::sql(), Parameters::parameters(), Context::z:context(), Timeout::integer()) -> query_result()
flush(Context) -> any()
Flush all cached information about the database.
get_current_props(Table, Id, Context) -> any()
has_connection(Site::z:context() | atom()) -> boolean()
Check if we have database connection up and runnng
insert(Table::table_name(), Context::z:context()) -> {ok, pos_integer() | undefined} | {error, term()}
Insert a new row in a table, use only default values.
insert(Table::table_name(), Parameters::props(), Context::z:context()) -> {ok, integer() | undefined} | {error, term()}
Insert a row, setting the fields to the props. Unknown columns are serialized in the props column. When the table has an 'id' column then the new id is returned.
prepare_cols(Cols, Props) -> any()
Check if all cols are valid columns in the target table, move unknown properties to the props column (if exists).
prepare_database(Context::z:context()) -> ok | {error, term()}
Create database and schema if they do not yet exist
q(Sql, Context) -> any()
q(Sql, Parameters, Context) -> any()
q(Sql, Parameters, Context, Timeout) -> any()
q1(Sql, Context) -> any()
q1(Sql, Parameters, Context) -> any()
q1(Sql::sql(), Parameters::parameters(), Context::#context{}, Timeout::pos_integer()) -> term() | undefined
q_row(Sql, Context) -> any()
q_row(Sql, Args, Context) -> any()
qmap(Sql::sql(), Context::z:context()) -> {ok, [map()]} | {error, query_error()}
qmap(Sql::sql(), Args::parameters(), Context::z:context()) -> {ok, [map()]} | {error, query_error()}
qmap(Sql::sql(), Args::parameters(), Options::qmap_options(), Context::z:context()) -> {ok, [map()]} | {error, query_error()}
qmap_props(Sql::sql(), Context::z:context()) -> {ok, [map()]} | {error, query_error()}
qmap_props(Sql::sql(), Args::parameters(), Context::z:context()) -> {ok, [map()]} | {error, query_error()}
qmap_props(Sql::sql(), Args::parameters(), Options::list(), Context::z:context()) -> {ok, [map()]} | {error, query_error()}
qmap_props_row(Sql::sql(), Context::z:context()) -> {ok, map()} | {error, query_error()}
qmap_props_row(Sql::sql(), Args::parameters(), Context::z:context()) -> {ok, map()} | {error, query_error()}
qmap_props_row(Sql::sql(), Args::parameters(), Options::qmap_options(), Context::z:context()) -> {ok, map()} | {error, query_error()}
qmap_row(Sql::sql(), Context::z:context()) -> {ok, map()} | {error, query_error()}
qmap_row(Sql::sql(), Args::parameters(), Context::z:context()) -> {ok, map()} | {error, query_error()}
qmap_row(Sql::sql(), Args::parameters(), Options::qmap_options(), Context::z:context()) -> {ok, map()} | {error, query_error()}
quoted_table_name(TableName::table_name()) -> {default | string(), string(), string()}
schema_exists_conn(Connection::epgsql:connection(), Schema::string()) -> boolean()
Check whether schema exists
select(Table::table_name(), Id::any(), Context::z:context()) -> {ok, Row::map()} | {error, term()}
Read a row from a table, the row must have a column with the name 'id'. The props column contents is merged with the other properties returned.
squery(Sql, Context) -> any()
squery(Sql, Context, Timeout) -> any()
table_exists(Table::table_name(), Context::z:context()) -> boolean()
Check the information schema if a certain table exists in the context database.
transaction(Function::transaction_fun(), Context::z:context()) -> any() | {error, term()}
Perform a function inside a transaction, do a rollback on exceptions
transaction(Function::transaction_fun(), Options::list(), Context::z:context()) -> any() | {error, term()}
Perform a transaction with extra options. Default retry on deadlock
transaction_clear(Context) -> any()
Clear any transaction in the context, useful when starting a thread with this context.
update(Table::table_name(), Id::id(), Parameters::props(), Context::z:context()) -> {ok, RowsUpdated::integer()} | {error, term()}
Update a row in a table, merging the props list with any new props values
update_sequence(Table::table_name(), Ids::[integer()], Context::z:context()) -> any()
Update the sequence of the ids in the table. They will be renumbered according to their position in the id list.
Generated by EDoc