tuple_object:tomap()
-
object
tuple_object¶ -
tuple_object:tomap([options])¶ A Lua table can have indexed values, also called key:value pairs. For example, here:
a = {}; a['field1'] = 10; a['field2'] = 20
ais a table with “field1: 10” and “field2: 20”.The tuple_object: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 is
names_only.If
names_onlyis false or omitted (default), then all the fields will appear twice, first with numeric headings and second with name headings.If
names_onlyis true, then all the fields will appear only once, with name headings.
Return: field-number:value pair(s) and key:value pair(s) from the tuple
Rtype: lua-table
In the following example, a tuple named
t1is returned from a space that has been formatted, then tables namedt1map1andt1map2are produced fromt1.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})
t1mapwill contain “1: 10”, “2: 20”, “field1: 10”, “field2: 20”.t1map_names_onlywill contain “field1: 10”, “field2: 20”.- options (
-