본문 바로가기

PostgreSQL

postgresql & ruby & gem pg install


==========================================================================================================

ruby & gem pg install 

yum install rubygems

yum install ruby-devel

gem install pg

==========================================================================================================

[root@ppas ~]# gem install pg

Building native extensions.  This could take a while...

Successfully installed pg-0.17.0

1 gem installed

Installing ri documentation for pg-0.17.0...

Invalid output formatter

For help on options, try 'rdoc --help'


[root@ppas db]# cat conn.rb

#!/usr/bin/ruby

require "rubygems"

require "pg"

begin

  conn = PGconn.connect('localhost',5555,'','','postgres','enterprisedb','postgres')

  q    = "select * from aa"

  res  = conn.exec(q)

  res.each do |r|

    p r

  end

rescue PGError => ex

  # PGError process

  print(ex.class," -> ",ex.message)

rescue => ex

  # Other Error  process

  print(ex.class," -> ",ex.message)

ensure

  conn.close if conn

end

==========================================================================================================

postgres=# SELECT * FROM AA;

 code

------

 11

 22

(2 rows)

==========================================================================================================

[root@ppas db]# ./conn.rb

{"code"=>"11"}

{"code"=>"22"}

==========================================================================================================

Go Ruby!

Install JRuby on Centos


wget http://jruby.org.s3.amazonaws.com/downloads/1.6.7/jruby-bin-1.6.7.tar.gz

tar xvzf jruby-bin-1.6.7.tar.gz

cd jruby-1.6.7

sudo vim /etc/bashrc

add following

- export JRUBY_HOME=/home/suhas/jruby-1.6.7

- export PATH=$JRUBY_HOME/bin:$PATH

##- export JRUBY_OPTS=?1.9


jruby -S gem install bundler rake rails

jruby -S gem install jruby-openssl

bundle install