Sha256: c330e5bce81fe35cff0511cb3dfb5b27240fff197afe8895b52b73dadc30d909
Contents?: true
Size: 906 Bytes
Versions: 45
Compression:
Stored size: 906 Bytes
Contents
module Blazer module Adapters class MongodbAdapter < BaseAdapter def run_statement(statement, comment) columns = [] rows = [] error = nil begin documents = db.command({:$eval => "#{statement.strip}.toArray()", nolock: true}).documents.first["retval"] columns = documents.flat_map { |r| r.keys }.uniq rows = documents.map { |r| columns.map { |c| r[c] } } rescue => e error = e.message end [columns, rows, error] end def tables db.collection_names end def preview_statement "db.{table}.find().limit(10)" end protected def client @client ||= Mongo::Client.new(settings["url"], connect_timeout: 1, socket_timeout: 1, server_selection_timeout: 1) end def db @db ||= client.database end end end end
Version data entries
45 entries across 45 versions & 3 rubygems