RDO PostgreSQL Driver

This is the PostgreSQL driver for RDO—Ruby Data Objects.

Build Status

Refer to the RDO project README for full usage information.

Supported PostgreSQL version

This driver supports PostgreSQL versions >= 7.4.

Older versions are no longer supported by PostgreSQL in any case.

Installation

Via rubygems:

$ gem install rdo-postgres

Or add the following line to your application's Gemfile:

gem "rdo-postgres"

And install with Bundler:

$ bundle install

Usage

The registered URI schemes are postgres://, postgresql:// and psql://.

require "rdo-postgres"

conn = RDO.connect("postgres://user:pass@localhost/dbname?encoding=utf-8")

Type Support

If not listed below, the String form of the value will be returned. The currently mapped types are tabled below:

PostgreSQL Type Ruby Type Notes
null NilClass
boolean TrueClass, FalseClass The strings 't' and 'f' will work as inputs too
text, char, varchar String The encoding specified on the connection is used
bytea String The output encoding is set to ASCII-8BIT/BINARY
integer, int4, int2, int8 Fixnum Ruby may use a Bignum, if needed
float, real, float4, float8 Float NaN, Infinity and -Infinity are supported
numeric, decimal BigDecimal NaN is supported
date Date
timestamp DateTime Input may also be a Time; output times are in the system time zone
timestamp with time zone DateTime Input may also be a Time
array Array n-dimensional arrays of the types listed above are supported

PostgreSQL style bind parameters

PostgreSQL uses $1, $2 etc for bind parameters. RDO uses '?'. You can use either, but you cannot mix both styles in the same query, or you will get errors.

These are ok:

conn.execute("SELECT * FROM users WHERE banned = ? AND created_at > ?", true, 1.week.ago)
conn.execute("SELECT * FROM users WHERE banned = $1 AND created_at > $2", true, 1.week.ago)

This is not ok:

conn.execute("SELECT * FROM users WHERE banned = $1 AND created_at > ?", true, 1.week.ago)

HStore Operators

Some of the hstore operators in PostgreSQL use the '?' character. If you need to use them, for now, you need to escape the '?' so RDO doesn't confuse them for bind markers. I'd like to remove this restriction.

conn.execute(%q{SELECT 'foo=>42,bar=>101'::hstore \? ?}, "foo")

Contributing

If you find any bugs, please send a pull request if you think you can fix it, or file in an issue in the issue tracker.

I'm particulary interested in patches surrounding support for arrays of custom types, such as ENUMs (this is done by reading from pg_type, in an efficient manner).

When sending pull requests, please use topic branches—don't send a pull request from the master branch of your fork.

Contributors will be credited in this README.

Written by Chris Corbyn.

Licensed under the MIT license. See the LICENSE file for full details.