0.0
No commit activity in last 3 years
No release in over 3 years
Provides access to PostgreSQL using the RDO interface
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 0.1.0
 Project Readme

RDO PostgreSQL Driver

This is the PostgreSQL driver for [RDO—Ruby Data Objects] (https://github.com/d11wtq/rdo).

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.

Copyright & Licensing

Written by Chris Corbyn.

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