Sha256: 27e199c7976fff522c00828b6b0791eb3fa062d66da2ed51fe84840c5705b141

Contents?: true

Size: 1.61 KB

Versions: 7

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

module DuckDB
  # The DuckDB::PendingResult encapsulates connection with DuckDB pending
  # result.
  # PendingResult provides methods to execute SQL asynchronousely and check
  # if the result is ready and to get the result.
  #
  #   require 'duckdb'
  #
  #   db = DuckDB::Database.open
  #   con = db.connect
  #   stmt = con.prepared_statement(VERY_SLOW_QUERY)
  #   pending_result = stmt.pending_prepared
  #   while pending_result.state == :not_ready
  #     print '.'
  #     sleep(0.01)
  #     pending_result.execute_task
  #   end
  #   result = pending_result.execute_pending
  class PendingResult
    STATES = %i[ready not_ready error no_tasks].freeze

    # returns the state of the pending result.
    # the result can be :ready, :not_ready, :error, :no_tasks.
    #
    # :ready means the result is ready to be fetched, and
    # you can call `execute_pending` to get the result.
    #
    # :not_ready means the result is not ready yet, so
    # you need to call `execute_task`.
    #
    # @return [symbol] :ready, :not_ready, :error, :no_tasks
    def state
      STATES[_state]
    end

    # returns the state of the pending result.
    # the result can be :ready, :not_ready, :error, :no_tasks.
    #
    # :ready means the result is ready to be fetched, and
    # you can call `execute_pending` to get the result.
    #
    # :not_ready or :no_tasks might mean the pending result
    # is not executed yet, so you need to call `execute_task`.
    #
    # @return [symbol] :ready, :not_ready, :error, :no_tasks
    def execute_check_state
      STATES[_execute_check_state]
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
duckdb-1.1.3.1 lib/duckdb/pending_result.rb
duckdb-1.1.3.0 lib/duckdb/pending_result.rb
duckdb-1.1.2.1 lib/duckdb/pending_result.rb
duckdb-1.1.2.0 lib/duckdb/pending_result.rb
duckdb-1.1.1.0 lib/duckdb/pending_result.rb
duckdb-1.1.0.1 lib/duckdb/pending_result.rb
duckdb-1.1.0.0 lib/duckdb/pending_result.rb