0.0
No commit activity in last 3 years
No release in over 3 years
Extensions to pg gem supporting typecasting.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

>= 0.9.0
 Project Readme

pg_typecast¶ ↑

Description¶ ↑

Provides typecasting support for the pg gem. The code is extracted from swift (github.com/shanna/swift) as a drop-in enhancement for users of pg.

Status¶ ↑

**THIS CODE IS NOT MAINTAINED ANYMORE**

This was done as an initial proof of concept and is not maintained anymore. If you’re looking for a database adapter that does typecasting for pg, have a look at github.com/deepfryed/swift-db-postgres

Dependencies¶ ↑

  • ruby >= 1.9.1

  • pg >= 0.9.0

Caveats¶ ↑

  • This gem overrides the PGresult#each method.

  • The rows are returned as hashes with field names as symbols and values typecast from postgres types to ruby types.

  • Timestamp conversion is done to localtime. The server and client are assumed to be in same timezone unless you use the ‘timestamp with time zone’ data type in postgresql.

Compiling¶ ↑

If pg_config is not on your PATH, then just set POSTGRES_INCLUDE and POSTGRES_LIB environment variables to the include and lib directories.

Synopsis¶ ↑

require 'pg'
require 'pg_typecast'

adapter = PGconn.connect 'host=127.0.0.1 dbname=test'
result  = adapter.exec('select * from users')
result.each do |row|
  p row
end

Typecasting¶ ↑

The following table illustrates the typecasting done from postgresql types to native ruby types.

+--------------------+---------------------------+
| postgresql type    |   ruby type               |
+--------------------+---------------------------+
| bool               |   TrueClass or FalseClass |
| bytea              |   StringIO                |
| date               |   Date                    |
| float              |   Float                   |
| integer            |   Fixnum or Bignum        |
| numeric            |   BigDecimal              |
| timestamp          |   Time                    |
| timestampz         |   Time                    |
+--------------------+---------------------------+

License¶ ↑

See LICENSE.