Ruby developers has a number of options for Postgresql client libraries:
Ruby developers has a number of options for ORMs
require 'sequel'
DB = Sequel.connect ENV['ELEPHANTSQL_URL'] || 'postgres://localhost/contacts'
class Person < Sequel::Model
end
persons = Person.where(first_name: 'John').exclude(last_name: 'Smith')
persons.each do |p|
puts [p.first_name, p.last_name].join(' ')
end
require 'active_record'
require 'uri'
uri = URI.parse(ENV['ELEPHANTSQL_URL'] || 'postgres://localhost/contacts')
ActiveRecord::Base.establish_connection(adapter: 'postgresql', host: uri.host, username: uri.user, password: uri.password, database: uri.path.sub('/', ''))
class Person < ActiveRecord::Base
end
persons = Person.where(first_name: 'John').where.not(last_name: 'Smith')
persons.each do |p|
puts [p.first_name, p.last_name].join(' ')
end
require 'dm-core'
DataMapper.setup(:default, ENV['ELEPHANTSQL_URL'] || 'postgres://localhost/contacts')
class Person
include DataMapper::Resource
property :id Serial
property :first_name String
property :last_name String
end
DataMapper.finalize
persons = Person.all(:first_name => 'John', :last_name.not => 'Smith')
persons.each do |p|
puts [p.first_name, p.last_name].join(' ')
end