Class: NoBrainer::QueryRunner::TableOnDemand

Inherits:
Middleware
  • Object
show all
Defined in:
lib/no_brainer/query_runner/table_on_demand.rb

Instance Method Summary collapse

Methods inherited from Middleware

#initialize

Constructor Details

This class inherits a constructor from NoBrainer::QueryRunner::Middleware

Instance Method Details

#call(env) ⇒ Object



2
3
4
5
6
7
8
9
10
11
# File 'lib/no_brainer/query_runner/table_on_demand.rb', line 2

def call(env)
  @runner.call(env)
# Not matching in RqlRuntimeError because we can get a DocumentNotPersisted
rescue RuntimeError => e
  if table_info = handle_table_on_demand_exception?(env, e)
    auto_create_table(env, *table_info)
    retry
  end
  raise
end

#handle_table_on_demand_exception?(env, e) ⇒ Boolean

Returns:



13
14
15
# File 'lib/no_brainer/query_runner/table_on_demand.rb', line 13

def handle_table_on_demand_exception?(env, e)
  /^Table `(.+)\.(.+)` does not exist\.$/.match(e.message).try(:[], 1..2)
end