Module z_db

Interface to database, uses database definition from Context.

Copyright 2009 Marc Worrell Date: 2009-04-07

Authors: Marc Worrell (marc@worrell.nl).

Description

Interface to database, uses database definition from Context

Function Index

assert_table_name/1Check if a name is a valid SQL table name.
assoc/2Return 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_names/2Return a list with the column names of a table.
columns/2Return a property list with all columns of the table.
create_table/3Ensure that a table with the given columns exists, alter any existing table to add, modify or drop columns.
delete/3Delete a row from a table, the row must have a column with the name 'id'.
drop_table/2Make sure that a table is dropped, only when the table exists.
equery/2
equery/3
equery/4
flush/1Flush all cached information about the database.
has_connection/1Check if we have database connection.
insert/2Insert a new row in a table, use only default values.
insert/3Insert a row, setting the fields to the props.
prepare_cols/2Check if all cols are valid columns in the target table, move unknown properties to the props column (if exists).
q/2
q/3
q/4
q1/2
q1/3
q1/4
q_row/2
q_row/3
select/3Read a row from a table, the row must have a column with the name 'id'.
squery/2
squery/3
table_exists/2Check the information schema if a certain table exists in the context database.
transaction/2Perform a function inside a transaction, do a rollback on exceptions.
transaction/3Perform a transaction with extra options.
transaction_clear/1Clear any transaction in the context, useful when starting a thread with this context.
update/4Update a row in a table, merging the props list with any new props values.
update_sequence/3Update the sequence of the ids in the table.

Function Details

assert_table_name/1

assert_table_name(T::String) -> true

Check if a name is a valid SQL table name. Crashes when invalid

assoc/2

assoc(Sql::SqlQuery, Context) -> Rows

Return property lists of the results of a query on the database in the Context

assoc/3

assoc(Sql, Parameters, Context) -> any()

assoc/4

assoc(Sql, Parameters, Context, Timeout) -> any()

assoc_props/2

assoc_props(Sql, Context) -> any()

assoc_props/3

assoc_props(Sql, Parameters, Context) -> any()

assoc_props/4

assoc_props(Sql, Parameters, Context, Timeout) -> any()

assoc_props_row/2

assoc_props_row(Sql, Context) -> any()

assoc_props_row/3

assoc_props_row(Sql, Parameters, Context) -> any()

assoc_row/2

assoc_row(Sql, Context) -> any()

assoc_row/3

assoc_row(Sql, Parameters, Context) -> any()

column_names/2

column_names(Table, Context) -> [atom()]

Return a list with the column names of a table. The names are sorted.

columns/2

columns(Table, Context) -> [#column_def{}]

Return a property list with all columns of the table. (example: [{id,int4,modifier},...])

create_table/3

create_table(Table, Cols, Context) -> any()

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

delete(Table, Id, Context) -> {ok, RowsDeleted}

Delete a row from a table, the row must have a column with the name 'id'

drop_table/2

drop_table(Name, Context) -> any()

Make sure that a table is dropped, only when the table exists

equery/2

equery(Sql, Context) -> any()

equery/3

equery(Sql, Parameters, Context) -> any()

equery/4

equery(Sql, Parameters, Context, Timeout) -> any()

flush/1

flush(Context) -> any()

Flush all cached information about the database.

has_connection/1

has_connection(Context) -> any()

Check if we have database connection

insert/2

insert(Table, Context) -> {ok, Id}

Insert a new row in a table, use only default values.

insert/3

insert(Table::atom(), Props::proplist(), Context) -> {ok, Id} | Error

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

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)

q/2

q(Sql, Context) -> any()

q/3

q(Sql, Parameters, Context) -> any()

q/4

q(Sql, Parameters, Context, Timeout) -> any()

q1/2

q1(Sql, Context) -> any()

q1/3

q1(Sql, Parameters, Context) -> any()

q1/4

q1(Sql, Parameters, Context, Timeout) -> any()

q_row/2

q_row(Sql, Context) -> any()

q_row/3

q_row(Sql, Args, Context) -> any()

select/3

select(Table, Id, Context) -> {ok, Row}

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

squery(Sql, Context) -> any()

squery/3

squery(Sql, Context, Timeout) -> any()

table_exists/2

table_exists(Table::TableName, Context) -> bool()

Check the information schema if a certain table exists in the context database.

transaction/2

transaction(Function, Context) -> FunctionResult | {error, Reason}

Perform a function inside a transaction, do a rollback on exceptions

transaction/3

transaction(Function, Options, Context) -> any()

Perform a transaction with extra options. Default retry on deadlock

transaction_clear/1

transaction_clear(Context) -> any()

Clear any transaction in the context, useful when starting a thread with this context.

update/4

update(Table, Id, Parameters, Context) -> {ok, RowsUpdated}

Update a row in a table, merging the props list with any new props values

update_sequence/3

update_sequence(Table, Ids::IdList, Context) -> void()

Update the sequence of the ids in the table. They will be renumbered according to their position in the id list.


Generated by EDoc, Sep 1 2014, 10:45:58.