Sha256: 82c8e1afbbc211af082584c7c26ce607b4ee91a45fd5d9cf7037d54f11130f25

Contents?: true

Size: 1.29 KB

Versions: 20

Compression:

Stored size: 1.29 KB

Contents

module Blazer
  module Adapters
    class SalesforceAdapter < BaseAdapter
      def run_statement(statement, comment)
        columns = []
        rows = []
        error = nil

        # remove comments manually
        statement = statement.gsub(/--.+/, "")
        # only supports single line /* */ comments
        # regex not perfect, but should be good enough
        statement = statement.gsub(/\/\*.+\*\//, "")

        # remove trailing semicolon
        statement = statement.sub(/;\s*\z/, "")

        begin
          response = client.query(statement)
          rows = response.map { |r| r.to_hash.except("attributes").values }
          columns = rows.any? ? response.first.to_hash.except("attributes").keys : []
        rescue => e
          error = e.message
        end

        [columns, rows, error]
      end

      def tables
        # cache
        @tables ||= client.describe.select { |r| r.queryable }.map(&:name)
      end

      def preview_statement
        "SELECT Id FROM {table} LIMIT 10"
      end

      # https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_quotedstringescapes.htm
      def quoting
        :backslash_escape
      end

      protected

      def client
        @client ||= Restforce.new
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 3 rubygems

Version Path
blazer-3.1.0 lib/blazer/adapters/salesforce_adapter.rb
blazer-3.0.4 lib/blazer/adapters/salesforce_adapter.rb
blazer_xlsx-3.0.8 lib/blazer/adapters/salesforce_adapter.rb
blazer_xlsx-3.0.7 lib/blazer/adapters/salesforce_adapter.rb
blazer_xlsx-3.0.6 lib/blazer/adapters/salesforce_adapter.rb
blazer_xlsx-3.0.5 lib/blazer/adapters/salesforce_adapter.rb
blazer-3.0.3 lib/blazer/adapters/salesforce_adapter.rb
blazer-3.0.2 lib/blazer/adapters/salesforce_adapter.rb
finery-3.0.3 lib/blazer/adapters/salesforce_adapter.rb
finery-3.0.2 lib/blazer/adapters/salesforce_adapter.rb
blazer-3.0.1 lib/blazer/adapters/salesforce_adapter.rb
finery-3.0.1 lib/blazer/adapters/salesforce_adapter.rb
finery-3.0.0 lib/blazer/adapters/salesforce_adapter.rb
blazer-3.0.0 lib/blazer/adapters/salesforce_adapter.rb
blazer-2.6.5 lib/blazer/adapters/salesforce_adapter.rb
blazer-2.6.4 lib/blazer/adapters/salesforce_adapter.rb
blazer-2.6.3 lib/blazer/adapters/salesforce_adapter.rb
blazer-2.6.2 lib/blazer/adapters/salesforce_adapter.rb
blazer-2.6.1 lib/blazer/adapters/salesforce_adapter.rb
blazer-2.6.0 lib/blazer/adapters/salesforce_adapter.rb