Skip to content
/ xpg Public

Wrapper for Ruby's pg gem that offers some convenient functionality.

Notifications You must be signed in to change notification settings

geoffk/xpg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

xpg

What is it?

xpg is a wrapper for Ruby's pg gem for connecting to Postgresql databases. It offers three features:

  1. Attributes of each row can be accessed as methods on the row object. So you can use user.username instead of user['username'].
  2. Attributes of each row are converted into the appropriate Ruby object.
  3. A simple insert method.

There is a major downside, however. Converting the database fields into the correct Ruby objects slows everything down significantly. Using xpg can be an order of magnitude slower that using pg alone.

Usage

Just require 'xpg' and use it like pg, except use XPGconn instead of PGconn. It should be totally compatible with every function of pg.

Example

reguire 'xpg'

@db = XPGconn.open(:dbname => 'xpg')

@db.insert('users', :username => 'geoffk', :active => false)

@db.exec('select username, active from users').each do |u|
  puts u['username']
  puts u[:username]
  puts u.username

  # Active has been converted into a boolean
  if u.active
    puts "Is active"
  else
    puts "Is not active"
  end
end

About

Wrapper for Ruby's pg gem that offers some convenient functionality.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages