Class: Couchbase::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase/query.rb

Constant Summary collapse

METHOD_MAPPING =
{
  :include_docs       => :setIncludeDocs,
  :descending         => :setDescending,
  :key                => :setKey,
  :keys               => :setKeys,
  :start_key          => :setRangeStart,
  :startkey           => :setRangeStart,
  :startkey_docid     => :setStartkeyDocID,
  :endkey             => :setRangeEnd,
  :endkey_docid       => :setEndkeyDocID,
  :inclusive_end      => :setInclusiveEnd,
  :limit              => :setLimit,
  :skip               => :setSkip,
  :reduce             => :setReduce,
  :group              => :setGroup,
  :group_level        => :setGroupLevel,
  :connection_timeout => nil
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Query

Returns a new instance of Query.



43
44
45
# File 'lib/couchbase/query.rb', line 43

def initialize(params)
  @params = params
end

Instance Method Details

#generateObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/couchbase/query.rb', line 47

def generate
  query = Java::ComCouchbaseClientProtocolViews::Query.new

  stale = @params.delete(:stale)
  if !stale.nil?
    case stale
    when :after_update
      query.setStale(Stale::UPDATE_AFTER)
    when :ok
      query.setStale(Stale::OK)
    when false
      query.setStale(Stale::FALSE)
    end
  end

  @params.each_pair do |meth, val|
    if METHOD_MAPPING.key?(meth)
      if java_meth = METHOD_MAPPING[meth]
        query.send(java_meth, val)
      end
    else
      fail ArgumentError, "Query does not support #{meth}"
    end
  end


  # @option params [true, false] :quiet (true) Do not raise error if
  #   associated document not found in the memory. If the parameter +true+
  #   will use +nil+ value instead.
  # @option params [String, Symbol] :on_error (:continue) Sets the
  #   response in the event of an error. Supported values:
  #   :continue:: Continue to generate view information in the event of an
  #               error, including the error information in the view
  #               response stream.
  #   :stop::     Stop immediately when an error condition occurs. No
  #               further view information will be returned.
  # @option params [Fixnum] :connection_timeout (75000) Timeout before the
  #   view request is dropped (milliseconds)


  # @option params [Hash] :body
  query
end