Postgres module

The primary module for accessing a PostgreSQL database seems to be the 'postgres' module on RAA.

However, the last release was in '03, and it seems like the module could use a little improvement. Also, it never hit that 1.0 mark, so I suppose the author doesn't think it's quite done either.

I am interested in writing a new postgresql module, is that a good idea? Is there another project underway? To other users of the postgres module, is there anything the current one doesn't quite do?

I had a few basic ideas about what I'd like it to do, if anyone has any comments please let me know.

First, I'd like to make it possible to execute queries in a more ruby-like way, for instance:

pg.exec("select * from my_table") do |rec|
     puts "#{rec['name']} #{rec['occupation']}"
end

Of course it would raise an exception if something went wrong. Also, I could make the iterator a method of the result object, rather than turning exec into an iterator.

Also, there just seem to be some things missing from the 'postgres' module, like getnotify(), asynchronous queries, etc.

Regards,
  Jeff Davis

Jeff Davis <jdavis-list@empires.org> writes:

The primary module for accessing a PostgreSQL database seems to be the
'postgres' module on RAA.

Hi Jeff,

Actually, I think the more common one is with ruby-dbi (which
eventually uses that postgres module). The DBI provides a more
ruby-like interface:

pg.exec("select * from my_table") do |rec|

# don't you need a rec.each here?

     puts "#{rec['name']} #{rec['occupation']}"
end

dbh.execute("select * from my_table") {|sth|
  sth.each{|row|
    puts "#{row['name']} #{row['occupation']}}}
    
More on:
http://www.kitebird.com/articles/ruby-dbi.html

However, the last release was in '03, and it seems like the module
could use a little improvement. Also, it never hit that 1.0 mark, so I
suppose the author doesn't think it's quite done either.

The module binds to libpq from postgresql. I scanned the change log of
libpq from 2003, and although there are changes, none seems major.

I am interested in writing a new postgresql module, is that a good
idea?

In any case, wouldn't it be easier for you and better for the ruby
community if you extend the existing postgres module?

Also, there just seem to be some things missing from the 'postgres'
module, like getnotify(), asynchronous queries, etc.

Hm.. I don't know. To me, it sounds like something that can be
incrementally added to the existing module and is not major enough as
to warrant a complete rewrite. But that's just me.

YS.