Class: Tarantool::BaseRecord::Select

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/tarantool/record/select.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record, params = {}) ⇒ Select

Returns a new instance of Select.



7
8
9
10
# File 'lib/tarantool/record/select.rb', line 7

def initialize(record, params={})
  @record = record
  @params = params
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



6
7
8
# File 'lib/tarantool/record/select.rb', line 6

def params
  @params
end

#recordObject (readonly)

Returns the value of attribute record.



6
7
8
# File 'lib/tarantool/record/select.rb', line 6

def record
  @record
end

Instance Method Details

#allObject Also known as: to_a



63
64
65
# File 'lib/tarantool/record/select.rb', line 63

def all
  results.dup
end

#auto_shardObject



57
58
59
60
61
# File 'lib/tarantool/record/select.rb', line 57

def auto_shard
  params = @params.dup
  params.delete :shard
  self.class.new(@record, params)
end

#call(*args) ⇒ Object



37
38
39
# File 'lib/tarantool/record/select.rb', line 37

def call(*args)
  @record.call(*args)
end

#eachObject



32
33
34
35
# File 'lib/tarantool/record/select.rb', line 32

def each
  return to_enum  unless block_given?
  results.each{|a| yield a}
end

#firstObject



68
69
70
# File 'lib/tarantool/record/select.rb', line 68

def first
  space.select(@params[:where], @params[:offset] || 0, 1).first
end

#limit(limit) ⇒ Object



41
42
43
# File 'lib/tarantool/record/select.rb', line 41

def limit(limit)
  self.class.new(@record, @params.merge(limit: limit))
end

#offset(offset) ⇒ Object



45
46
47
# File 'lib/tarantool/record/select.rb', line 45

def offset(offset)
  self.class.new(@record, @params.merge(offset: offset))
end

#reset!Object



27
28
29
30
# File 'lib/tarantool/record/select.rb', line 27

def reset!
  @results = nil
  self
end

#resultsObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/tarantool/record/select.rb', line 16

def results
  @results ||= begin
      raise "Condition is not set"  unless @params[:where]
      @record.auto_space.select(
        @params[:where],
        @params[:offset] || 0,
        @params[:limit] || -1
      )
    end
end

#shard(params) ⇒ Object



53
54
55
# File 'lib/tarantool/record/select.rb', line 53

def shard(params)
  self.class.new(@record, @params.merge(shard: params))
end

#spaceObject



72
73
74
75
# File 'lib/tarantool/record/select.rb', line 72

def space
  space = @record.auto_space
  @params[:shard] ? space.shard(@params[:shard]) : space
end

#space_noObject



12
13
14
# File 'lib/tarantool/record/select.rb', line 12

def space_no
  @record.space_no
end

#where(params) ⇒ Object



49
50
51
# File 'lib/tarantool/record/select.rb', line 49

def where(params)
  self.class.new(@record, @params.merge(where: params))
end