Skip to content

Commit 4b100cc

Browse files
committed
feature: add noreturn opt for some DML operations
This patch introduces `noreturn` opt for some DML operarions (`insert`, `replace`, `update`, `delete`, `insert_many`, `replace_many`) which suppress returning successfully processed tuple(s). Closes #267
1 parent 83b3d84 commit 4b100cc

File tree

7 files changed

+37
-1
lines changed

7 files changed

+37
-1
lines changed

crud/common/schema.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ function schema.wrap_func_result(space, func, args, opts)
216216
result.space_schema_hash = get_space_schema_hash(space)
217217
end
218218
else
219-
result.res = filter_tuple_fields(func_res, opts.field_names)
219+
if opts.noreturn ~= true then
220+
result.res = filter_tuple_fields(func_res, opts.field_names)
221+
end
220222
end
221223

222224
return result

crud/delete.lua

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ local function delete_on_storage(space_name, key, field_names, opts)
4444
return schema.wrap_box_space_func_result(space, 'delete', {key}, {
4545
add_space_schema_hash = false,
4646
field_names = field_names,
47+
noreturn = opts.noreturn,
4748
})
4849
end
4950

@@ -108,6 +109,7 @@ local function call_delete_on_router(vshard_router, space_name, key, opts)
108109
sharding_func_hash = bucket_id_data.sharding_func_hash,
109110
sharding_key_hash = sharding_key_hash,
110111
skip_sharding_hash_check = skip_sharding_hash_check,
112+
noreturn = opts.noreturn,
111113
}
112114

113115
local call_opts = {
@@ -172,6 +174,7 @@ function delete.call(space_name, key, opts)
172174
bucket_id = '?number|cdata',
173175
fields = '?table',
174176
vshard_router = '?string|table',
177+
noreturn = '?boolean',
175178
})
176179

177180
opts = opts or {}

crud/insert.lua

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ local function insert_on_storage(space_name, tuple, opts)
4545
return schema.wrap_box_space_func_result(space, 'insert', {tuple}, {
4646
add_space_schema_hash = opts.add_space_schema_hash,
4747
field_names = opts.fields,
48+
noreturn = opts.noreturn,
4849
})
4950
end
5051

@@ -85,6 +86,7 @@ local function call_insert_on_router(vshard_router, space_name, original_tuple,
8586
sharding_func_hash = sharding_data.sharding_func_hash,
8687
sharding_key_hash = sharding_data.sharding_key_hash,
8788
skip_sharding_hash_check = sharding_data.skip_sharding_hash_check,
89+
noreturn = opts.noreturn,
8890
}
8991

9092
local call_opts = {
@@ -156,6 +158,7 @@ function insert.tuple(space_name, tuple, opts)
156158
add_space_schema_hash = '?boolean',
157159
fields = '?table',
158160
vshard_router = '?string|table',
161+
noreturn = '?boolean',
159162
})
160163

161164
opts = opts or {}
@@ -194,6 +197,7 @@ function insert.object(space_name, obj, opts)
194197
fields = '?table',
195198
vshard_router = '?string|table',
196199
skip_nullability_check_on_flatten = '?boolean',
200+
noreturn = '?boolean',
197201
})
198202

199203
opts = opts or {}

crud/insert_many.lua

+10
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ local function insert_many_on_storage(space_name, tuples, opts)
5656
local insert_result = schema.wrap_box_space_func_result(space, 'insert', {tuple}, {
5757
add_space_schema_hash = opts.add_space_schema_hash,
5858
field_names = opts.fields,
59+
noreturn = opts.noreturn,
5960
})
6061

6162
if insert_result.err ~= nil then
@@ -148,6 +149,7 @@ local function call_insert_many_on_router(vshard_router, space_name, original_tu
148149
fields = opts.fields,
149150
stop_on_error = opts.stop_on_error,
150151
rollback_on_error = opts.rollback_on_error,
152+
noreturn = opts.noreturn,
151153
}
152154

153155
local iter, err = BatchInsertIterator:new({
@@ -181,6 +183,9 @@ local function call_insert_many_on_router(vshard_router, space_name, original_tu
181183
end
182184

183185
if next(rows) == nil then
186+
if errs == nil then
187+
return true
188+
end
184189
return nil, errs
185190
end
186191

@@ -219,6 +224,7 @@ function insert_many.tuples(space_name, tuples, opts)
219224
stop_on_error = '?boolean',
220225
rollback_on_error = '?boolean',
221226
vshard_router = '?string|table',
227+
noreturn = '?boolean',
222228
})
223229

224230
opts = opts or {}
@@ -257,6 +263,7 @@ function insert_many.objects(space_name, objs, opts)
257263
rollback_on_error = '?boolean',
258264
vshard_router = '?string|table',
259265
skip_nullability_check_on_flatten = '?boolean',
266+
noreturn = '?boolean',
260267
})
261268

262269
opts = opts or {}
@@ -291,6 +298,9 @@ function insert_many.objects(space_name, objs, opts)
291298
end
292299

293300
if next(tuples) == nil then
301+
if next(format_errs) == nil then
302+
return true, {}
303+
end
294304
return nil, format_errs
295305
end
296306

crud/replace.lua

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ local function replace_on_storage(space_name, tuple, opts)
4545
return schema.wrap_box_space_func_result(space, 'replace', {tuple}, {
4646
add_space_schema_hash = opts.add_space_schema_hash,
4747
field_names = opts.fields,
48+
noreturn = opts.noreturn,
4849
})
4950
end
5051

@@ -85,6 +86,7 @@ local function call_replace_on_router(vshard_router, space_name, original_tuple,
8586
sharding_func_hash = sharding_data.sharding_func_hash,
8687
sharding_key_hash = sharding_data.sharding_key_hash,
8788
skip_sharding_hash_check = sharding_data.skip_sharding_hash_check,
89+
noreturn = opts.noreturn,
8890
}
8991

9092
local call_opts = {
@@ -155,6 +157,7 @@ function replace.tuple(space_name, tuple, opts)
155157
add_space_schema_hash = '?boolean',
156158
fields = '?table',
157159
vshard_router = '?string|table',
160+
noreturn = '?boolean',
158161
})
159162

160163
opts = opts or {}
@@ -193,6 +196,7 @@ function replace.object(space_name, obj, opts)
193196
fields = '?table',
194197
vshard_router = '?string|table',
195198
skip_nullability_check_on_flatten = '?boolean',
199+
noreturn = '?boolean',
196200
})
197201

198202
opts = opts or {}

crud/replace_many.lua

+10
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ local function replace_many_on_storage(space_name, tuples, opts)
5656
local insert_result = schema.wrap_box_space_func_result(space, 'replace', {tuple}, {
5757
add_space_schema_hash = opts.add_space_schema_hash,
5858
field_names = opts.fields,
59+
noreturn = opts.noreturn,
5960
})
6061

6162
table.insert(errs, err)
@@ -150,6 +151,7 @@ local function call_replace_many_on_router(vshard_router, space_name, original_t
150151
fields = opts.fields,
151152
stop_on_error = opts.stop_on_error,
152153
rollback_on_error = opts.rollback_on_error,
154+
noreturn = opts.noreturn,
153155
}
154156

155157
local iter, err = BatchInsertIterator:new({
@@ -183,6 +185,9 @@ local function call_replace_many_on_router(vshard_router, space_name, original_t
183185
end
184186

185187
if next(rows) == nil then
188+
if errs == nil then
189+
return true
190+
end
186191
return nil, errs
187192
end
188193

@@ -221,6 +226,7 @@ function replace_many.tuples(space_name, tuples, opts)
221226
stop_on_error = '?boolean',
222227
rollback_on_error = '?boolean',
223228
vshard_router = '?string|table',
229+
noreturn = '?boolean',
224230
})
225231

226232
opts = opts or {}
@@ -259,6 +265,7 @@ function replace_many.objects(space_name, objs, opts)
259265
rollback_on_error = '?boolean',
260266
vshard_router = '?string|table',
261267
skip_nullability_check_on_flatten = '?boolean',
268+
noreturn = '?boolean',
262269
})
263270

264271
opts = opts or {}
@@ -293,6 +300,9 @@ function replace_many.objects(space_name, objs, opts)
293300
end
294301

295302
if next(tuples) == nil then
303+
if next(format_errs) == nil then
304+
return true, {}
305+
end
296306
return nil, format_errs
297307
end
298308

crud/update.lua

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ local function update_on_storage(space_name, key, operations, field_names, opts)
4444
local res, err = schema.wrap_box_space_func_result(space, 'update', {key, operations}, {
4545
add_space_schema_hash = false,
4646
field_names = field_names,
47+
noreturn = opts.noreturn,
4748
})
4849

4950
if err ~= nil then
@@ -140,6 +141,7 @@ local function call_update_on_router(vshard_router, space_name, key, user_operat
140141
sharding_func_hash = bucket_id_data.sharding_func_hash,
141142
sharding_key_hash = sharding_key_hash,
142143
skip_sharding_hash_check = skip_sharding_hash_check,
144+
noreturn = opts.noreturn,
143145
}
144146

145147
local call_opts = {
@@ -208,6 +210,7 @@ function update.call(space_name, key, user_operations, opts)
208210
bucket_id = '?number|cdata',
209211
fields = '?table',
210212
vshard_router = '?string|table',
213+
noreturn = '?boolean',
211214
})
212215

213216
opts = opts or {}

0 commit comments

Comments
 (0)