Skip to content

Commit 959c606

Browse files
authored
Add tuple_object.format() reference (#4714)
Resolves #4301
1 parent 75205a7 commit 959c606

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

doc/reference/reference_lua/box_tuple.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ Below is a list of all ``box.tuple`` functions.
4747
* - :doc:`./box_tuple/find`
4848
- Get the number of the first field/all fields matching the search value
4949

50+
* - :doc:`./box_tuple/format`
51+
- Get the format of a tuple
52+
5053
* - :doc:`./box_tuple/info`
5154
- Get information about the tuple
5255

@@ -85,6 +88,7 @@ Below is a list of all ``box.tuple`` functions.
8588
box_tuple/field_name
8689
box_tuple/field_path
8790
box_tuple/find
91+
box_tuple/format
8892
box_tuple/info
8993
box_tuple/next
9094
box_tuple/pairs

doc/reference/reference_lua/box_tuple/bsize.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.. _box_tuple-bsize:
33

44
================================================================================
5-
box.tuple.bsize()
5+
tuple_object.bsize()
66
================================================================================
77

88
.. class:: tuple_object
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
.. _box_tuple-format:
2+
3+
tuple_object:format()
4+
=====================
5+
6+
.. class:: tuple_object
7+
8+
.. method:: format()
9+
10+
Get the format of a tuple. The resulting table lists the fields of a tuple
11+
(their names and types) if the ``format`` option was specified during the tuple
12+
creation. Otherwise, the return value is empty.
13+
14+
:return: the tuple format.
15+
:rtype: table
16+
17+
.. note::
18+
19+
``tuple_object.format()`` is equivalent to ``box.tuple.format(tuple_object)``.
20+
21+
Example:
22+
23+
* A formatted tuple:
24+
25+
.. code-block:: tarantoolsession
26+
27+
tarantool> f = box.tuple.format.new({{'id', 'number'}, {'name', 'string'}})
28+
---
29+
...
30+
31+
tarantool> ftuple = box.tuple.new({1, 'Bob'}, {format = f})
32+
---
33+
...
34+
35+
tarantool> ftuple:format()
36+
---
37+
- [{'name': 'id', 'type': 'number'}, {'name': 'name', 'type': 'string'}]
38+
...
39+
40+
tarantool> box.tuple.format(ftuple)
41+
---
42+
- [{'name': 'id', 'type': 'number'}, {'name': 'name', 'type': 'string'}]
43+
...
44+
45+
* A tuple without a format:
46+
47+
.. code-block:: tarantoolsession
48+
49+
tarantool> tuple1 = box.tuple.new({1, 'Bob'}) -- no format
50+
---
51+
...
52+
53+
tarantool> tuple1:format()
54+
---
55+
- []
56+
...
57+
58+
tarantool> box.tuple.format(tuple1)
59+
---
60+
- []
61+
...

0 commit comments

Comments
 (0)