Sha256: 1a32e87a0af74666169c72361be1b86a7e13a8d96be3554fa78e358a5cd8ef4e

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

module BigQueryAdapter
  # Includes helper methods
  module DatabaseStatements
    NATIVE_DATABASE_TYPES = {
      boolean:      { name: 'BOOL' },
      integer:      { name: 'INTEGER' },
      float:        { name: 'FLOAT' },
      string:       { name: 'STRING' },
      datetime:     { name: 'DATETIME' },
      date:         { name: 'DATE' },
      timestamp:    { name: 'TIMESTAMP' },
      time:         { name: 'TIME' }
    }.freeze

    def native_database_types
      NATIVE_DATABASE_TYPES
    end

    def valid_type?(type) # :nodoc:
      !native_database_types[type].nil?
    end

    # Executes the SQL statement in the context of this connection.
    # Returns the number of rows affected.
    def execute(sql, name = nil, _binds = [])
      log(sql, name) do
        @connection.do(sql)
      end
    end

    # Executes +sql+ statement in the context of this connection using
    # +binds+ as the bind substitutes. +name+ is logged along with
    # the executed +sql+ statement.
    # rubocop:disable Lint/UnusedMethodArgument
    def exec_query(sql, name = 'SQL', _binds = [], prepare: false)
      log(sql, name) do
        result = @connection.run(sql)
        ActiveRecord::Result.new(result.columns, result.rows)
      end
    end
    # rubocop:enable Lint/UnusedMethodArgument

    def supports_ddl_transactions
      false
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
big_query_adapter-0.1.0 lib/big_query_adapter/database_statements.rb