Files

Class/Module Index [+]

Quicksearch

Tarantool::BaseRecord::ClassMethods

Public Instance Methods

_tail(*types) click to toggle source
# File lib/tarantool/base_record.rb, line 78
def _tail(*types)
  types = types.map{|type| Serializers.check_type(type)}

  raise ArgumentError, "double _tail declaration"  if fields.include?(:_tail)
  self.fields = fields.merge(:_tail => types)

  define_field_accessor(:_tail, types)
end
all(cond, opts={}) click to toggle source
# File lib/tarantool/base_record.rb, line 184
def all(cond, opts={})
  res = space.all(cond, opts)
  res.map!{|hash| from_fetched(hash)}
  res
end
auto_space() click to toggle source

space that will return records as results for calls it is useful, if you wish to use callback interface

# File lib/tarantool/base_record.rb, line 145
def auto_space
  @auto_space ||= begin
      space.with_translator(method(:from_fetched))
    end
end
by_pk(pk) click to toggle source
# File lib/tarantool/base_record.rb, line 156
def by_pk(pk)
  if Hash === (res = space.by_pk(pk))
    from_fetched(res)
  end
end
by_pks(pks) click to toggle source
# File lib/tarantool/base_record.rb, line 162
def by_pks(pks)
  space.all_by_pks(pks).map{|hash| from_fetched(hash)}
end
call(proc_name, *args) click to toggle source

Call stored procedure. By default, it prepends space_no to arguments. To avoid prepending, set +space_no: nil+ in options.

MyRecord.call('box.select_range', offset, limit)
MyRecord.call('myfunction', arg1, arg2, space_no: nil)

You could recieve arbitarry arrays or hashes instead of instances of record, if you pass :returns argument. See documentation for SpaceHash for this.

# File lib/tarantool/base_record.rb, line 220
def call(proc_name, *args)
  opts = Hash === args.last ? args.pop : {}
  res = space.call(proc_name, args, opts)
  if Array === res && !opts[:returns]
    res.map{|hash| from_fetched(hash) }
  else
    res
  end
end
create(attributes = {}) click to toggle source
# File lib/tarantool/base_record.rb, line 194
def create(attributes = {})
  r = new(attributes)
  r.save
  r
end
delete(pk, ret_tuple=false) click to toggle source
# File lib/tarantool/base_record.rb, line 269
def delete(pk, ret_tuple=false)
  if ret_tuple
    from_fetched space.delete(pk, return_tuple: true)
  else
    space.delete(pk)
  end
end
field(name, type, params = {}) click to toggle source
# File lib/tarantool/base_record.rb, line 64
def field(name, type, params = {})
  type = Serializers.check_type(type)

  raise ArgumentError, "_tail should be last declaration"  if fields.include?(:_tail)
  self.fields = fields.merge(name => type)
  index name  if indexes.empty?

  if params[:default]
    self.default_values = default_values.merge name => params[:default]
  end

  define_field_accessor(name, type)
end
find(*args) click to toggle source
# File lib/tarantool/base_record.rb, line 166
def find(*args)
  if args.size == 1
    by_pk(args[0])
  else
    by_pks(args)
  end
end
first(cond) click to toggle source
# File lib/tarantool/base_record.rb, line 174
def first(cond)
  if Hash === cond
    if Hash === (res = space.first(cond))
      from_fetched(res)
    end
  else
    by_pk(cond)
  end
end
from_fetched(hash) click to toggle source
# File lib/tarantool/base_record.rb, line 230
def from_fetched(hash)
  hash && allocate.__fetched(hash)
end
index(*fields) click to toggle source
# File lib/tarantool/base_record.rb, line 87
def index(*fields)
  options = Hash === fields.last ? fields.pop : {}
  if options[:primary]
    self.indexes = indexes.dup.tap{|ind| ind[0] = fields}
  else
    self.indexes += [fields]
  end
end
insert(hash, ret_tuple = false) click to toggle source
# File lib/tarantool/base_record.rb, line 234
def insert(hash, ret_tuple = false)
  hash = default_values.merge(hash)
  if ret_tuple
    from_fetched space.insert(hash, return_tuple: true)
  else
    space.insert(hash)
  end
end
invoke(proc_name, *args) click to toggle source

Call stored procedure without returning tuples. By default, it prepends space_no to arguments. To avoid prepending, set +space_no: nil+ in options.

MyRecord.call('box.select_range', offset, limit)
MyRecord.call('myfunction', arg1, arg2, space_no: nil)
# File lib/tarantool/base_record.rb, line 206
def invoke(proc_name, *args)
  opts = Hash === args.last ? args.pop : {}
  space.invoke(proc_name, args, opts)
end
primary_index() click to toggle source
# File lib/tarantool/base_record.rb, line 113
def primary_index
  indexes[0]
end
replace(hash, ret_tuple = false) click to toggle source
# File lib/tarantool/base_record.rb, line 243
def replace(hash, ret_tuple = false)
  hash = default_values.merge(hash)
  if ret_tuple
    from_fetched space.replace(hash, return_tuple: true)
  else
    space.replace(hash)
  end
end
reset_space!() click to toggle source
# File lib/tarantool/base_record.rb, line 151
def reset_space!
  @space = nil
  @auto_space = nil
end
select(cond=nil, opts={}) click to toggle source
# File lib/tarantool/base_record.rb, line 190
def select(cond=nil, opts={})
  cond.nil? ? Select.new(self) : all(cond, opts)
end
set_shard_fields(*args) click to toggle source
Alias for: shard_fields
set_space_no(v) click to toggle source
Alias for: space_no=
set_tarantool(v) click to toggle source
Alias for: tarantool=
shard_fields(*args) click to toggle source
# File lib/tarantool/base_record.rb, line 104
def shard_fields(*args)
  if args.empty?
    _shard_fields
  else
    self._shard_fields = args
  end
end
Also aliased as: set_shard_fields
shard_proc(cb = nil, &block) click to toggle source
# File lib/tarantool/base_record.rb, line 96
def shard_proc(cb = nil, &block)
  if cb ||= block
    self._shard_proc = cb
  else
    _shard_proc
  end
end
space() click to toggle source
# File lib/tarantool/base_record.rb, line 117
def space
  @space ||= begin
      shard_fields = _shard_fields || primary_index
      shard_proc = _shard_proc ||
        if shard_fields.size == 1
          case fields[shard_fields[0]]
          when :int, :int16, :int8
            :sumbur_murmur_fmix
          when :int64
            :sumbur_murmur_int64
          when :string
            :sumbur_murmur_str
          else
            :default
          end
        else
          :default
        end
      _tarantool.space_hash(_space_no, fields.dup,
                           keys: indexes,
                           shard_fields: shard_fields,
                           shard_proc: shard_proc
                          )
    end
end
space_no(v=nil) click to toggle source
# File lib/tarantool/base_record.rb, line 50
def space_no(v=nil)
  unless v
    _space_no
  else
    self.space_no = v
  end
end
space_no=(v) click to toggle source
# File lib/tarantool/base_record.rb, line 58
def space_no=(v)
  reset_space!
  self._space_no = v
end
Also aliased as: set_space_no
store(hash, ret_tuple = false) click to toggle source
# File lib/tarantool/base_record.rb, line 252
def store(hash, ret_tuple = false)
  hash = default_values.merge(hash)
  if ret_tuple
    from_fetched space.store(hash, return_tuple: true)
  else
    space.store(hash)
  end
end
tarantool(v=nil) click to toggle source
# File lib/tarantool/base_record.rb, line 33
def tarantool(v=nil)
  unless v
    _tarantool
  else
    self.tarantool = v
  end
end
tarantool=(v) click to toggle source
# File lib/tarantool/base_record.rb, line 41
def tarantool=(v)
  reset_space!
  unless ::Tarantool::DB === v && v.primary_interface == :synchronous
    raise ArgumentError, "you may assing to record's tarantool only instances of Tarantool::BlockDB or Tarantool::FiberDB"
  end
  self._tarantool= v
end
Also aliased as: set_tarantool
update(pk, ops, ret_tuple=false) click to toggle source
# File lib/tarantool/base_record.rb, line 261
def update(pk, ops, ret_tuple=false)
  if ret_tuple
    from_fetched space.update(pk, ops, return_tuple: true)
  else
    space.update(pk, ops)
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.