Module: SurveyorWarehouse::DB
- Defined in:
- lib/surveyor_warehouse/db.rb
Class Method Summary collapse
- .adapter ⇒ Object
-
.columns(tablename) ⇒ Object
Columns are returned a hash like below:.
- .configurations ⇒ Object
- .connection ⇒ Object
- .database ⇒ Object
- .password ⇒ Object
- .username ⇒ Object
Class Method Details
.adapter ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/surveyor_warehouse/db.rb', line 29 def self.adapter @adapter ||= if 'postgresql' == configurations['adapter'] 'postgres' else raise "Unsupported database adapter: #{db['adapter']}" end end |
.columns(tablename) ⇒ Object
Columns are returned a hash like below:
{ :column1 => [:primary_key], :column2 => [:not_null] }
42 43 44 45 46 |
# File 'lib/surveyor_warehouse/db.rb', line 42 def self.columns(tablename) connection.schema(tablename.to_sym).inject({}) do |attrs, (cname, cattrs)| attrs.merge(cname => cattrs) end end |
.configurations ⇒ Object
13 14 15 |
# File 'lib/surveyor_warehouse/db.rb', line 13 def self.configurations @configurations ||= ::ActiveRecord::Base.configurations[Rails.env] end |
.connection ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/surveyor_warehouse/db.rb', line 3 def self.connection @connection ||= Sequel.connect( :adapter=> adapter, :host=>'localhost', :database=> database, :user=> username, :password=> password).extension(:pg_array) @connection.extend(SequelExtension::Connection) end |
.database ⇒ Object
25 26 27 |
# File 'lib/surveyor_warehouse/db.rb', line 25 def self.database @database ||= configurations['database'] end |
.password ⇒ Object
21 22 23 |
# File 'lib/surveyor_warehouse/db.rb', line 21 def self.password @password ||= configurations['password'] end |
.username ⇒ Object
17 18 19 |
# File 'lib/surveyor_warehouse/db.rb', line 17 def self.username @username ||= configurations['username'] end |