Submodule box.tuple
The box.tuple submodule provides read-only access for the tuple
userdata type. It allows, for a single tuple:
selective retrieval of the field contents, retrieval of information
about size, iteration over all the fields, and conversion to a Lua
table.
Below is a list of all box.tuple functions.
Name | Use |
|---|---|
Create a tuple | |
Check whether a given object is a tuple | |
Count tuple fields | |
Get count of bytes in a tuple | |
Get a tuple's field by specifying a number | |
Get a tuple's field by specifying a name | |
Get a tuple's fields or parts by specifying a path | |
Get the number of the first field/all fields matching the search value | |
Get the format of a tuple | |
Get information about the tuple | |
Get the next field value from tuple | |
Prepare for iterating | |
Get a tuple's fields as a table | |
Get a tuple's fields as a table along with key:value pairs | |
Remove (and replace) a tuple's fields | |
Get a tuple's fields | |
Update a tuple | |
Update a tuple ignoring errors |
This function will illustrate how to convert tuples to/from Lua tables and lists of scalars:
tuple = box.tuple.new({scalar1, scalar2, ... scalar_n}) -- scalars to tuplelua_table = {tuple:unpack()} -- tuple to Lua tablelua_table = tuple:totable() -- tuple to Lua tablescalar1, scalar2, ... scalar_n = tuple:unpack() -- tuple to scalarstuple = box.tuple.new(lua_table) -- Lua table to tuple
Then it will find the field that contains 'b', remove that field from
the tuple, and display how many bytes remain in the tuple. The function
uses Tarantool box.tuple functions new(), unpack(), find(),
transform(), bsize().
function example()local tuple1, tuple2, lua_table_1, scalar1, scalar2, scalar3, field_numberlocal luatable1 = {}tuple1 = box.tuple.new({'a', 'b', 'c'})luatable1 = tuple1:totable()scalar1, scalar2, scalar3 = tuple1:unpack()tuple2 = box.tuple.new(luatable1[1],luatable1[2],luatable1[3])field_number = tuple2:find('b')tuple2 = tuple2:transform(field_number, 1)return 'tuple2 = ' , tuple2 , ' # of bytes = ' , tuple2:bsize()end
... And here is what happens when one invokes the function:
tarantool> example()---- tuple2 =- ['a', 'c']- ' # of bytes = '- 5...