Module dado

Dado is a set of facilities implemented over LuaSQL connection objects.

The module's goal is to simplify the most used database operations.

Version 1.5.2.

Info:

  • Release: $Id: dado.lua,v 1.19 2013-10-12 01:32:43 tomas Exp $

Functions

assertexec (self, stmt) Executes a SQL statement raising an error if something goes wrong.
commit (self) Commits the current transaction.
rollback (self) Rolls back the current transaction.
setautocommit (self, bool) Turn autocommit mode on or off.
nextval (self, seq, field) Obtains next value from a sequence.
delete (self, tabname, cond) Deletes a row.
insert (self, tabname, contents) Inserts a new row.
update (self, tabname, contents, cond) Updates existing rows.
select (self, columns, tabname, cond, extra, mode) Retrieves rows.
selectall (self, columns, tabname, cond, extra, mode) Retrieves all rows.
wrap_connection (conn, key) Wraps a database connection into a connection object.
connect (dbname, dbuser, dbpass, driver) Tries to use a connection in the cache or opens a new one.
close (self) Closes the connection and invalidates the object.


Functions

assertexec (self, stmt)
Executes a SQL statement raising an error if something goes wrong. (it never returns nil,errmsg).

Parameters:

  • self Dado Object.
  • stmt String with SQL statement.

Returns:

    Cursor or number of rows affected by the command
commit (self)
Commits the current transaction.

Parameters:

  • self Dado Object.
rollback (self)
Rolls back the current transaction.

Parameters:

  • self Dado Object.
setautocommit (self, bool)
Turn autocommit mode on or off.

Parameters:

  • self Dado Object.
  • bool Boolean indicating to turn autocommit on (true) or off (false).
nextval (self, seq, field)
Obtains next value from a sequence. with the sequence.

Parameters:

  • self Dado Object.
  • seq String with sequence name (complete name or just the name of the table).
  • field String (optional) with the name of the primary key associated

Returns:

    String with next sequence value.
delete (self, tabname, cond)
Deletes a row.

Parameters:

  • self Dado Object.
  • tabname String with table name.
  • cond String with where-clause (and following SQL text).

Returns:

    Number of rows affected.

see also:

insert (self, tabname, contents)
Inserts a new row.

Parameters:

  • self Dado Object.
  • tabname String with table name.
  • contents Table with field-value pairs.

Returns:

    Number of rows affected.

see also:

update (self, tabname, contents, cond)
Updates existing rows.

Parameters:

  • self Dado Object.
  • tabname String with table name.
  • contents Table with field-value pairs.
  • cond String with where-clause (and following SQL text).

Returns:

    Number of rows affected.

see also:

select (self, columns, tabname, cond, extra, mode)
Retrieves rows. Creates an iterator over the result of a query. This iterator could be used in for-loops. (this argument also indicates whether the function should return a table or the values directly).

Parameters:

  • self Dado Object.
  • columns String with fields list.
  • tabname String with table name.
  • cond String with where-clause (and following SQL text).
  • extra String with extra SQL text (to be used when there is no where-clause).
  • mode String indicating fetch mode

Returns:

  1. Iterator over the result set.
  2. Cursor object (to allow explicit closing).

see also:

selectall (self, columns, tabname, cond, extra, mode)
Retrieves all rows.

Parameters:

  • self Dado Object.
  • columns String with fields list.
  • tabname String with table name.
  • cond String with where-clause (and following SQL text).
  • extra String with extra SQL text.
  • mode String indicating fetch mode (default == 'a').

Returns:

    Table with the entire result set.

see also:

wrap_connection (conn, key)
Wraps a database connection into a connection object.

Parameters:

  • conn Object with LuaSQL database connection.
  • key String with the key to the database object in the cache.

Returns:

    Dado Connection.
connect (dbname, dbuser, dbpass, driver)
Tries to use a connection in the cache or opens a new one.

Parameters:

  • dbname String with database name.
  • dbuser String with database username (optional).
  • dbpass String with database user password (optional).
  • driver String with LuaSQL's driver (default = "postgres").

Returns:

    Connection.
close (self)
Closes the connection and invalidates the object.

Parameters:

  • self Dado Object.
generated by LDoc 1.3