Skip to content

Commit

Permalink
Add tuple_object.format() reference (#4714)
Browse files Browse the repository at this point in the history
Resolves #4301
  • Loading branch information
p7nov authored Dec 24, 2024
1 parent 75205a7 commit 959c606
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
4 changes: 4 additions & 0 deletions doc/reference/reference_lua/box_tuple.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ Below is a list of all ``box.tuple`` functions.
* - :doc:`./box_tuple/find`
- Get the number of the first field/all fields matching the search value

* - :doc:`./box_tuple/format`
- Get the format of a tuple

* - :doc:`./box_tuple/info`
- Get information about the tuple

Expand Down Expand Up @@ -85,6 +88,7 @@ Below is a list of all ``box.tuple`` functions.
box_tuple/field_name
box_tuple/field_path
box_tuple/find
box_tuple/format
box_tuple/info
box_tuple/next
box_tuple/pairs
Expand Down
2 changes: 1 addition & 1 deletion doc/reference/reference_lua/box_tuple/bsize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.. _box_tuple-bsize:

================================================================================
box.tuple.bsize()
tuple_object.bsize()
================================================================================

.. class:: tuple_object
Expand Down
61 changes: 61 additions & 0 deletions doc/reference/reference_lua/box_tuple/format.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
.. _box_tuple-format:

tuple_object:format()
=====================

.. class:: tuple_object

.. method:: format()

Get the format of a tuple. The resulting table lists the fields of a tuple
(their names and types) if the ``format`` option was specified during the tuple
creation. Otherwise, the return value is empty.

:return: the tuple format.
:rtype: table

.. note::

``tuple_object.format()`` is equivalent to ``box.tuple.format(tuple_object)``.

Example:

* A formatted tuple:

.. code-block:: tarantoolsession
tarantool> f = box.tuple.format.new({{'id', 'number'}, {'name', 'string'}})
---
...
tarantool> ftuple = box.tuple.new({1, 'Bob'}, {format = f})
---
...
tarantool> ftuple:format()
---
- [{'name': 'id', 'type': 'number'}, {'name': 'name', 'type': 'string'}]
...
tarantool> box.tuple.format(ftuple)
---
- [{'name': 'id', 'type': 'number'}, {'name': 'name', 'type': 'string'}]
...
* A tuple without a format:

.. code-block:: tarantoolsession
tarantool> tuple1 = box.tuple.new({1, 'Bob'}) -- no format
---
...
tarantool> tuple1:format()
---
- []
...
tarantool> box.tuple.format(tuple1)
---
- []
...

0 comments on commit 959c606

Please sign in to comment.