RAA - sqlyzer

sqlyzer / 0.1

Short description: A complete Ruby object to Sql serialize solution
Category: Library/Database
Status: alpha
Created: 2007-05-11 22:55:25 GMT
Last update: 2007-05-11 22:55:25 GMT
Owner: Paul Quemin (Projects of this owner)
Homepage: http://rubyforge.org/projects/sqlyzer/
Download: http://rubyforge.org/projects/sqlyzer/
License: GPL
Dependency:
None
Description:
                ___
               /\_ \
   ____     __ \//\ \    __  __  ____      __   _ __
  /',__\  /'__`\ \ \ \  /\ \/\ \/\_ ,`\  /'__`\/\`'__\
 /\__, `\/\ \L\ \ \_\ \_\ \ \_\ \/_/  /_/\  __/\ \ \/
 \/\____/\ \___, \/\____\\/`____ \/\____\ \____\\ \_\
  \/___/  \/___/\ \/____/ `/___/> \/____/\/____/ \/_/
               \ \_\         /\___/
                \/_/         \/__/  version 0.1

What is Sqlyzer ?

Sqlyzer is a Ruby Mixin able to store, load, update and delete Ruby objects and their relationships in a database by automatically generate adapted tables and queries without a line of Sql from the user.

Current version is : *0.1*

Here is the list of currently supported Sql types :

  • TEXT,
  • VARCHAR,
  • INT,
  • INT2,
  • INT4,
  • INT8,
  • FLOAT,
  • FLOAT4,
  • FLOAT8,
  • BOOL,
  • DATE,
  • TIME,
  • DATETIME.

The final goal is to handle object inheritance, associations, resource handling (for various optimizations) and request caching.

Okay, give me a sample code

  require 'rubygems'
  require 'sqlyzer'

  class Test
        include Sqlyzer::Serializer

        sql_has_keys    :lastname, :firstname/SQL_TEXT
        sql_has_values  :age/SQL_INT2, :birth/Time.now, :male/SQL_BOOL

        def initialize(firstname, lastname, age, male = false)
            @firstname = firstname
            @lastname = lastname
            @age = age
            @male = male
        end

  end

  Sqlyzer::Db::connect DB_API, DB_HOST, DB_NAME, DB_USER, DB_PASS
  Test.new('sexy', 'jimmy', 42).sql_new

Congratulations ! You just generate :

  1. a ‘Test’ Sql table containing :
    • ‘firstname’ and ‘lastname’ as TEXT primary keys;
    • ‘age’ as INT2;
    • ‘birth’ as DATETIME with current date as default value;
    • ‘male’ as BOOL flag.
  2. a unique index constraint on ‘Test’ primary keys;
  3. an INSERT request to the ‘Test’ table with the data from the created ‘Test’ Ruby object.

Run the code a second time, ‘sql_new’ will load previously saved data from ‘Test’ table : the first run ‘Time.now’ return value is restored to a ‘birth’ public method of the fresh instance of class ‘Test’.

How do I help ?

The project is now hosted on RubyForge : rubyforge.org/projects/sqlyzer/.

Edit this project (for project owner)

back to RAA top