class OttomanORM::Datastore
Attributes
client[RW]
Public Class Methods
new(parameters)
click to toggle source
# File lib/ottoman_orm/datastore.rb, line 6 def initialize parameters self.connect parameters end
Public Instance Methods
create(name, data)
click to toggle source
# File lib/ottoman_orm/datastore.rb, line 10 def create name, data execute_sproc(name + '_create', data) end
get(name, id)
click to toggle source
# File lib/ottoman_orm/datastore.rb, line 14 def get name, id execute_sproc(name + '_get', id).values() end
get_by_field(name, field, value)
click to toggle source
# File lib/ottoman_orm/datastore.rb, line 18 def get_by_field name, field, value execute_sproc(name + '_get_by_' + field, value).values() end
Protected Instance Methods
build_query_string(sproc, args)
click to toggle source
# File lib/ottoman_orm/datastore.rb, line 40 def build_query_string(sproc, args) query_string = 'select ' + sproc + '(\'' + args + '\')' end
connect(parameters)
click to toggle source
# File lib/ottoman_orm/datastore.rb, line 24 def connect parameters config = YAML.load_file(File.join('config', 'ottoman_orm.yml'))[parameters[:mode]] @client = PG::Connection.new( :host => config['host'], :port => config['port'], :dbname => config['dbname'], :user => config['user'], :password => config['password'] ) end
Also aliased as: reconnect!
execute_sproc(sproc, args)
click to toggle source
# File lib/ottoman_orm/datastore.rb, line 36 def execute_sproc(sproc, args) @client.exec(build_query_string(sproc, args)) end