Class: DDG::Adapter::PostgreSQL
- Defined in:
- lib/ddg/adapter/postgresql.rb
Instance Method Summary collapse
-
#initialize(config) ⇒ PostgreSQL
constructor
A new instance of PostgreSQL.
- #select(sql) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(config) ⇒ PostgreSQL
Returns a new instance of PostgreSQL.
10 11 12 13 14 15 16 17 18 |
# File 'lib/ddg/adapter/postgresql.rb', line 10 def initialize(config) @db = PG::Connection.open( host: config[:host], port: config[:port], user: config[:user], password: config[:password], dbname: config[:database] ) end |
Instance Method Details
#select(sql) ⇒ Object
20 21 22 23 24 |
# File 'lib/ddg/adapter/postgresql.rb', line 20 def select(sql) @db.exec(sql).to_a.map do |row| JSON.parse(row.to_json, symbolize_names: true) end end |