Class: ConceptQL::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/conceptql/database.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db, opts = {}) ⇒ Database

Returns a new instance of Database.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/conceptql/database.rb', line 7

def initialize(db, opts={})
  @db = db
  db_type = :impala
  if db
    extensions.each do |extension|
      db.extension extension
    end
    db_type = db.database_type.to_sym
  end

  @opts = opts.revalue { |v| v ? v.to_sym : v }
  @opts[:data_model] ||= :omopv4
  @opts[:database_type] ||= db_type
  db.set(db_opts) if db.respond_to?(:set)
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



5
6
7
# File 'lib/conceptql/database.rb', line 5

def db
  @db
end

Instance Method Details

#db_optsObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/conceptql/database.rb', line 27

def db_opts
  db_opts = {}
  if opts[:database_type] == :impala
    db_opts.merge!(runtime_filter_mode: "OFF")
    if mem_limit = (opts[:impala_mem_limit] || ENV['IMPALA_MEM_LIMIT'])
      db_opts.merge!(mem_limit: mem_limit)
    end
  end
  db_opts
end

#extensionsObject



38
39
40
# File 'lib/conceptql/database.rb', line 38

def extensions
  [:date_arithmetic, :error_sql]
end

#query(statement, opts = {}) ⇒ Object



23
24
25
# File 'lib/conceptql/database.rb', line 23

def query(statement, opts={})
  Query.new(db, statement, @opts.merge(opts))
end