Class: Qravan::Db
- Inherits:
-
Object
- Object
- Qravan::Db
- Defined in:
- lib/qravan/source/db.rb
Overview
Database class
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#result ⇒ Object
Returns the value of attribute result.
Instance Method Summary collapse
- #extract(sql) ⇒ Object
-
#initialize(source) ⇒ Db
constructor
A new instance of Db.
Constructor Details
#initialize(source) ⇒ Db
Returns a new instance of Db.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/qravan/source/db.rb', line 11 def initialize(source) @connection = Sequel.connect(adapter: source["adapter"], user: source["user"], password: source["password"], host: source["host"], port: source["port"], database: source["database"], max_connections: source["max_connections"], logger: Logger.new("logs/db.log")) end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
9 10 11 |
# File 'lib/qravan/source/db.rb', line 9 def connection @connection end |
#result ⇒ Object
Returns the value of attribute result.
9 10 11 |
# File 'lib/qravan/source/db.rb', line 9 def result @result end |
Instance Method Details
#extract(sql) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/qravan/source/db.rb', line 23 def extract(sql) Console.logger.info "DB EXTRACT: #{sql}" @result = [] time = Time.now @connection[sql].each do |row| @result << row end total = Time.now - time @result << { time: "DB Duration: #{Time.now - time}s" } @result end |