Class: Og::PsqlStore
Overview
A Store that persists objects into a PostgreSQL database. To read documentation about the methods, consult the documentation for SqlStore and Store.
Design
The getvalue interface is used instead of each for extra performance.
Instance Attribute Summary
Attributes inherited from SqlStore
Attributes inherited from Store
#options, #transaction_nesting
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #enchant(klass, manager) ⇒ Object
- #exec(sql) ⇒ Object
-
#initialize(options) ⇒ PsqlStore
constructor
A new instance of PsqlStore.
- #query(sql) ⇒ Object
Methods included from PsqlUtils
Methods included from SqlUtils
#date, #escape, #join_table, #parse_date, #parse_float, #parse_int, #parse_timestamp, #quote, #table, #timestamp
Methods inherited from SqlStore
#commit, #count, #enable_logging, #find, #find_one, #join, #load, #reload, #rollback, #start, #unjoin, #update, #update_properties
Methods inherited from Store
#commit, #count, #delete, #find, for_name, #insert, #load, #reload, #rollback, #save, #start, #transaction, #update, #update_properties
Constructor Details
#initialize(options) ⇒ PsqlStore
Returns a new instance of PsqlStore.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/og/store/psql.rb', line 72 def initialize() super @conn = PGconn.connect( [:address], [:port], nil, nil, [:name], [:user].to_s, [:password].to_s ) schema_order = [:schema_order] encoding = [:encoding] = [:min_messages] @conn.exec("SET search_path TO #{schema_order}") if schema_order @conn.exec("SET client_encoding TO '#{encoding}'") if encoding @conn.exec("SET client_min_messages TO '#{}'") if rescue => ex # gmosx: any idea how to better test this? if ex.to_s =~ /database .* does not exist/i Logger.info "Database '#{[:name]}' not found!" self.class.create() retry end raise end |
Class Method Details
.create(options) ⇒ Object
61 62 63 64 65 |
# File 'lib/og/store/psql.rb', line 61 def self.create() # gmosx: system is used to avoid shell expansion. system 'createdb', [:name], '-U', [:user] super end |
.destroy(options) ⇒ Object
67 68 69 70 |
# File 'lib/og/store/psql.rb', line 67 def self.destroy() system 'dropdb', [:name], '-U', [:user] super end |
Instance Method Details
#close ⇒ Object
100 101 102 103 |
# File 'lib/og/store/psql.rb', line 100 def close @conn.close super end |
#enchant(klass, manager) ⇒ Object
105 106 107 108 109 |
# File 'lib/og/store/psql.rb', line 105 def enchant(klass, manager) klass.const_set 'OGSEQ', "#{table(klass)}_oid_seq" klass.property :oid, Fixnum, :sql => 'serial PRIMARY KEY' super end |
#exec(sql) ⇒ Object
118 119 120 121 122 123 |
# File 'lib/og/store/psql.rb', line 118 def exec(sql) Logger.debug sql if $DBG @conn.exec(sql).clear rescue => ex handle_sql_exception(ex, sql) end |
#query(sql) ⇒ Object
111 112 113 114 115 116 |
# File 'lib/og/store/psql.rb', line 111 def query(sql) Logger.debug sql if $DBG return @conn.exec(sql) rescue => ex handle_sql_exception(ex, sql) end |