From: Reid Thompson Date: 2007-10-17T08:22:27+09:00 Subject: Re: recommendations for working with PostgreSQL Reid Thompson wrote: > > > Chad Perrin wrote: >> I have need to work with PostgreSQL via Ruby. What gems/modules do you >> recommend? Are there any quickstart-type howtos online to which you >> might direct me? >> >> Thanks in advance. >> > og www.nitroproject.org > > $ cat testog.rb > require 'og' > > class Comment > property :title, String > property :body, String > property :author, String > property :create_time, Time > end > > og_psql = { > :destroy => false, > :store => :psql, > :user => 'rthompso', > :address => '127.0.0.1', > :password => 'rthompso', > :name => 'test' > } > > db =Og.setup(og_psql) > > > t1= Time.now > # save the object in the database > db.store.start > 1.upto(10000) { |i| > c = Comment.new > c.title = 'Hello' > c.body = 'World' > c.create_time = Time.now > c.author = 'tml' > c.save > } > db.store.commit > puts Time.now - t1 > > -----------------this is on cygwin windows ---------------------- > > $ ruby -v ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-cygwin] > > ------------------------------------------------------ > cyberhome: /home/rthompso> > $ export RUBYOPT=rubygems > cyberhome: /home/rthompso> > $ ruby testog.rb > INFO: Og uses the Psql store. > NOTICE: CREATE TABLE will create implicit sequence "ogcomment_oid_seq" > for serial column "ogcomment.oid" > NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index > "ogcomment_pkey" for table "ogcomment" > INFO: Created table 'ogcomment'. > 10.697 > > cyberhome: /home/rthompso> > $ psql -U rthompso -h 127.0.0.1 -c "select count(*) from ogcomment" test > count > ------- > 10000 > (1 row) > > I just updated og... updated to reflect a few changes... I'm sure there are others that can give better examples.. require 'og' class Comment attr_accessor :title, String attr_accessor :body, String attr_accessor :author, String attr_accessor :create_time, Time end og_psql = { :destroy => false, :store => :postgresql, :user => 'rthompso', :address => '127.0.0.1', :password => 'rthompso', :name => 'test' } db =Og.setup(og_psql) t1= Time.now # save the object in the database db.store.start 1.upto(10000) { |i| c = Comment.new c.title = 'Hello' c.body = 'World' c.create_time = Time.now c.author = 'tml' c.save } db.store.commit puts Time.now - t1