tuple_object:tomap()
tuple_object
A Lua table can have indexed values, also called key:value pairs. For example, here:
a = {}; a['field1'] = 10; a['field2'] = 20
a is a table with "field1: 10" and "field2: 20".
The /reference/reference_lua/box_tuple/totable function only returns a table containing the values. But the
tuple_object:tomap() function returns a table containing not only the
values, but also the key:value pairs.
This only works if the tuple comes from a space that has been formatted with a format clause.
Parameters:
options(table) — the only possible option isnames_only.
If names_only is false or omitted (default), then all the fields
will appear twice, first with numeric headings and second with name
headings.
If names_only is true, then all the fields will appear only once,
with name headings.
Returns
field-number:value pair(s) and key:value pair(s) from the tuple
Return type
lua-table
In the following example, a tuple named t1 is returned from a space
that has been formatted, then tables named t1map1 and t1map2 are
produced from t1.
format = {{'field1', 'unsigned'}, {'field2', 'unsigned'}}s = box.schema.space.create('test', {format = format})s:create_index('pk',{parts={1,'unsigned',2,'unsigned'}})t1 = s:insert{10, 20}t1map = t1:tomap()t1map_names_only = t1:tomap({names_only=true})
t1map will contain "1: 10", "2: 20", "field1: 10", "field2:
20".
t1map_names_only will contain "field1: 10", "field2: 20".