Class: NoBrainer::QueryRunner::DatabaseOnDemand

Inherits:
Middleware
  • Object
show all
Defined in:
lib/no_brainer/query_runner/database_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
12
13
# File 'lib/no_brainer/query_runner/database_on_demand.rb', line 2

def call(env)
  @runner.call(env)
rescue RuntimeError => e
  if db_name = handle_database_on_demand_exception?(env, e)
    # Don't auto create on db_drop.
    return {} if NoBrainer::RQL.db_drop?(env[:query])

    auto_create_database(env, db_name)
    retry
  end
  raise
end

#handle_database_on_demand_exception?(env, e) ⇒ Boolean

Returns:



15
16
17
# File 'lib/no_brainer/query_runner/database_on_demand.rb', line 15

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