Class: Tarantool::Query

Inherits:
Object
  • Object
show all
Includes:
Request
Defined in:
lib/tarantool/query.rb

Direct Known Subclasses

BlockDB::Query, CallbackDB::Query, FiberDB::Query

Constant Summary

Constants included from Request

Request::BINARY, Request::BOX_ADD, Request::BOX_REPLACE, Request::BOX_RETURN_TUPLE, Request::CALL_HEADER, Request::DELETE_HEADER, Request::EMPTY, Request::INSERT_HEADER, Request::INT32_0, Request::INT32_1, Request::LEST_INT32, Request::MAX_BYTE_SIZE, Request::ONE, Request::PACK_STRING, Request::REQUEST_CALL, Request::REQUEST_DELETE, Request::REQUEST_INSERT, Request::REQUEST_PING, Request::REQUEST_SELECT, Request::REQUEST_UPDATE, Request::SELECT_HEADER, Request::TYPES_AUTO, Request::TYPES_FALLBACK, Request::TYPES_STR_AUTO, Request::TYPES_STR_STR, Request::UPDATE_FIELDNO_OP, Request::UPDATE_HEADER, Request::UPDATE_OPS, Request::ZERO

Constants included from Serializers

Serializers::MAP

Constants included from Util::Packer

Util::Packer::INT16, Util::Packer::INT32, Util::Packer::INT64, Util::Packer::INT8, Util::Packer::MAX_INT16, Util::Packer::MAX_INT32, Util::Packer::MAX_INT64, Util::Packer::MAX_INT8, Util::Packer::MAX_SINT16, Util::Packer::MAX_SINT32, Util::Packer::MAX_SINT64, Util::Packer::MAX_SINT8, Util::Packer::MIN_INT, Util::Packer::MIN_SINT16, Util::Packer::MIN_SINT32, Util::Packer::MIN_SINT64, Util::Packer::MIN_SINT8, Util::Packer::SINT16, Util::Packer::SINT32, Util::Packer::SINT64, Util::Packer::SINT8

Instance Attribute Summary

Attributes included from Request

#insert_with_shards_count, #previous_shards_count, #shard_proc, #shards_count

Instance Method Summary collapse

Methods included from Request

#_all_shards, #_call, #_delete, #_detect_shard, #_detect_shard_for_insert, #_detect_shards, #_detect_shards_for_insert, #_detect_shards_for_key, #_detect_shards_for_keys, #_detect_type, #_detect_types, #_flat_uniq, #_get_shard_nums, #_init_shard_vars, #_insert, #_modify_request, #_pack_operations, #_parse_hash_definition, #_ping, #_raise_integer_overflow, #_raise_or_return, #_select, #_send_request, #_space_call_fix_values, #_update, #all_shards, #detect_shard, #detect_shard_for_insert, #detect_shards, #detect_shards_for_insert, #pack_field, #pack_tuple, #shard

Methods included from Serializers

#check_type, #get_serializer

Constructor Details

#initialize(tarantool) ⇒ Query

Returns a new instance of Query.



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

def initialize(tarantool)
  @tarantool = tarantool
  _init_shard_vars(nil, false)
end

Instance Method Details

#all_blk(space_no, index_no, keys, opts = {}, &block) ⇒ Object



93
94
95
# File 'lib/tarantool/query.rb', line 93

def all_blk(space_no, index_no, keys, opts={}, &block)
  all_cb(space_no, index_no, keys, block, opts)
end

#all_cb(space_no, index_no, keys, cb, opts = {}) ⇒ Object



23
24
25
26
27
# File 'lib/tarantool/query.rb', line 23

def all_cb(space_no, index_no, keys, cb, opts={})
  select_cb(space_no, index_no, keys,
            opts[:offset] || 0, opts[:limit] || -1,
            cb, opts)
end

#call_blk(func_name, values, opts = {}, &block) ⇒ Object



125
126
127
# File 'lib/tarantool/query.rb', line 125

def call_blk(func_name, values, opts={}, &block)
  call_cb(func_name, values, block, opts)
end

#call_cb(func_name, values, cb, opts = {}) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/tarantool/query.rb', line 77

def call_cb(func_name, values, cb, opts={})
  opts = opts.dup
  values = [*values]
  opts[:return_tuple] = true  if opts[:return_tuple].nil?
  opts[:types] ||= _detect_types(values)
  opts[:returns] ||= TYPES_AUTO
  if Hash === opts[:returns] && opts[:return_tuple]
    opts[:returns], *opts[:translators] = _parse_hash_definition(opts[:returns])
  end
  _call(func_name, values, cb, opts)
end

#delete_blk(space_no, pk, opts = {}, &block) ⇒ Object



117
118
119
# File 'lib/tarantool/query.rb', line 117

def delete_blk(space_no, pk, opts={}, &block)
  delete_cb(space_no, pk, block, opts)
end

#delete_cb(space_no, pk, cb, opts = {}) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/tarantool/query.rb', line 59

def delete_cb(space_no, pk, cb, opts={})
  pk = [*pk]
  pk_types = opts[:pk_types] || _detect_types(pk)
  returns = opts[:returns] || TYPES_AUTO
  if Hash === returns && opts[:return_tuple]
    returns, *translators = _parse_hash_definition(returns)
  end
  _delete(space_no, pk, returns, pk_types, cb,
          opts[:return_tuple], all_shards, translators)
end

#first_blk(space_no, index_no, key, opts = {}, &block) ⇒ Object



97
98
99
# File 'lib/tarantool/query.rb', line 97

def first_blk(space_no, index_no, key, opts={}, &block)
  first_cb(space_no, index_no, key, block, opts)
end

#first_cb(space_no, index_no, key, cb, opts = {}) ⇒ Object



29
30
31
# File 'lib/tarantool/query.rb', line 29

def first_cb(space_no, index_no, key, cb, opts={})
  select_cb(space_no, index_no, [key], 0, :first, cb, opts)
end

#insert_blk(space_no, tuple, opts = {}, &block) ⇒ Object



101
102
103
# File 'lib/tarantool/query.rb', line 101

def insert_blk(space_no, tuple, opts={}, &block)
  insert_cb(space_no, tuple, block, opts)
end

#insert_cb(space_no, tuple, cb, opts = {}) ⇒ Object



33
34
35
36
# File 'lib/tarantool/query.rb', line 33

def insert_cb(space_no, tuple, cb, opts={})
  types = opts[:types] || _detect_types(tuple)
  _insert(space_no, BOX_ADD, tuple, types, cb, opts[:return_tuple], all_shards)
end

#invoke_blk(func_name, values, opts = {}, &block) ⇒ Object



121
122
123
# File 'lib/tarantool/query.rb', line 121

def invoke_blk(func_name, values, opts={}, &block)
  invoke_cb(func_name, values, block, opts)
end

#invoke_cb(func_name, values, cb, opts = {}) ⇒ Object



70
71
72
73
74
75
# File 'lib/tarantool/query.rb', line 70

def invoke_cb(func_name, values, cb, opts={})
  opts = opts.dup
  values = [*values]
  opts[:types] ||= _detect_types(values)
  _call(func_name, values, cb, opts)
end

#ping_blk(&block) ⇒ Object



129
130
131
# File 'lib/tarantool/query.rb', line 129

def ping_blk(&block)
  ping_cb(block)
end

#replace_blk(space_no, tuple, opts = {}, &block) ⇒ Object



105
106
107
# File 'lib/tarantool/query.rb', line 105

def replace_blk(space_no, tuple, opts={}, &block)
  replace_cb(space_no, tuple, block, opts)
end

#replace_cb(space_no, tuple, cb, opts = {}) ⇒ Object



38
39
40
41
# File 'lib/tarantool/query.rb', line 38

def replace_cb(space_no, tuple, cb, opts={})
  types = opts[:types] || _detect_types(tuple)
  _insert(space_no, BOX_REPLACE, tuple, types, cb, opts[:return_tuple], all_shards)
end

#select_blk(space_no, index_no, keys, offset, limit, opts = {}, &block) ⇒ Object



89
90
91
# File 'lib/tarantool/query.rb', line 89

def select_blk(space_no, index_no, keys, offset, limit, opts={}, &block)
  select_cb(space_no, index_no, keys, offset, limit, block, opts)
end

#select_cb(space_no, index_no, keys, offset, limit, cb, opts = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/tarantool/query.rb', line 12

def select_cb(space_no, index_no, keys, offset, limit, cb, opts={})
  keys = [*keys]
  types = opts[:types] || _detect_types(keys)
  returns = opts[:returns] || TYPES_AUTO
  if Hash === returns
    returns, *translators = _parse_hash_definition(returns)
  end
  _select(space_no, index_no, offset, limit, keys, cb, returns,
          types, all_shards, translators)
end

#store_blk(space_no, tuple, opts = {}, &block) ⇒ Object



109
110
111
# File 'lib/tarantool/query.rb', line 109

def store_blk(space_no, tuple, opts={}, &block)
  store_cb(space_no, tuple, block, opts)
end

#store_cb(space_no, tuple, cb, opts = {}) ⇒ Object



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

def store_cb(space_no, tuple, cb, opts={})
  types = opts[:types] || _detect_types(tuple)
  _insert(space_no, 0, tuple, types, cb, opts[:return_tuple], all_shards)
end

#update_blk(space_no, pk, operation, opts = {}, &block) ⇒ Object



113
114
115
# File 'lib/tarantool/query.rb', line 113

def update_blk(space_no, pk, operation, opts={}, &block)
  update_cb(space_no, pk, operation, block, opts={})
end

#update_cb(space_no, pk, operations, cb, opts = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/tarantool/query.rb', line 48

def update_cb(space_no, pk, operations, cb, opts={})
  pk = [*pk]
  pk_types = opts[:pk_types] || _detect_types(pk)
  returns = opts[:returns] || TYPES_AUTO
  if Hash === returns && opts[:return_tuple]
    returns, *translators = _parse_hash_definition(returns)
  end
  _update(space_no, pk, operations, returns, pk_types, cb,
          opts[:return_tuple], all_shards, translators)
end