Class Og::Connection
In: lib/og/connection.rb
Parent: Object

A Connection to the Database. This file defines the skeleton functionality. A backend specific implementation file (driver) implements all methods.

Future

  • support caching.
  • support prepared statements.

Methods

<<   close   commit   count   create_table   delete   delete!   drop_table   exec   get   get_all   get_by_name   get_by_oid   insert   load   load_all   load_by_name   load_by_oid   new   pupdate   put   query   rollback   save   select   select_one   start   transaction   update   update_properties  

Attributes

db  [R]  The backend
deserialize  [RW]  If set to true, the select methods deserialize the resultset to create entities.
og  [R]  The frontend (Og) contains useful strucutres.

Public Class methods

Initialize a connection to the database.

Public Instance methods

<<(obj)

Alias for save

Close the connection to the database.

Create the managed object table. The properties of the object are mapped to the table columns. Additional sql relations and constrains are created (indicices, sequences, etc).

Delete an object from the database. Allways perform a deep delete.

No need to optimize here with pregenerated code. Deletes are not used as much as reads or writes.

Input:

obj_or_oid = Object or oid to delete. klass = Class of object (can be nil if an object is passed)

delete!(obj_or_oid, klass = nil, cascade = true)

Alias for delete

Drop the managed object table.

Execute an SQL query, no result returned.

get(oid, klass)

Alias for load

get_all(klass, extrasql = nil)

Alias for load_all

get_by_name(name, klass)

Alias for load_by_name

get_by_oid(oid, klass)

Alias for load_by_oid

Force insertion of managed object.

Load an object from the database.

Input: oid = the object oid, OR the object name.

Load all objects of the given klass. Used to be called ‘collect’ in an earlier version.

Load an object by name.

Load an object by oid.

pupdate(update_sql, obj_or_oid, klass = nil)

Alias for update_properties

put(obj)

Alias for save

Execute an SQL query and return the result

Save an object to the database. Insert if this is a new object or update if this is already stored in the database.

Perform a standard SQL query to the database. Deserializes the results.

Optimized for one result.

Transaction helper. In the transaction block use the db pointer to the backend.

Force update of managed object.

Update only specific fields of the managed object.

Input: sql = the sql code to updated the properties.

WARNING: the object in memory is not updated.

[Validate]