tarantool16 0.0.8 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE.txt +1 -1
- data/README.md +13 -1
- data/lib/tarantool16.rb +13 -1
- data/lib/tarantool16/connection/common.rb +21 -3
- data/lib/tarantool16/connection/dumb.rb +32 -10
- data/lib/tarantool16/connection/response.rb +1 -1
- data/lib/tarantool16/consts.rb +4 -1
- data/lib/tarantool16/db.rb +8 -13
- data/lib/tarantool16/dumb_db.rb +6 -13
- data/lib/tarantool16/errors.rb +76 -4
- data/lib/tarantool16/schema.rb +12 -5
- data/lib/tarantool16/version.rb +1 -1
- data/tarantool16.gemspec +1 -0
- data/test/config.lua +19 -20
- data/test/helper.rb +1 -1
- data/test/test_dumb.rb +7 -2
- metadata +17 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 63754d46ed07662ab888812c32e83af56392c9e0e7793c6cc2c9d0eef8d380b8
|
4
|
+
data.tar.gz: 88d78ada3ee0d7f25accb2467a08e6c136196e8dfbf8df30029a077f141d6298
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1405326f3ee82b5ee9e18208fa80539e03b654646e7b2e2a505bb1c600ae3da4b4752309555623d05c5817797fa14fc39cf74c961968408b16fde0aa6e2abb6
|
7
|
+
data.tar.gz: bf92e1697011c27853b6d954766d97a1a2a970a042c9777a917b68d4bf6d0dca6de93d9991c0f553a6dad92e527874467c9d4216ca9ef7b65fe5ec281f3ea87d
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Tarantool16
|
2
2
|
|
3
|
-
This is adapter for [tarantool](http://tarantool.org) version 1.6.
|
3
|
+
This is adapter for [tarantool](http://tarantool.org) version 1.6 and 1.7.
|
4
4
|
|
5
5
|
(adapter for version <=1.5 is called [tarantool](https://github.org/tarantoool/tarantool-ruby))
|
6
6
|
|
@@ -29,6 +29,9 @@ require 'tarantool16'
|
|
29
29
|
|
30
30
|
db = Tarantool16.new host:'localhost:33013'
|
31
31
|
#db = Tarantool16.new host:'localhost:33013', user:'tester', password:'testpass'
|
32
|
+
#db = Tarantool16.new host:['tcp','localhost:33013']
|
33
|
+
#db = Tarantool16.new host:['unix','path/to.sock']
|
34
|
+
#db = Tarantool16.new unix:'path/to.sock'
|
32
35
|
|
33
36
|
# select from '_space' space info about 'test' table
|
34
37
|
# returns array of tuples as an array
|
@@ -71,6 +74,15 @@ tar.update(:_space, {name: 'test'}, {format: [:=, [{name: :id, type: :num}, {nam
|
|
71
74
|
|
72
75
|
## Changelog
|
73
76
|
|
77
|
+
0.1.0 - breaking change: call now issues request in Tarantool17 format.
|
78
|
+
use call16 to issue `call` request to Tarantool16.
|
79
|
+
see tests for difference in returned results.
|
80
|
+
0.0.11 - change a way of unix socket option.
|
81
|
+
since previos scheme were introduced 12 hours ago,
|
82
|
+
i think it is still safe to change it.
|
83
|
+
0.0.10 - a bit of fixes
|
84
|
+
0.0.9 - Fix detection of update operation shape
|
85
|
+
Add unix socket connection.
|
74
86
|
0.0.8 - Fix schema read from new tarantool versions
|
75
87
|
Implement UPSERT
|
76
88
|
0.0.7 - Implement EVAL, fix REPLACE
|
data/lib/tarantool16.rb
CHANGED
@@ -5,7 +5,19 @@ module Tarantool16
|
|
5
5
|
autoload :DumbDB, 'tarantool16/dumb_db'
|
6
6
|
def self.new(opts = {})
|
7
7
|
opts = opts.dup
|
8
|
-
|
8
|
+
if opts[:unix] && opts[:host]
|
9
|
+
raise "`:host` and `:unix` options are mutually exclusive"
|
10
|
+
elsif opts[:unix]
|
11
|
+
hosts = ["unix", opts[:unix]]
|
12
|
+
elsif opts[:host]
|
13
|
+
host = opts[:host]
|
14
|
+
if Array === host
|
15
|
+
hosts = host
|
16
|
+
else
|
17
|
+
host = [host, opts[:port]].compact.join(':')
|
18
|
+
hosts = ["tcp", host]
|
19
|
+
end
|
20
|
+
end
|
9
21
|
type = opts[:type] && opts[:type].to_s || 'dumb'
|
10
22
|
case type
|
11
23
|
when 'dumb'
|
@@ -144,13 +144,25 @@ module Tarantool16
|
|
144
144
|
Option.error(sync, e, nil)
|
145
145
|
end
|
146
146
|
|
147
|
+
def _unix?
|
148
|
+
@host[0] == 'unix' || @host[0] == :unix
|
149
|
+
end
|
150
|
+
|
151
|
+
def _tcp?
|
152
|
+
@host[0] == 'tcp' || @host[0] == :tcp
|
153
|
+
end
|
154
|
+
|
155
|
+
def _unix_sock_path
|
156
|
+
@host[1]
|
157
|
+
end
|
158
|
+
|
147
159
|
def host_port
|
148
|
-
@host =~ /^(.*):([^:]+)$/
|
160
|
+
@host[1] =~ /^(.*):([^:]+)$/
|
149
161
|
[$1, $2.to_i]
|
150
162
|
end
|
151
163
|
|
152
164
|
def _ipv6?
|
153
|
-
@host.count(':') > 1
|
165
|
+
@host[1].count(':') > 1
|
154
166
|
end
|
155
167
|
|
156
168
|
def _insert(space_no, tuple, cb)
|
@@ -205,7 +217,13 @@ module Tarantool16
|
|
205
217
|
def _call(name, args, cb)
|
206
218
|
req = {IPROTO_FUNCTION_NAME => name,
|
207
219
|
IPROTO_TUPLE => args}
|
208
|
-
send_request(
|
220
|
+
send_request(REQUEST_TYPE_CALL17, req, cb)
|
221
|
+
end
|
222
|
+
|
223
|
+
def _call16(name, args, cb)
|
224
|
+
req = {IPROTO_FUNCTION_NAME => name,
|
225
|
+
IPROTO_TUPLE => args}
|
226
|
+
send_request(REQUEST_TYPE_CALL16, req, cb)
|
209
227
|
end
|
210
228
|
|
211
229
|
def _eval(expr, args, cb)
|
@@ -68,16 +68,23 @@ module Tarantool16
|
|
68
68
|
unless could_be_connected?
|
69
69
|
raise Disconnected, "connection is closed"
|
70
70
|
end
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
71
|
+
if _unix?
|
72
|
+
@socket = Socket.unix(_unix_sock_path)
|
73
|
+
elsif _tcp?
|
74
|
+
@socket = Socket.new((_ipv6? ? Socket::AF_INET6 : Socket::AF_INET), Socket::SOCK_STREAM)
|
75
|
+
@socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
|
76
|
+
@socket.sync = true
|
77
|
+
sockaddr = Socket.pack_sockaddr_in(*host_port.reverse)
|
78
|
+
@retry = @reconnect
|
79
|
+
if @timeout
|
80
|
+
_connect_nonblock(sockaddr)
|
81
|
+
else
|
82
|
+
@socket.connect(sockaddr)
|
83
|
+
end
|
78
84
|
else
|
79
|
-
@
|
85
|
+
raise "unsupported host option: #{@host.inspect}"
|
80
86
|
end
|
87
|
+
|
81
88
|
greeting = _read(IPROTO_GREETING_SIZE)
|
82
89
|
unless greeting && greeting.bytesize == IPROTO_GREETING_SIZE
|
83
90
|
raise Disconnected, "mailformed greeting #{greeting.inspect}"
|
@@ -124,7 +131,13 @@ module Tarantool16
|
|
124
131
|
req = req[n..-1]
|
125
132
|
end
|
126
133
|
rescue IO::WaitWritable
|
127
|
-
|
134
|
+
nf = now_f
|
135
|
+
if expire <= nf
|
136
|
+
raise Timeout, "response timeouted"
|
137
|
+
else
|
138
|
+
_wait_writable(expire - nf)
|
139
|
+
retry
|
140
|
+
end
|
128
141
|
rescue Errno::EINTR
|
129
142
|
retry
|
130
143
|
end
|
@@ -192,7 +205,16 @@ module Tarantool16
|
|
192
205
|
end
|
193
206
|
end
|
194
207
|
|
195
|
-
if
|
208
|
+
if (RUBY_VERSION.split('.').map(&:to_i) <=> [2,1]) >= 0
|
209
|
+
EXCEPTION_FALSE = {exception: false}.freeze
|
210
|
+
def _read_nonblock(n, buf)
|
211
|
+
if buf
|
212
|
+
@socket.read_nonblock(n, buf, EXCEPTION_FALSE)
|
213
|
+
else
|
214
|
+
@socket.read_nonblock(n, EXCEPTION_FALSE)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
elsif defined?(Kgio)
|
196
218
|
def _read_nonblock(n, buf)
|
197
219
|
return buf ? Kgio.tryread(@socket, n, buf) : Kgio.tryread(@socket, n)
|
198
220
|
end
|
data/lib/tarantool16/consts.rb
CHANGED
@@ -24,16 +24,19 @@ module Tarantool16
|
|
24
24
|
REQUEST_TYPE_REPLACE = 3
|
25
25
|
REQUEST_TYPE_UPDATE = 4
|
26
26
|
REQUEST_TYPE_DELETE = 5
|
27
|
-
|
27
|
+
REQUEST_TYPE_CALL16 = 6
|
28
28
|
REQUEST_TYPE_AUTHENTICATE = 7
|
29
29
|
REQUEST_TYPE_EVAL = 8
|
30
30
|
REQUEST_TYPE_UPSERT = 9
|
31
|
+
REQUEST_TYPE_CALL17 = 10
|
31
32
|
REQUEST_TYPE_ERROR = 1 << 15
|
32
33
|
|
33
34
|
|
34
35
|
SPACE_SCHEMA = 272
|
35
36
|
SPACE_SPACE = 280
|
37
|
+
SPACE_VSPACE = 281
|
36
38
|
SPACE_INDEX = 288
|
39
|
+
SPACE_VINDEX = 289
|
37
40
|
SPACE_FUNC = 296
|
38
41
|
SPACE_USER = 304
|
39
42
|
SPACE_PRIV = 312
|
data/lib/tarantool16/db.rb
CHANGED
@@ -9,7 +9,6 @@ module Tarantool16
|
|
9
9
|
@future = nil
|
10
10
|
@spaces = nil
|
11
11
|
@defined_fields = {}
|
12
|
-
_fill_standard_spaces
|
13
12
|
@conn = self.class::Connection.new(@host, @opts)
|
14
13
|
end
|
15
14
|
|
@@ -28,14 +27,6 @@ module Tarantool16
|
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
31
|
-
def _fill_standard_spaces
|
32
|
-
rf = @defined_fields
|
33
|
-
rf[SPACE_INDEX] =
|
34
|
-
[%w{sid num}, %w{iid num}, %w{name str},
|
35
|
-
%w{type str}, %w{unique num}, %w{part_count num},
|
36
|
-
{name: 'parts', type: [:num, :str], tail: true}]
|
37
|
-
end
|
38
|
-
|
39
30
|
def _synchronized
|
40
31
|
raise "Override #_synchronized"
|
41
32
|
end
|
@@ -78,7 +69,7 @@ module Tarantool16
|
|
78
69
|
_synchronized do
|
79
70
|
_fill_spaces(r.data)
|
80
71
|
spaces = @spaces
|
81
|
-
_select(
|
72
|
+
_select(SPACE_VINDEX, 0, [], 0, 2**30, :all, false, fill_indexes)
|
82
73
|
end
|
83
74
|
end
|
84
75
|
end
|
@@ -96,7 +87,7 @@ module Tarantool16
|
|
96
87
|
end
|
97
88
|
end
|
98
89
|
end
|
99
|
-
_select(
|
90
|
+
_select(SPACE_VSPACE, 0, [], 0, 2**30, :all, false, fill_spaces)
|
100
91
|
return future
|
101
92
|
end
|
102
93
|
end
|
@@ -187,7 +178,7 @@ module Tarantool16
|
|
187
178
|
|
188
179
|
def _update(sno, ino, key, ops, need_hash, cb)
|
189
180
|
ino = 0 if ino.nil? && key.is_a?(Array)
|
190
|
-
ops_good = ops.is_a?(Array) && ops.all?{|a|
|
181
|
+
ops_good = ops.is_a?(Array) && ops.all?{|a| a[1].is_a?(Integer)}
|
191
182
|
if sno.is_a?(Integer) && ino.is_a?(Integer) && key.is_a?(Array) && ops_good
|
192
183
|
return conn._update(sno, ino, key, ops, cb)
|
193
184
|
end
|
@@ -202,7 +193,7 @@ module Tarantool16
|
|
202
193
|
|
203
194
|
def _upsert(sno, ino, tuple_key, ops, need_hash, cb)
|
204
195
|
ino = 0 if ino.nil?
|
205
|
-
ops_good = ops.is_a?(Array) && ops.all?{|a|
|
196
|
+
ops_good = ops.is_a?(Array) && ops.all?{|a| a[1].is_a?(Integer)}
|
206
197
|
if sno.is_a?(Integer) && ino.is_a?(Integer) && tuple_key.is_a?(Array) && ops_good
|
207
198
|
return conn._upsert(sno, ino, tuple_key, ops, cb)
|
208
199
|
end
|
@@ -220,6 +211,10 @@ module Tarantool16
|
|
220
211
|
conn._call(name, args, cb)
|
221
212
|
end
|
222
213
|
|
214
|
+
def _call16(name, args, cb)
|
215
|
+
conn._call16(name, args, cb)
|
216
|
+
end
|
217
|
+
|
223
218
|
def _eval(expr, args, cb)
|
224
219
|
conn._eval(expr, args, cb)
|
225
220
|
end
|
data/lib/tarantool16/dumb_db.rb
CHANGED
@@ -69,6 +69,10 @@ module Tarantool16
|
|
69
69
|
_call(name, args, RETURN_OR_RAISE)
|
70
70
|
end
|
71
71
|
|
72
|
+
def call16(name, args)
|
73
|
+
_call16(name, args, RETURN_OR_RAISE)
|
74
|
+
end
|
75
|
+
|
72
76
|
def eval(expr, args)
|
73
77
|
_eval(expr, args, RETURN_OR_RAISE)
|
74
78
|
end
|
@@ -92,34 +96,23 @@ module Tarantool16
|
|
92
96
|
UNDEF = Object.new.freeze
|
93
97
|
def initialize
|
94
98
|
@r = UNDEF
|
95
|
-
@cb = nil
|
96
99
|
end
|
97
100
|
def then(cb)
|
98
101
|
unless @r.equal? UNDEF
|
99
102
|
return cb.call(@r)
|
100
103
|
end
|
101
|
-
|
102
|
-
raise "Blocking future accepts only 1 callback"
|
103
|
-
end
|
104
|
-
@cb = cb
|
104
|
+
raise "DumbDB::ShemaFuture future is not real future :-("
|
105
105
|
end
|
106
106
|
|
107
107
|
def then_blk
|
108
108
|
unless @r.equal? UNDEF
|
109
109
|
return yield @r
|
110
110
|
end
|
111
|
-
|
112
|
-
raise "Blocking future accepts only 1 callback"
|
113
|
-
end
|
114
|
-
@cb = lambda{|r| yield r}
|
111
|
+
raise "DumbDB::ShemaFuture future is not real future :-("
|
115
112
|
end
|
116
113
|
|
117
114
|
def set(r)
|
118
115
|
@r = r
|
119
|
-
if cb = @cb
|
120
|
-
@cb = nil
|
121
|
-
cb.call(r)
|
122
|
-
end
|
123
116
|
end
|
124
117
|
end
|
125
118
|
|
data/lib/tarantool16/errors.rb
CHANGED
@@ -24,7 +24,7 @@ module Tarantool16
|
|
24
24
|
4=> :ER_TUPLE_NOT_FOUND,
|
25
25
|
5=> :ER_UNSUPPORTED,
|
26
26
|
6=> :ER_NONMASTER,
|
27
|
-
7=> :
|
27
|
+
7=> :ER_READONLY,
|
28
28
|
8=> :ER_INJECTION,
|
29
29
|
9=> :ER_CREATE_SPACE,
|
30
30
|
10=> :ER_SPACE_EXISTS,
|
@@ -35,7 +35,7 @@ module Tarantool16
|
|
35
35
|
15=> :ER_LAST_DROP,
|
36
36
|
16=> :ER_TUPLE_FORMAT_LIMIT,
|
37
37
|
17=> :ER_DROP_PRIMARY_KEY,
|
38
|
-
18=> :
|
38
|
+
18=> :ER_KEY_PART_TYPE,
|
39
39
|
19=> :ER_EXACT_MATCH,
|
40
40
|
20=> :ER_INVALID_MSGPACK,
|
41
41
|
21=> :ER_PROC_RET,
|
@@ -55,10 +55,82 @@ module Tarantool16
|
|
55
55
|
35=> :ER_NO_SUCH_INDEX,
|
56
56
|
36=> :ER_NO_SUCH_SPACE,
|
57
57
|
37=> :ER_NO_SUCH_FIELD,
|
58
|
-
38=> :
|
59
|
-
39=> :
|
58
|
+
38=> :ER_SPACE_FIELD_COUNT,
|
59
|
+
39=> :ER_INDEX_FIELD_COUNT,
|
60
60
|
40=> :ER_WAL_IO,
|
61
61
|
41=> :ER_MORE_THAN_ONE_TUPLE,
|
62
|
+
42=> :ER_ACCESS_DENIED,
|
63
|
+
43=> :ER_CREATE_USER,
|
64
|
+
44=> :ER_DROP_USER,
|
65
|
+
45=> :ER_NO_SUCH_USER,
|
66
|
+
46=> :ER_USER_EXISTS,
|
67
|
+
47=> :ER_PASSWORD_MISMATCH,
|
68
|
+
48=> :ER_UNKNOWN_REQUEST_TYPE,
|
69
|
+
49=> :ER_UNKNOWN_SCHEMA_OBJECT,
|
70
|
+
50=> :ER_CREATE_FUNCTION,
|
71
|
+
51=> :ER_NO_SUCH_FUNCTION,
|
72
|
+
52=> :ER_FUNCTION_EXISTS,
|
73
|
+
53=> :ER_FUNCTION_ACCESS_DENIED,
|
74
|
+
54=> :ER_FUNCTION_MAX,
|
75
|
+
55=> :ER_SPACE_ACCESS_DENIED,
|
76
|
+
56=> :ER_USER_MAX,
|
77
|
+
57=> :ER_NO_SUCH_ENGINE,
|
78
|
+
58=> :ER_RELOAD_CFG,
|
79
|
+
59=> :ER_CFG,
|
80
|
+
60=> :ER_SOPHIA,
|
81
|
+
61=> :ER_LOCAL_SERVER_IS_NOT_ACTIVE,
|
82
|
+
62=> :ER_UNKNOWN_SERVER,
|
83
|
+
63=> :ER_CLUSTER_ID_MISMATCH,
|
84
|
+
64=> :ER_INVALID_UUID,
|
85
|
+
65=> :ER_CLUSTER_ID_IS_RO,
|
86
|
+
66=> :ER_RESERVED66,
|
87
|
+
67=> :ER_SERVER_ID_IS_RESERVED,
|
88
|
+
68=> :ER_INVALID_ORDER,
|
89
|
+
69=> :ER_MISSING_REQUEST_FIELD,
|
90
|
+
70=> :ER_IDENTIFIER,
|
91
|
+
71=> :ER_DROP_FUNCTION,
|
92
|
+
72=> :ER_ITERATOR_TYPE,
|
93
|
+
73=> :ER_REPLICA_MAX,
|
94
|
+
74=> :ER_INVALID_XLOG,
|
95
|
+
75=> :ER_INVALID_XLOG_NAME,
|
96
|
+
76=> :ER_INVALID_XLOG_ORDER,
|
97
|
+
77=> :ER_NO_CONNECTION,
|
98
|
+
78=> :ER_TIMEOUT,
|
99
|
+
79=> :ER_ACTIVE_TRANSACTION,
|
100
|
+
80=> :ER_NO_ACTIVE_TRANSACTION,
|
101
|
+
81=> :ER_CROSS_ENGINE_TRANSACTION,
|
102
|
+
82=> :ER_NO_SUCH_ROLE,
|
103
|
+
83=> :ER_ROLE_EXISTS,
|
104
|
+
84=> :ER_CREATE_ROLE,
|
105
|
+
85=> :ER_INDEX_EXISTS,
|
106
|
+
86=> :ER_TUPLE_REF_OVERFLOW,
|
107
|
+
87=> :ER_ROLE_LOOP,
|
108
|
+
88=> :ER_GRANT,
|
109
|
+
89=> :ER_PRIV_GRANTED,
|
110
|
+
90=> :ER_ROLE_GRANTED,
|
111
|
+
91=> :ER_PRIV_NOT_GRANTED,
|
112
|
+
92=> :ER_ROLE_NOT_GRANTED,
|
113
|
+
93=> :ER_MISSING_SNAPSHOT,
|
114
|
+
94=> :ER_CANT_UPDATE_PRIMARY_KEY,
|
115
|
+
95=> :ER_UPDATE_INTEGER_OVERFLOW,
|
116
|
+
96=> :ER_GUEST_USER_PASSWORD,
|
117
|
+
97=> :ER_TRANSACTION_CONFLICT,
|
118
|
+
98=> :ER_UNSUPPORTED_ROLE_PRIV,
|
119
|
+
99=> :ER_LOAD_FUNCTION,
|
120
|
+
100=> :ER_FUNCTION_LANGUAGE,
|
121
|
+
101=> :ER_RTREE_RECT,
|
122
|
+
102=> :ER_PROC_C,
|
123
|
+
103=> :ER_UNKNOWN_RTREE_INDEX_DISTANCE_TYPE,
|
124
|
+
104=> :ER_PROTOCOL,
|
125
|
+
105=> :ER_UPSERT_UNIQUE_SECONDARY_KEY,
|
126
|
+
106=> :ER_WRONG_INDEX_RECORD,
|
127
|
+
107=> :ER_WRONG_INDEX_PARTS,
|
128
|
+
108=> :ER_WRONG_INDEX_OPTIONS,
|
129
|
+
109=> :ER_WRONG_SCHEMA_VERSION,
|
130
|
+
110=> :ER_SLAB_ALLOC_MAX,
|
131
|
+
111=> :ER_WRONG_SPACE_OPTIONS,
|
132
|
+
112=> :ER_UNSUPPORTED_INDEX_FEATURE,
|
133
|
+
113=> :ER_VIEW_IS_RO,
|
62
134
|
}.each do |n, s|
|
63
135
|
klass = Class.new(KnownDBError)
|
64
136
|
klass.return_code = n
|
data/lib/tarantool16/schema.rb
CHANGED
@@ -18,9 +18,10 @@ module Tarantool16
|
|
18
18
|
@field_names = {}
|
19
19
|
@fields = []
|
20
20
|
@has_tail = false
|
21
|
-
flds.each_with_index do |fld, i|
|
21
|
+
flds.each_with_index do |fld, i; name|
|
22
22
|
if @has_tail
|
23
|
-
|
23
|
+
$stderr.puts "no fields allowed after tail: #{flds}"
|
24
|
+
break
|
24
25
|
end
|
25
26
|
case fld
|
26
27
|
when String, Symbol
|
@@ -33,7 +34,12 @@ module Tarantool16
|
|
33
34
|
type = fld['type'] || fld[:type]
|
34
35
|
tail = fld['tail'] || fld[:tail]
|
35
36
|
end
|
37
|
+
unless name.is_a?(String) || name.is_a?(Symbol)
|
38
|
+
$stderr.puts "no field name found for field_#{i} in #{flds}"
|
39
|
+
name = "field_#{i}"
|
40
|
+
end
|
36
41
|
name_s = name.to_sym
|
42
|
+
name = name.to_s
|
37
43
|
field = Field.new(name_s, i, type)
|
38
44
|
@field_names[name] = field
|
39
45
|
@field_names[name_s] = field
|
@@ -41,6 +47,7 @@ module Tarantool16
|
|
41
47
|
@fields << field
|
42
48
|
@has_tail = true if tail
|
43
49
|
end
|
50
|
+
# refresh indices ?
|
44
51
|
if @index_defs
|
45
52
|
self.indices= @index_defs
|
46
53
|
end
|
@@ -182,12 +189,12 @@ module Tarantool16
|
|
182
189
|
|
183
190
|
def map_ops(ops)
|
184
191
|
ops.map do |op|
|
185
|
-
case
|
192
|
+
case op1 = op[1]
|
186
193
|
when Integer
|
187
194
|
op
|
188
195
|
when Symbol, String
|
189
196
|
_op = op.dup
|
190
|
-
_op[1] = @field_names[
|
197
|
+
_op[1] = @field_names[op1].pos
|
191
198
|
_op
|
192
199
|
when Array
|
193
200
|
fld_pos = case op[0]
|
@@ -198,7 +205,7 @@ module Tarantool16
|
|
198
205
|
else
|
199
206
|
raise "No field #{op[0].inspect} in #{name_sid}"
|
200
207
|
end
|
201
|
-
|
208
|
+
op1.dup.insert(1, fld_pos)
|
202
209
|
end
|
203
210
|
end
|
204
211
|
end
|
data/lib/tarantool16/version.rb
CHANGED
data/tarantool16.gemspec
CHANGED
data/test/config.lua
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
local log = require 'log'
|
2
2
|
box.cfg{
|
3
3
|
listen = 33013,
|
4
|
-
|
5
|
-
|
4
|
+
memtx_dir='.',
|
5
|
+
wal_mode='none',
|
6
6
|
}
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
7
|
+
box.once('initbox', function()
|
8
|
+
local s1 = box.schema.space.create('test', {id = 513, if_not_exists = true})
|
9
|
+
local ip = s1:create_index('primary', {type = 'hash', parts = {1, 'unsigned'}, if_not_exists = true})
|
10
|
+
local iname = s1:create_index('name', {type = 'tree', parts = {2, 'STR'}, if_not_exists = true})
|
11
|
+
local irtree = s1:create_index('point', {type = 'rtree', unique=false, parts = {3, 'ARRAY'}, if_not_exists = true})
|
12
|
+
local ipname = s1:create_index('id_name', {type = 'tree', parts = {1, 'unsigned', 2, 'STR'}})
|
13
|
+
local s2 = box.schema.space.create('test1', {id = 514, if_not_exists = true})
|
14
|
+
local ip = s2:create_index('primary', {type = 'hash', parts = {1, 'unsigned'}, if_not_exists = true})
|
15
|
+
|
16
|
+
box.schema.user.create('tester', {password='testpass'})
|
17
|
+
box.schema.user.grant('tester', 'read,write,execute', 'universe')
|
18
|
+
box.schema.func.create('reseed')
|
19
|
+
box.schema.func.create('func1')
|
20
|
+
end)
|
18
21
|
|
19
22
|
function reseed()
|
20
23
|
local s1 = box.space.test
|
@@ -27,15 +30,11 @@ function reseed()
|
|
27
30
|
s2:insert{2, "world", {3, 4}, 200}
|
28
31
|
end
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
end)
|
33
|
-
|
34
|
-
if not box.schema.user.exists('tester') then
|
35
|
-
box.schema.user.create('tester', {password='testpass'})
|
36
|
-
box.schema.user.grant('tester', 'read,write,execute', 'universe')
|
33
|
+
function func1(i)
|
34
|
+
return i+1
|
37
35
|
end
|
38
36
|
|
37
|
+
box.schema.user.grant('guest', 'read,write,execute', 'universe')
|
39
38
|
local console = require 'console'
|
40
39
|
console.listen '0.0.0.0:33015'
|
41
40
|
|
data/test/helper.rb
CHANGED
data/test/test_dumb.rb
CHANGED
@@ -71,6 +71,11 @@ describe 'DumbConnection' do
|
|
71
71
|
db.delete(:test, "world", index: 1).must_equal [r2]
|
72
72
|
end
|
73
73
|
|
74
|
+
it "should call" do
|
75
|
+
db.call("func1", [1]).must_equal [2]
|
76
|
+
db.call16("func1", [1]).must_equal [[2]]
|
77
|
+
end
|
78
|
+
|
74
79
|
it "should eval" do
|
75
80
|
db.eval("local a, b = ... ; return a + b", [1, 2]).must_equal [3]
|
76
81
|
end
|
@@ -118,7 +123,7 @@ describe 'DumbConnection' do
|
|
118
123
|
Spawn.with_pause do
|
119
124
|
proc {
|
120
125
|
db.get(:test, 1)
|
121
|
-
}.must_raise Tarantool16::Connection::CouldNotConnect
|
126
|
+
}.must_raise ::Tarantool16::Connection::CouldNotConnect
|
122
127
|
end
|
123
128
|
end
|
124
129
|
|
@@ -127,7 +132,7 @@ describe 'DumbConnection' do
|
|
127
132
|
Spawn.with_pause do
|
128
133
|
proc {
|
129
134
|
db.get(:test, 1)
|
130
|
-
}.must_raise Tarantool16::Connection::Timeout
|
135
|
+
}.must_raise ::Tarantool16::Connection::Timeout
|
131
136
|
end
|
132
137
|
end
|
133
138
|
end
|
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.
|
4
|
+
version: 0.1.2
|
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:
|
11
|
+
date: 2021-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.0.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: msgpack
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,8 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
114
|
- !ruby/object:Gem::Version
|
101
115
|
version: '0'
|
102
116
|
requirements: []
|
103
|
-
|
104
|
-
rubygems_version: 2.4.3
|
117
|
+
rubygems_version: 3.1.2
|
105
118
|
signing_key:
|
106
119
|
specification_version: 4
|
107
120
|
summary: adapter for Tarantool 1.6
|