Skip to content

Add tuple_object.format() reference #4714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
---
- []
...
Loading