-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
box: feature
tuple:format
to get a format of a tuple
This patch adds `tuple:format()` method to get a format of a tuple. Closes #10005 @TarantoolBot document Title: New `format` method for `box.tuple` Product: Tarantool Since: 3.2 The `tuple:format` method returns a format of a tuple.
- Loading branch information
1 parent
3d97334
commit 6d5f1db
Showing
7 changed files
with
101 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## feature/box | ||
|
||
* Added the `tuple:format` method to get a format of a tuple (gh-10005). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
local utils = require('internal.utils') | ||
|
||
local internal = box.internal | ||
|
||
-- new() needs a wrapper in Lua, because format normalization needs to be done | ||
-- in Lua. | ||
box.tuple.format.new = function(format) | ||
utils.check_param(format, 'format', 'table') | ||
format = box.internal.space.normalize_format(nil, nil, format, 2) | ||
return box.internal.tuple_format.new(format) | ||
end | ||
|
||
setmetatable(box.tuple.format, { | ||
__call = function(_, t) | ||
return internal.tuple.tuple_get_format(t) | ||
end, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
local server = require('luatest.server') | ||
local t = require('luatest') | ||
|
||
local g = t.group() | ||
|
||
g.before_all(function(cg) | ||
cg.server = server:new() | ||
cg.server:start() | ||
end) | ||
|
||
g.after_all(function(cg) | ||
cg.server:drop() | ||
end) | ||
|
||
-- Checks that `tuple:format` works as expected. | ||
g.test_tuple_format = function() | ||
local f = box.tuple.format.new({{'id', 'number'}, {'name', 'string'}}) | ||
local tuple = box.tuple.new({1, 'Flint'}, {format = f}) | ||
t.assert_equals(type(tuple:format()), 'table') | ||
t.assert_equals(tuple:format(), f:totable()) | ||
|
||
tuple = box.tuple.new({1, 'Flint', true}, {format = f}) | ||
t.assert_equals(type(tuple:format()), 'table') | ||
t.assert_equals(tuple:format(), f:totable()) | ||
end | ||
|
||
-- Checks that `box.tuple.format` works as expected. | ||
g.test_box_tuple_format = function() | ||
local f = box.tuple.format.new({{'id', 'number'}, {'name', 'string'}}) | ||
local tuple = box.tuple.new({1, 'Flint'}, {format = f}) | ||
t.assert_equals(type(box.tuple.format(tuple)), 'table') | ||
t.assert_equals(box.tuple.format(tuple), f:totable()) | ||
t.assert_equals(box.tuple.format(tuple), tuple:format()) | ||
|
||
tuple = box.tuple.new({1, 'Flint', true}, {format = f}) | ||
t.assert_equals(type(box.tuple.format(tuple)), 'table') | ||
t.assert_equals(box.tuple.format(tuple), f:totable()) | ||
t.assert_equals(box.tuple.format(tuple), tuple:format()) | ||
end | ||
|
||
-- Checks that `tuple:format` and `box.tuple.format` work as expected | ||
-- without set format. | ||
g.test_tuple_format_with_no_format = function() | ||
local tuple = box.tuple.new({1, 'Flint'}) | ||
t.assert_equals(type(tuple:format()), 'table') | ||
t.assert_equals(tuple:format(), {}) | ||
|
||
t.assert_equals(type(box.tuple.format(tuple)), 'table') | ||
t.assert_equals(box.tuple.format(tuple), {}) | ||
end |