Q: postgres access in Windows

Discussion in 'Ruby' started by G. Ralph Kuntz, MD, MS, Jul 28, 2008.

  1. I spent a couple of hour this weekend trying to get Ruby to talk to
    PostgreSQL on a Windows Vista machine without success. I am working
    with both Cygwin Ruby and JRuby.

    I installed the DBI gem, including dbd_pg. I get the following error
    in both version of Ruby:

    Could not load driver (no such file to load -- /usr/lib/ruby/
    site_ruby/1.8/dbd/Pg)

    I also tried jruby-postgres and pgconn but I could not figure out how
    to call the first one and got errors with the second. I could not
    find any documentation (even tried ri).

    I tried Googling everything I could think of.

    Has anyone gotten a DB connection to PostgreSQL working under Windows
    with any version of Ruby?

    Thanks.
     
    G. Ralph Kuntz, MD, MS, Jul 28, 2008
    #1
    1. Advertising

  2. G. Ralph Kuntz, MD, MS

    J-H Johansen Guest

    On Mon, Jul 28, 2008 at 2:14 PM, G. Ralph Kuntz, MD, MS <> wrote:
    > I spent a couple of hour this weekend trying to get Ruby to talk to
    > PostgreSQL on a Windows Vista machine without success. I am working
    > with both Cygwin Ruby and JRuby.
    >
    > I installed the DBI gem, including dbd_pg. I get the following error
    > in both version of Ruby:
    >
    > Could not load driver (no such file to load -- /usr/lib/ruby/
    > site_ruby/1.8/dbd/Pg)
    >
    > I also tried jruby-postgres and pgconn but I could not figure out how
    > to call the first one and got errors with the second. I could not
    > find any documentation (even tried ri).
    >
    > I tried Googling everything I could think of.
    >
    > Has anyone gotten a DB connection to PostgreSQL working under Windows
    > with any version of Ruby?
    >
    > Thanks.
    >
    >



    Hi,

    My current use of postgres is done like this (but I think you can
    require 'dbi' instead of 'rubygems'):

    require 'rubygems'
    require 'postgres'

    $conn = PGconn.connect('hostname','port','','','db-name','username','password')

    If you've installed rails you can also do the following in order to
    use ActiveRecord which is nice:

    require 'rubygems'
    require 'active_record'

    ActiveRecord::Base.pluralize_table_names = false
    ActiveRecord::Base.establish_connection(
    :adapter => "postgresql",
    :host => "hostname",
    :database => "db-name",
    :username => "username",
    :password => "password"
    )

    And then create objects of tables or views.
    Assuming you have a table or a view called gen_table:

    class GenTable < ActiveRecord::Base; end
    gt = GenTable.find:)all)

    for a in gt
    puts a.id
    end



    --
    J-H Johansen
    --
    There are 10 kinds of people in the world: Those who understand binary and
    those who don't...
     
    J-H Johansen, Jul 28, 2008
    #2
    1. Advertising

  3. That worked like a charm!

    Is there any documentation on PGconn and the other classes in the
    postgres-pr module?

    Thanks.
     
    G. Ralph Kuntz, MD, MS, Jul 28, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Reid Priedhorsky

    Secure Postgres access

    Reid Priedhorsky, Sep 6, 2006, in forum: Python
    Replies:
    9
    Views:
    541
  2. Alec Taylor
    Replies:
    2
    Views:
    241
    Miki Tebeka
    Nov 30, 2011
  3. Carl Youngblood

    ruby-postgres for windows?

    Carl Youngblood, Jul 26, 2003, in forum: Ruby
    Replies:
    0
    Views:
    87
    Carl Youngblood
    Jul 26, 2003
  4. Nick Black
    Replies:
    1
    Views:
    165
    Kashia Buch
    Nov 16, 2006
  5. Dillip Kumar
    Replies:
    5
    Views:
    107
    Kevin Williams
    Nov 24, 2007
Loading...

Share This Page