Class Og
In: lib/og/backend.rb
lib/og/backends/mysql.rb
lib/og/backends/psql.rb
lib/og/backends/sqlite.rb
lib/og/connection.rb
lib/og/enchant.rb
lib/og/meta.rb
lib/og/mock.rb
lib/og/version.rb
lib/og.rb
Parent: Object

Og (ObjectGraph) is an efficient, yet simple Object-Relational mapping library.

Features

The library provides the following features:

+ Object-Relational mapping. + Absolutely no configuration files. + Multiple backends (PostgreSQL, MySQL). + ActiveRecord-style meta language and db aware methods. + Deserialize to Ruby Objects or ResultSets. + Deserialize sql join queries to Ruby Objects. + Serialize arbitrary ruby object graphs through YAML. + Connection pooling. + Thread safety. + SQL transactions. + Lifecycle callbacks. + Transparent support for cascading deletes for all backends. + Hierarchical structures (preorder traversal, materialized paths) + Works safely as part of distributed application. + Simple implementation.

Meta language

primary_key :pid (NOT IMPLEMENTED) name_key :name (NOT IMPLEMENTED) prop_accessor Fixnum, :pid, :sql => "smallint DEFAULT 1" has_many Child, :children many_to_many Role, :roles sql_index :pid

Design

Keep the main classes backend agnostic. For class ids we use the name instead of a hash. Class ids are typically not used in querys, they are stored for completeness. If we store a hash we cannot reclaim the class thus invalidating the point. Instead of .name(), to_s() is used so the methods are more flexible (they accept class names too!!)

Og allows the serialization of arbitrary Ruby objects. Just mark them as Object (or Array or Hash) in the prop_accessor and the engine will serialize a YAML dump of the object. Arbitrary object graphs are supported too.

This is NOT a singleton, an application may access multiple databases.

The og.xxx methods are more flexible and allow you to use multiple databases for example.

Managed Objects Lifecycle Callbacks

  • og_pre_insert
  • og_post_insert
        * og_pre_update
    
  • og_post_update
  • og_pre_insert_update
  • og_post_insert_update
  • self.og_pre_delete

A class level callback is used for delete because typically you call delete with an oid and not an object to avoid a deserialization.

Future

  • Support prepared statements (pgsql)
  • Support stored procedures (pgsql)
  • Support caching.
  • Deserialize to OpenStruct.
  • Better documentation.

Methods

use  

Classes and Modules

Module Og::Enchant
Module Og::MetaLanguage
Module Og::Unmanageable
Class Og::Backend
Class Og::Connection
Class Og::Database
Class Og::MockDatabase
Class Og::MysqlBackend
Class Og::PsqlBackend
Class Og::SqliteBackend

Constants

Version = '0.9.5'   The version of Og.

Public Class methods

Set the active database.

[Validate]