tarantool16 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af64fb29db82e36fb7a370dd4136cdff47398588
4
- data.tar.gz: 6c8fcaf9af9c9fe7547f369aec65d2fdd4148a10
3
+ metadata.gz: 63c6f3dd4aa811b1cb867865472ca56c2ebafb90
4
+ data.tar.gz: 009fceed5451625228f289889a4b000d6595e6ea
5
5
  SHA512:
6
- metadata.gz: 5190f23a23de008bfd24c08a2170418941f5d99af23dda05e9c166ea5b0599a3bd8dec79da6309a32dea7c33e94ee498148d1f4d776a8bfb213425769d166d06
7
- data.tar.gz: f1b4bccd8d7402b88b3a30ebd9e403fb727586fed05e54051a977f1127db9fdd2391b053e7f8824ca1d941d4671caa49769fd6895e1ced7f8613b0c70216b068
6
+ metadata.gz: 52ec4a7a31e37024fc0aac40f23812d6fa0a153526fd4eb5ca017c5d8bc4ea084a590e9ed0c1c6f043a85ff7485de956657ede835f81e89cc54cbc6907b04fc8
7
+ data.tar.gz: 2a82a91c5288ced4bdbe9f0e878464cc07aff7704314f398025b21785ee7a40291e5088c88144eac1f29b0a55a8864ee5900ff7a2bfe36c620c95d8a395b65fa
data/README.md CHANGED
@@ -71,6 +71,8 @@ tar.update(:_space, {name: 'test'}, {format: [:=, [{name: :id, type: :num}, {nam
71
71
 
72
72
  ## Changelog
73
73
 
74
+ 0.0.8 - Fix schema read from new tarantool versions
75
+ Implement UPSERT
74
76
  0.0.7 - Implement EVAL, fix REPLACE
75
77
  0.0.6 - DumbConnection supports timeouts
76
78
 
@@ -194,6 +194,14 @@ module Tarantool16
194
194
  send_request(REQUEST_TYPE_UPDATE, req, cb)
195
195
  end
196
196
 
197
+ def _upsert(space_no, index_no, tuple_key, ops, cb)
198
+ req = {IPROTO_SPACE_ID => space_no,
199
+ IPROTO_INDEX_ID => index_no,
200
+ IPROTO_TUPLE => tuple_key,
201
+ IPROTO_DEF_DUPLE => ops}
202
+ send_request(REQUEST_TYPE_UPSERT, req, cb)
203
+ end
204
+
197
205
  def _call(name, args, cb)
198
206
  req = {IPROTO_FUNCTION_NAME => name,
199
207
  IPROTO_TUPLE => args}
@@ -11,6 +11,7 @@ module Tarantool16
11
11
  IPROTO_FUNCTION_NAME = 0x22
12
12
  IPROTO_USER_NAME = 0x23
13
13
  IPROTO_EXPR = 0x27
14
+ IPROTO_DEF_DUPLE = 0x28
14
15
  IPROTO_DATA = 0x30
15
16
  IPROTO_ERROR = 0x31
16
17
 
@@ -26,6 +27,7 @@ module Tarantool16
26
27
  REQUEST_TYPE_CALL = 6
27
28
  REQUEST_TYPE_AUTHENTICATE = 7
28
29
  REQUEST_TYPE_EVAL = 8
30
+ REQUEST_TYPE_UPSERT = 9
29
31
  REQUEST_TYPE_ERROR = 1 << 15
30
32
 
31
33
 
@@ -114,7 +114,14 @@ module Tarantool16
114
114
 
115
115
  def _fill_indices(spaces, rows)
116
116
  rows.
117
- map{|row| [row[0], [row[2], row[1], row[3], 6.step(row.size-1, 2).map{|i| row[i]}]]}.
117
+ map{|row|
118
+ if row[4].is_a? Hash
119
+ # new format
120
+ [row[0], [row[2], row[1], row[3], row[5].map(&:first)]]
121
+ else
122
+ [row[0], [row[2], row[1], row[3], 6.step(row.size-1, 2).map{|i| row[i]}]]
123
+ end
124
+ }.
118
125
  group_by{|sid, _| sid}.
119
126
  each do |sid, inds|
120
127
  sp = spaces[sid]
@@ -193,6 +200,22 @@ module Tarantool16
193
200
  end
194
201
  end
195
202
 
203
+ def _upsert(sno, ino, tuple_key, ops, need_hash, cb)
204
+ ino = 0 if ino.nil?
205
+ ops_good = ops.is_a?(Array) && ops.all?{|a| ops[1].is_a?(Integer)}
206
+ if sno.is_a?(Integer) && ino.is_a?(Integer) && tuple_key.is_a?(Array) && ops_good
207
+ return conn._upsert(sno, ino, tuple_key, ops, cb)
208
+ end
209
+ _with_space(sno, cb) do |sp|
210
+ _tuple = tuple_key.is_a?(Hash) ? sp.map_tuple(tuple_key) : tuple_key
211
+ sp.get_ino(ino, nil, ITERATOR_EQ, cb) do |_ino, _key|
212
+ _ops = ops_good ? ops : sp.map_ops(ops)
213
+ _cb = need_hash ? sp.wrap_cb(cb) : cb
214
+ conn._upsert(sp.sid, _ino, tuple_key, _ops, _cb)
215
+ end
216
+ end
217
+ end
218
+
196
219
  def _call(name, args, cb)
197
220
  conn._call(name, args, cb)
198
221
  end
@@ -59,6 +59,12 @@ module Tarantool16
59
59
  _update(sno, ino, key, ops, need_hash, RETURN_OR_RAISE)
60
60
  end
61
61
 
62
+ def upsert(sno, tuple_key, ops, opts = {})
63
+ ino = opts[:index] || 0
64
+ need_hash = opts.fetch(:hash, Hash === tuple_key)
65
+ _upsert(sno, ino, tuple_key, ops, need_hash, RETURN_OR_RAISE)
66
+ end
67
+
62
68
  def call(name, args)
63
69
  _call(name, args, RETURN_OR_RAISE)
64
70
  end
@@ -260,7 +260,7 @@ module Tarantool16
260
260
  end
261
261
 
262
262
  def map_key(key)
263
- return key if key.is_a?(Array)
263
+ return key if key.is_a?(Array) || key.nil?
264
264
  res = []
265
265
  positions = @part_positions
266
266
  key.each_key do |k|
@@ -1,3 +1,3 @@
1
1
  module Tarantool16
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/test/config.lua CHANGED
@@ -11,12 +11,20 @@ if not box.space.test then
11
11
  local irtree = s1:create_index('point', {type = 'rtree', unique=false, parts = {3, 'ARRAY'}, if_not_exists = true})
12
12
  local ipname = s1:create_index('id_name', {type = 'tree', parts = {1, 'NUM', 2, 'STR'}})
13
13
  end
14
+ if not box.space.test1 then
15
+ local s2 = box.schema.space.create('test1', {id = 514, if_not_exists = true})
16
+ local ip = s2:create_index('primary', {type = 'hash', parts = {1, 'NUM'}, if_not_exists = true})
17
+ end
14
18
 
15
19
  function reseed()
16
20
  local s1 = box.space.test
17
21
  s1:truncate()
18
22
  s1:insert{1, "hello", {1, 2}, 100}
19
23
  s1:insert{2, "world", {3, 4}, 200}
24
+ local s2 = box.space.test1
25
+ s2:truncate()
26
+ s2:insert{1, "hello", {1, 2}, 100}
27
+ s2:insert{2, "world", {3, 4}, 200}
20
28
  end
21
29
 
22
30
  pcall(function()
data/test/test_dumb.rb CHANGED
@@ -59,6 +59,13 @@ describe 'DumbConnection' do
59
59
  db.update(:test, "world", {1 => [':', 6, 0, '!']}, index: 1).must_equal [rwith(r2,1,"world!")]
60
60
  end
61
61
 
62
+ it "should upsert" do
63
+ db.upsert(:test1, [1, 'hallo', [7,5], 999], [[:+, 3, 1]])
64
+ db.select(:test1, 1).must_equal [rwith(r1,3,101)]
65
+ db.upsert(:test1, r3, [[:+, 3, 1]])
66
+ db.select(:test1, 3).must_equal [r3]
67
+ end
68
+
62
69
  it "should delete" do
63
70
  db.delete(:test, 1).must_equal [r1]
64
71
  db.delete(:test, "world", index: 1).must_equal [r2]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tarantool16
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sokolov Yura aka funny_falcon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-05 00:00:00.000000000 Z
11
+ date: 2016-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler