Sha256: 6ed97dad6152916a401a3dd1f44360f7c720ca4e5c29d12d3ca86aa584916ee1

Contents?: true

Size: 1018 Bytes

Versions: 2

Compression:

Stored size: 1018 Bytes

Contents

# frozen_string_literal: true

require "async"
require "sequel"
require "logger"
module Qravan
  # Database class
  class Db
    attr_accessor :result, :connection

    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

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
qravan-0.1.1 lib/qravan/source/db.rb
qravan-0.1.0 lib/qravan/source/db.rb