From 959c60699508ffdd6f7af23833e1614c8b48b888 Mon Sep 17 00:00:00 2001 From: Pavel Semyonov Date: Tue, 24 Dec 2024 16:56:57 +0700 Subject: [PATCH] Add tuple_object.format() reference (#4714) Resolves #4301 --- doc/reference/reference_lua/box_tuple.rst | 4 ++ .../reference_lua/box_tuple/bsize.rst | 2 +- .../reference_lua/box_tuple/format.rst | 61 +++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 doc/reference/reference_lua/box_tuple/format.rst diff --git a/doc/reference/reference_lua/box_tuple.rst b/doc/reference/reference_lua/box_tuple.rst index eff5175786..b370b09a13 100644 --- a/doc/reference/reference_lua/box_tuple.rst +++ b/doc/reference/reference_lua/box_tuple.rst @@ -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 @@ -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 diff --git a/doc/reference/reference_lua/box_tuple/bsize.rst b/doc/reference/reference_lua/box_tuple/bsize.rst index a7805daa46..f2b7953c6c 100644 --- a/doc/reference/reference_lua/box_tuple/bsize.rst +++ b/doc/reference/reference_lua/box_tuple/bsize.rst @@ -2,7 +2,7 @@ .. _box_tuple-bsize: ================================================================================ -box.tuple.bsize() +tuple_object.bsize() ================================================================================ .. class:: tuple_object diff --git a/doc/reference/reference_lua/box_tuple/format.rst b/doc/reference/reference_lua/box_tuple/format.rst new file mode 100644 index 0000000000..6dbafe72eb --- /dev/null +++ b/doc/reference/reference_lua/box_tuple/format.rst @@ -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) + --- + - [] + ...