@@ -384,6 +384,27 @@ A list of all ``box.space`` functions follows, then comes a list of all
384
384
indexes must be created before tuples are inserted.
385
385
386
386
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
+
387
408
.. _box_space-delete :
388
409
389
410
.. method :: delete(key)
@@ -484,6 +505,28 @@ A list of all ``box.space`` functions follows, then comes a list of all
484
505
485
506
box.space.T:format({{name='surname',type='string'},{name='IDX',type='array'}})
486
507
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
+
487
530
.. _box_space-get :
488
531
489
532
.. method :: get(key)
@@ -515,6 +558,14 @@ A list of all ``box.space`` functions follows, then comes a list of all
515
558
516
559
box.space.tester:get{1}
517
560
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'] ``.
518
569
519
570
.. _box_space-insert :
520
571
0 commit comments