Sha256: d0ec3562f0f9e80456b10b15264bf16be48b23873181d32626ca6fc04bef1d01

Contents?: true

Size: 1.84 KB

Versions: 3

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true

module Snowflake
  require "ruby_snowflake_client_ext" # build bundle of the go files
  LOG_LEVEL = 0

  class Error < StandardError
    # This will get pulled through to Sentry, see:
    # https://github.com/getsentry/sentry-ruby/blob/11ecd254c0d2cae2b327f0348074e849095aa32d/sentry-ruby/lib/sentry/error_event.rb#L31-L33
    attr_reader :sentry_context

    def initialize(details)
      @sentry_context = details
    end
  end

  class Client
    attr_reader :error
    # Wrap the private _connect method, as sending kwargs to Go would require
    # wrapping the function in C as the current CGO has a limitation on
    # accepting variadic arguments for functions.
    def connect(account:"", warehouse:"", database:"", schema: "", user: "", password: "", role: "")
      @connection_details = {
        account: account,
        warehouse: warehouse,
        database: database,
        schema: schema,
        user: user,
        role: role
      }

      _connect(account.dup, warehouse.dup, database.dup, schema.dup, user.dup, password.dup, role.dup)
      if error != nil
        raise Error.new(@connection_details), error
      end
      true
    end

    def fetch(sql)
      result = _fetch(sql)
      return result if result.valid?
      raise Error.new(@connection_details.merge(sql: sql)), result.error
    end
  end


  class Result
    attr_reader :query_duration, :error

    def valid?
      error == nil
    end

    def get_all_rows(&blk)
      GC.disable
      if blk
        while r = next_row do
          yield r
        end
      else
        get_rows_array
      end
    ensure
      GC.enable
    end

    private
      def get_rows_array
        arr = []
        while r = next_row do
          puts "at #{arr.length}" if arr.length % 15000 == 0 && LOG_LEVEL > 0
          arr << r
        end
        arr
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby_snowflake_client-1.3.1 lib/ruby_snowflake_client.rb
ruby_snowflake_client-1.2.0 lib/ruby_snowflake_client.rb
ruby_snowflake_client-1.1.1 lib/ruby_snowflake_client.rb