Module erlydb_psql

This module implements the Postgresql driver for ErlyDB.

Copyright © Roberto Saccon 2007

Authors: Roberto Saccon (rsaccon@gmail.com).

Description

This module implements the Postgresql driver for ErlyDB.

Based on code initially developed by Brian Olson, see (http://groups.google.com/group/erlyweb/browse_frm/thread/e1585240f790c87c)

This is an internal ErlyDB module that you normally shouldn't have to use directly.

Postgresql driver is an OTP application. Define database details and authetication credentials for the driver pool in psql.app.src and run 'make app' to crate an OTP-ish ebin/psql.app

For license information see LICENSE.txt

Function Index

get_last_insert_id/2Get the id of the last inserted record.
get_metadata/1Get the table names and fields for the database.
q/1Execute a statement directly against the PostgreSQL driver.
q/2
q2/1Execute a (binary or string) statement against the Postgresql driver using the default options.
q2/2Execute a (binary or string) statement against the MySQL driver.
select/2Execute a raw SELECT statement.
select_as/3Execute a SELECT statements for records belonging to the given module, returning all rows with additional data to support higher-level ErlyDB features.
start/0Starts the psql and sql applications up if they are not already started.
stop/0Stops the psql and sql applications.
transaction/2Models a transaction.
update/2Execute a INSERT, DELETE or UPDATE statement.

Function Details

get_last_insert_id/2

get_last_insert_id(TableName::atom(), Options::proplist()) -> term()

Get the id of the last inserted record.

get_metadata/1

get_metadata(Options) -> term()

Get the table names and fields for the database.

q/1

q(Statement) -> term()

Execute a statement directly against the PostgreSQL driver. If Options contains the value {allow_unsafe_sql, true}, binary and string queries as well as ErlSQL queries with binary and/or string expressions are accepted. Otherwise the function crashes.

q/2

q(X1, Options) -> term()

q2/1

q2(Statement::string() | binary()) -> psql_result()

Execute a (binary or string) statement against the Postgresql driver using the default options.

q2/2

q2(Statement::string() | binary(), Options::proplist()) -> psql_result()

Execute a (binary or string) statement against the MySQL driver.

select/2

select(PoolId::atom(), Statement::statement()) -> {ok, Rows::list()} | {error, Error}

Execute a raw SELECT statement.

select_as/3

select_as(Module::atom(), Statement::statement(), FixedCols::tuple()) -> {ok, Rows} | {error, Error}

Execute a SELECT statements for records belonging to the given module, returning all rows with additional data to support higher-level ErlyDB features.

start/0

start() -> term()

Starts the psql and sql applications up if they are not already started. Any errors that are returned are ignored.

stop/0

stop() -> term()

Stops the psql and sql applications.

transaction/2

transaction(Fun, Options) -> term()

Models a transaction. If an error occurs in the function provided, then the transaction will rollback. Otherwise it will commit.

update/2

update(Statement::statement(), Options::options()) -> {ok, NumAffected} | {error, Err}

Execute a INSERT, DELETE or UPDATE statement.