Method: CrateRuby::Client#execute

Defined in:
lib/crate_ruby/client.rb

#execute(sql, args = nil, bulk_args = nil, http_options = {}) ⇒ ResultSet

Executes a SQL statement against the Crate HTTP REST endpoint.

Parameters:

  • sql (String)

    statement to execute

  • args (Array) (defaults to: nil)

    Array of values used for parameter substitution

  • bulk_args (Array) (defaults to: nil)

    List of lists containing records to be processed

  • http_options (Hash) (defaults to: {})

    Net::HTTP options (open_timeout, read_timeout)

Returns:



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/crate_ruby/client.rb', line 115

def execute(sql, args = nil, bulk_args = nil, http_options = {})
  @logger.debug sql
  req = Net::HTTP::Post.new('/_sql', headers)
  body = { 'stmt' => sql }
  body['args'] = args if args
  body['bulk_args'] = bulk_args if bulk_args
  req.body = body.to_json
  response = request(req, http_options)
  @logger.debug response.body

  case response.code
  when /^2\d{2}/
    ResultSet.new response.body
  else
    @logger.info(response.body)
    raise CrateRuby::CrateError, response.body
  end
end