Class: Datafusion::DbExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/datafusion/db_executor.rb

Constant Summary collapse

TAG =
"DBEXECUTOR"

Instance Method Summary collapse

Constructor Details

#initialize(conn) ⇒ DbExecutor

Returns a new instance of DbExecutor.



7
8
9
# File 'lib/datafusion/db_executor.rb', line 7

def initialize(conn)
  @db = Sequel.connect(conn)
end

Instance Method Details

#execute(sql, label = '') ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/datafusion/db_executor.rb', line 18

def execute(sql, label='')
  run = rand(36**5).to_s(36)

  Datafusion.log.info("#{TAG}: starting run id:#{run} for: '#{label}'")
  @db[sql].each do |r|
    Datafusion.log.info("#{TAG}: out: #{r}")
  end
  Datafusion.log.info("#{TAG}: finished run id:#{run}")
end

#remove!Object



11
12
13
14
15
16
# File 'lib/datafusion/db_executor.rb', line 11

def remove!
  servers = @db[:pg_foreign_server].map(:srvname)
  servers.each do |srv|
    execute("drop server if exists #{srv} cascade", "drop #{srv}")
  end
end