pgsql Ruby Gem

A PostgreSQL library that was carefully designed.

Author

Bertram Scharpf <[email protected]>

Features

  • Connection parameters from hash

  • Query parameters

  • Asynchronous queries

  • Quick query of single lines or values

  • Full PostgreSQL quoting support

  • Built-in transactions and savepoints by Ruby blocks

Example

Write something like this:

require "pgsql"

Pg::Conn.open :dbname => "test1", :user => "jdoe" do |conn|
  conn.exec "SELECT * FROM mytable;" do |result|
    result.each { |row|
        l = row.join ", "
            ...
    }
  end
  cmd = "    SELECT * FROM mytable WHERE num=$1::INTEGER;\n  ENDSQL\n  conn.query cmd, 42 do |row|\n    l = row.join \", \"\n        ...\n  end\n  ...\nend\n"

Thanks

In the remembrance of Guy Decoux.