Object
# File lib/tarantool/space_array.rb, line 13 def initialize(tarantool, space_no, fields, indexes, shard_fields = nil, shard_proc = nil) @tarantool = tarantool @space_no = space_no fields = ([*fields].empty? ? TYPES_AUTO : fields).dup tail_size = Integer === fields.last ? fields.pop : 1 fields.map!{|type| check_type(type)} fields << tail_size @fields = fields indexes = [*indexes].map{|ind| frozen_array(ind) }.freeze if !indexes.empty? @index_fields = indexes @indexes = _map_indexes(indexes) else @index_fields = [] @indexes = [TYPES_FALLBACK] end shard_fields ||= @index_fields[0] unless shard_fields || @tarantool.shards_count == 1 raise ArgumentError, "You could not use space without specifying primary key or shard fields when shards count is greater than 1" else @shard_fields = [*shard_fields] @shard_positions = @shard_fields _init_shard_vars(shard_proc) end end
# File lib/tarantool/space_array.rb, line 73 def _fix_index_fields(index_fields, keys) sorted = index_fields.sort if index_no = @index_fields.index{|fields| fields.take(index_fields.size).sort == sorted} real_fields = @index_fields[index_no] permutation = index_fields.map{|i| real_fields.index(i)} keys = [*keys].map{|v| [*v].values_at(*permutation)} [index_no, keys] end end
# File lib/tarantool/space_array.rb, line 42 def _map_indexes(indexes) indexes.map do |index| (index.map do |i| unless (field = @fields[i]) && !field.is_a?(Integer) raise ArgumentError, "Wrong index field number: #{index} #{i}" end field end << :error).freeze end.freeze end
callback with block api
# File lib/tarantool/space_array.rb, line 162 def all_by_key_blk(index_no, key, opts={}, &block) all_by_key_cb(index_no, key, block, opts) end
# File lib/tarantool/space_array.rb, line 61 def all_by_key_cb(index_no, key, cb, opts={}) select_cb(index_no, [key], opts[:offset] || 0, opts[:limit] || -1, cb) end
# File lib/tarantool/space_array.rb, line 170 def all_by_keys_blk(index_no, keys, opts={}, &block) all_by_keys_cb(index_no, keys, block, opts) end
# File lib/tarantool/space_array.rb, line 69 def all_by_keys_cb(index_no, keys, cb, opts = {}) select_cb(index_no, keys, opts[:offset] || 0, opts[:limit] || -1, cb) end
# File lib/tarantool/space_array.rb, line 53 def all_by_pks_cb(keys, cb, opts={}) all_by_keys_cb(0, keys, cb, opts) end
# File lib/tarantool/space_array.rb, line 57 def by_pk_cb(pk, cb) first_by_key_cb(0, pk, cb) end
# File lib/tarantool/space_array.rb, line 151 def call_cb(func_name, values, cb, opts = {}) values, opts = _space_call_fix_values(values, @space_no, opts) opts[:return_tuple] = true if opts[:return_tuple].nil? opts[:returns] ||= @fields if opts[:return_tuple] _call(func_name, values, cb, opts) end
# File lib/tarantool/space_array.rb, line 139 def delete_cb(pk, cb, opts = {}) shard_nums = _get_shard_nums{ _detect_shards_for_key(pk, 0) } _delete(@space_no, pk, @fields, @indexes[0] || _detect_types([*pk]), cb, opts[:return_tuple], shard_nums) end
# File lib/tarantool/space_array.rb, line 166 def first_by_key_blk(index_no, key, &block) first_by_key_cb(index_no, key, block) end
# File lib/tarantool/space_array.rb, line 65 def first_by_key_cb(index_no, key, cb) select_cb(index_no, [key], 0, :first, cb) end
# File lib/tarantool/space_array.rb, line 109 def insert_cb(tuple, cb, opts = {}) shard_nums = detect_shard_for_insert(tuple.values_at(*@shard_positions)) _insert(@space_no, BOX_ADD, tuple, @fields, cb, opts[:return_tuple], shard_nums) end
# File lib/tarantool/space_array.rb, line 146 def invoke_cb(func_name, values, cb, opts = {}) values, opts = _space_call_fix_values(values, @space_no, opts) _call(func_name, values, cb, opts) end
# File lib/tarantool/space_array.rb, line 114 def replace_cb(tuple, cb, opts = {}) shard_nums = detect_shard(tuple.values_at(*@shard_positions)) _insert(@space_no, BOX_REPLACE, tuple, @fields, cb, opts[:return_tuple], shard_nums, opts.fetch(:in_any_shard, true)) end
# File lib/tarantool/space_array.rb, line 174 def select_blk(index_no, keys, offset=0, limit=-1, &block) select_cb(index_no, keys, offset, limit, block) end
# File lib/tarantool/space_array.rb, line 83 def select_cb(index_no, keys, offset, limit, cb) if Array === index_no raise ArgumentError, "Has no defined indexes to search index #{index_no}" if @index_fields.empty? index_fields = index_no index_no = @index_fields.index{|fields| fields.take(index_fields.size) == index_fields} unless index_no || index_fields.size == 1 index_no, keys = _fix_index_fields(index_fields, keys) unless index_no raise(ArgumentError, "Not found index with field numbers #{index_no}, " + "(defined indexes #{@index_fields})") end end end unless @index_fields.empty? unless index_types = @indexes[index_no] raise ArgumentError, "No index ##{index_no}" end else index_types = _detect_types([*[*keys][0]]) end shard_nums = _get_shard_nums { _detect_shards_for_keys(keys, index_no) } _select(@space_no, index_no, offset, limit, keys, cb, @fields, index_types, shard_nums) end
# File lib/tarantool/space_array.rb, line 120 def store_cb(tuple, cb, opts = {}) shard_nums = _get_shard_nums{ if opts.fetch(:to_insert_shard, true) _detect_shard_for_insert(tuple.values_at(*@shard_positions)) else _detect_shard(tuple.values_at(*@shard_positions)) end } _insert(@space_no, 0, tuple, @fields, cb, opts[:return_tuple], shard_nums) end
# File lib/tarantool/space_array.rb, line 131 def update_cb(pk, operations, cb, opts = {}) shard_nums = _get_shard_nums{ _detect_shards_for_key(pk, 0) } _update(@space_no, pk, operations, @fields, @indexes[0] || _detect_types([*pk]), cb, opts[:return_tuple], shard_nums) end
Generated with the Darkfish Rdoc Generator 2.