Method: OMF::Web::Server#load_database

Defined in:
lib/omf-web/thin/server.rb

#load_database(id, config) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/omf-web/thin/server.rb', line 207

def load_database(id, config)
  unless db_cfg = config[:database]
    fatal "Missing database configuration in datasource '#{config}'"
    abort
  end
  db = get_database(db_cfg)
  if query_s = config[:query]
    unless schema = config[:schema]
      fatal "Missing schema configuration in datasource '#{config}'"
      abort
    end
    require 'omf_oml/schema'
    config[:schema] = OMF::OML::OmlSchema.create(schema)
    table = db.create_table(id, config)
  else
    unless table_name = config.delete(:table)
      fatal "Missing 'table' in datasource configuration '#{config}'"
      abort
    end
    config[:name] = id
    unless table = db.create_table(table_name, config)
      fatal "Can't find table '#{table_name}' in database '#{db_cfg}'"
      abort
    end
  end
  OMF::Web.register_datasource table, name: id
end