Skip to content

Commit 9e6c33b

Browse files
committed
Fixes gh-317 Document field names changes
1 parent 999d4fe commit 9e6c33b

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

doc/1.7/book/box/box_space.rst

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,27 @@ A list of all ``box.space`` functions follows, then comes a list of all
384384
indexes must be created before tuples are inserted.
385385

386386

387+
**Using field names instead of field numbers:** `create_index()` can use field names and/or field types
388+
described by the optional :ref:`space_object:format() <box_space-format>` clause.
389+
In the following example, we show `format()` for a space that has two columns
390+
named 'x' and 'y', and then we show five variations of the `parts={}` clause of `create_index()`,
391+
first for the 'x' column, second for both the 'x' and 'y' columns.
392+
The variations include omitting the type, using numbers, and adding extra braces.
393+
394+
.. code-block:: none
395+
396+
box.space.T:format({{name='x', type='scalar'}, {name='y', type='integer'}})
397+
box.space.T:create_index('I2',{parts={{'x','scalar'}}})
398+
box.space.T:create_index('I3',{parts={{'x','scalar'},{'y','integer'}}})
399+
box.space.T:create_index('I4',{parts={1,'scalar'}})
400+
box.space.T:create_index('I5',{parts={1,'scalar',2,'integer'}})
401+
box.space.T:create_index('I6',{parts={1}})
402+
box.space.T:create_index('I7',{parts={1,2}})
403+
box.space.T:create_index('I8',{parts={'x'}})
404+
box.space.T:create_index('I9',{parts={'x','y'}})
405+
box.space.T:create_index('I10',{parts={{'x'}}})
406+
box.space.T:create_index('I11',{parts={{'x'},{'y'}}})
407+
387408
.. _box_space-delete:
388409

389410
.. method:: delete(key)
@@ -484,6 +505,28 @@ A list of all ``box.space`` functions follows, then comes a list of all
484505
485506
box.space.T:format({{name='surname',type='string'},{name='IDX',type='array'}})
486507
508+
There are legal variations of the format clause, omitting both 'name=' and 'type=',
509+
omitting 'type=' alone, and adding extra braces.
510+
The following examples show all the variations,
511+
first for one field named 'x', second for two fields named 'x' and 'y'.
512+
513+
.. code-block:: lua
514+
515+
box.space.T:format({{'x'}})
516+
box.space.T:format({{'x'},{'y'}})
517+
box.space.T:format({{name='x',type='scalar'}})
518+
box.space.T:format({{name='x',type='scalar'},{name='y',type='unsigned'}})
519+
box.space.T:format({{name='x'}})
520+
box.space.T:format({{name='x'},{name='y'}})
521+
box.space.T:format({{'x',type='scalar'}})
522+
box.space.T:format({{'x',type='scalar'},{'y',type='unsigned'}})
523+
box.space.T:format({{'x','scalar'}})
524+
box.space.T:format({{'x','scalar'},{'y','unsigned'}})
525+
526+
Names specified with the format clause can be used in
527+
:ref:`space_object:get() <box_space-get>` and in
528+
:ref:`space_object:create_index() <box_space-create_index>`.
529+
487530
.. _box_space-get:
488531

489532
.. method:: get(key)
@@ -515,6 +558,14 @@ A list of all ``box.space`` functions follows, then comes a list of all
515558
516559
box.space.tester:get{1}
517560
561+
**Using field names instead of field numbers:** `get()` can use field names
562+
described by the optional :ref:`space_object:format() <box_space-format>` clause.
563+
This is similar to a standard Lua feature, where a component can be referenced
564+
by its name instead of its number. So, if `tester` had been formatted with a
565+
field named 'x', and if the name `x` had been used in the index definition,
566+
and ``get`` or ``select`` had retrieved a single tuple,
567+
then the field in the tuple could be referenced with
568+
``box.space.tester:get{1}['x']`` or ``box.space.tester:select{1}[1]['x']``.
518569

519570
.. _box_space-insert:
520571

0 commit comments

Comments
 (0)