sql-serialize.rb
Path: sql-serialize.rb
Modified: Tue Mar 09 22:43:14 CET 2004

SQLSerializable

Author:Anders Borch
Copyright:Copyright © 2003 Anders Borch
License:LGPL

This ruby module will provide sql serialization for ruby objects in a transparent manner. The only requirement of this module is that all classes that are to be stored in an sql database uses it as a mix-in.

This module provides a number of functions and uses a number of internal variables. All internal methods and variables are prepended by `sql_’. As long as this namespace is not used by the objects that mix in any of the SQLSerializable derived modules everything should work seamlessly.

Also, in order to construct the classes properly, they must have a default constructor. The default constructor is extected to set the sql_primary_key to the name of the primary key (for example :number if the @number instance variable is the primary key).

The general structure is that there are entity tables for each entity that will be serialized. The entity table will hold "basic" data such as strings and numerics (and in time dates) and entity_assoc table will then hold associated objects, and entity_array and entity_hash will hold arrays and hashes in thta goes into that entity. This gives a very human readable table scheme for classes that only contain "primitive" datatypes, whereas classes that contain arrays and hashes will have those put in the ClassName_array or ClassName_hash tables. Aggregated classes will go in the ClassName_assoc table.

Everything that is serialized will have an sql_assoc_id which will be stored along with all other data in that entity. There is also an sql_ids table which holds all ids and the name of the class they refer to so it may be referenced from everywhere without knowing the datatype of the entity. The sql_ids table also holds a reference count to all objects so they may be properly garbage collected when noone holds any references to them any longer.

Required files
dbi    date   
Classes and Modules
Module DBI
  ::Class DBI::DatabaseHandle
Module SQLSerializable
Class SQLSerializeError