primary_index()
click to toggle source
# File lib/tarantool/base_record.rb, line 113 def primary_index indexes[0] end
# 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
# 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
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
# File lib/tarantool/base_record.rb, line 156 def by_pk(pk) if Hash === (res = space.by_pk(pk)) from_fetched(res) end end
# File lib/tarantool/base_record.rb, line 162 def by_pks(pks) space.all_by_pks(pks).map{|hash| from_fetched(hash)} end
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
# File lib/tarantool/base_record.rb, line 194 def create(attributes = {}) r = new(attributes) r.save r end
# 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
# 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
# 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
# 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
# File lib/tarantool/base_record.rb, line 230 def from_fetched(hash) hash && allocate.__fetched(hash) end
# 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
# 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
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
# File lib/tarantool/base_record.rb, line 113 def primary_index indexes[0] end
# 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
# File lib/tarantool/base_record.rb, line 151 def reset_space! @space = nil @auto_space = nil end
# File lib/tarantool/base_record.rb, line 190 def select(cond=nil, opts={}) cond.nil? ? Select.new(self) : all(cond, opts) end
# 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
# File lib/tarantool/base_record.rb, line 50 def space_no(v=nil) unless v _space_no else self.space_no = v end end
# File lib/tarantool/base_record.rb, line 58 def space_no=(v) reset_space! self._space_no = v end
# 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
# File lib/tarantool/base_record.rb, line 33 def tarantool(v=nil) unless v _tarantool else self.tarantool = v end end
# 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
Generated with the Darkfish Rdoc Generator 2.