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

Version Path
sql-jarvis-2.1.10 lib/blazer/adapters/mongodb_adapter.rb
sql-jarvis-2.1.9 lib/blazer/adapters/mongodb_adapter.rb
sql-jarvis-2.1.8 lib/blazer/adapters/mongodb_adapter.rb
sql-jarvis-2.1.7 lib/blazer/adapters/mongodb_adapter.rb
sql-jarvis-2.1.6 lib/blazer/adapters/mongodb_adapter.rb
blazer-2.5.0 lib/blazer/adapters/mongodb_adapter.rb
blazer-2.4.8 lib/blazer/adapters/mongodb_adapter.rb
blazer-2.4.7 lib/blazer/adapters/mongodb_adapter.rb
blazer-2.4.6 lib/blazer/adapters/mongodb_adapter.rb
blazer-2.4.5 lib/blazer/adapters/mongodb_adapter.rb
blazer-2.4.4 lib/blazer/adapters/mongodb_adapter.rb
blazer-2.4.3 lib/blazer/adapters/mongodb_adapter.rb
blazer-2.4.2 lib/blazer/adapters/mongodb_adapter.rb
blazer-2.4.1 lib/blazer/adapters/mongodb_adapter.rb
blazer-2.4.0 lib/blazer/adapters/mongodb_adapter.rb
blazer-2.3.1 lib/blazer/adapters/mongodb_adapter.rb
blazer-2.3.0 lib/blazer/adapters/mongodb_adapter.rb
blazer-2.2.8 lib/blazer/adapters/mongodb_adapter.rb
blazer-2.2.7 lib/blazer/adapters/mongodb_adapter.rb
blazer-2.2.6 lib/blazer/adapters/mongodb_adapter.rb