mac*postgres*ruby

PostgreSQLのインストール

参考URL:http://homepage.mac.com/reefedge/osx/index_4.html

postgresをスーパーユーザーで作成。


ruby-postgresのインストール

sudo gem install ruby-postgres

終わり。

テストスクリプト

require "rubygems"
require "postgres"

conn = PGconn.connect("localhost", 5432, "", "", "dbname", "dbuser");
res = conn.exec("select * from verbs;");
p rows = res.num_tuples
p cols = res.num_fields
for i in 0..rows-1 do
  for j in 0..cols-1 do
    print res.getvalue(i,j)," "
  end
  print "\n"
end
conn.close

とりあえず動いた。

結論

要hack。
使い方イミフ。