Table of Contents

ORMs

Ramaze does not come bundled with an ORM (Object-Relational Mapper), you are free to use whichever one you prefer. We suggest Sequel =)

Ramaze::Store

Built into Ramaze, Ramaze::Store leverages YAML and Pstore to provide a persistant store for ruby objects.

  require 'ramaze/store/default'
  DB = Ramaze::Store::Default.new('yaml.db')

ActiveRecord

  require 'active_record'
 
  ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => 'db.sqlite'
  ActiveRecord::Base.establish_connection(
    :adapter  => "mysql",
    :host     => "host",
    :username => "user",
    :password => "pass",
    :database => "dbname"
  )
 
  class NewItem < ActiveRecord::Migration
    def self.up
      create_table :items do |t|
        t.column :name, :string
        t.column :description, :text
        t.column :active, :boolean
        t.column :created_at, :datetime
      end
    end
    def self.down
      drop_table :items
    end
  end
  NewItem.up
 
  class ArItem < ActiveRecord::Base
    set_table_name 'items'
  end

Og

  require 'og'
  $DBG = true
 
  class Entry
    property :created, Time
    property :updated, Time
    property :title, String
    property :content, String
    def initialize title, content
      @created=Time.now
      @updated=Time.now
      @title=title
      @content=content
    end
  end
 
  Og.setup :evolve_schema => :full, :store => :sqlite

Datamapper

Datamapper is another new kid on the block when it comes to Ruby ORMs. It's based on the datamapper design pattern and takes cues from both Og and ActiveRecord.

  require 'data_mapper'
 
  DataMapper::Database.setup({
    :adapter  => 'mysql',
    :host     => 'localhost',
    :username => 'user',
    :password => 'pass',
    :database => 'dbname'
  })
 
  class Post < DataMapper::Base
    property :title, :string
    property :body, :text
    property :created_at, :datetime
  end
 
  database.save(Post)

Sequel

For more information, check out the RDoc, CheatSheet.

  require 'sequel'
 
  DB = Sequel.sqlite 'db.sqlite'
  DB = Sequel('mysql://user:pass@host:port/dbname')
 
  class Author < Sequel::Model(:authors)
    set_schema do
      primary_key :id
      varchar :name
    end
  end
 
  Author.create_table
  Author.create :name => 'Michael Crichton'

Kansas

DBI

DBI is a low-level database interface library for Ruby. You use SQL directly to access your data, and the results are returned as Ruby objects. DBI is specifically not an ORM; M4DBI is an ORM built on top of DBI.

DBrb

DBrb is a wrapper to facilitate working with Ruby DBI. The intention is to make the most commonly used DB functionality (as determined by me) easy and intuitive to use.