diff --git a/doc/sphinx/book/box/box_schema.rst b/doc/sphinx/book/box/box_schema.rst index 8af37388ab80ec29f6a8c542c27679edaa90c854..fce9b6eafd9f76b89d5e023f38223b0e4c8b4118 100644 --- a/doc/sphinx/book/box/box_schema.rst +++ b/doc/sphinx/book/box/box_schema.rst @@ -6,6 +6,8 @@ The ``box.schema`` package has one data-definition function: ``space.create()``. +.. _box.schema.space.create: + .. function:: space.create(space-name [, {options} ]) Create a space. @@ -36,6 +38,8 @@ The ``box.schema`` package has one data-definition function: ``space.create()``. +---------------+--------------------+---------+---------------------+ | user | user name | string | current user's name | +---------------+--------------------+---------+---------------------+ + | format | field names+types | table | (blank) | + +---------------+--------------------+---------+---------------------+ ================================================= Example @@ -52,6 +56,8 @@ The ``box.schema`` package has one data-definition function: ``space.create()``. | :codenormal:`---` | :codenormal:`...` +For an illustration with the :code:`format` clause, see :ref:`box.space._space example <boxspaceexample>`. + After a space is created, usually the next step is to :func:`create an index <space_object.create_index>` for it, and then it is available for insert, select, and all the other :mod:`box.space` diff --git a/doc/sphinx/book/box/box_space.rst b/doc/sphinx/book/box/box_space.rst index e64343628a84977c25bc4cfb28537dd6d9c420c4..66d9240cea853cab436791eafdfa18bc5f10f53c 100644 --- a/doc/sphinx/book/box/box_space.rst +++ b/doc/sphinx/book/box/box_space.rst @@ -645,26 +645,27 @@ A list of all ``box.space`` functions follows, then comes a list of all .. data:: _space ``_space`` is a system tuple set. Its tuples contain these fields: - ``id, uid, space-name, engine, field_count, temporary``. + ``id, uid, space-name, engine, field_count, temporary, format``. + These fields are established by :ref:`box.schema.space.create <box.schema.space.create>`. EXAMPLE. The following function will display all simple fields in all tuples of ``_space``. | :codenormal:`console = require('console'); console.delimiter('!')` | :codenormal:`function example()` - | :codenormal:`local ta = {}, i, line` - | :codenormal:`for k, v in box.space._space:pairs() do` - | :codenormal:`i = 1` - | :codenormal:`line = ''` - | :codenormal:`while i <= #v do` - | :codenormal:`if type(v[i]) ~= 'table' then` - | :codenormal:`line = line .. v[i] .. ' '` - | :codenormal:`end` - | :codenormal:`i = i + 1` - | :codenormal:`end` - | :codenormal:`table.insert(ta, line)` - | :codenormal:`end` - | :codenormal:`return ta` + | |nbsp| |nbsp| :codenormal:`local ta = {}, i, line` + | |nbsp| |nbsp| :codenormal:`for k, v in box.space._space:pairs() do` + | |nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`i = 1` + | |nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`line = ''` + | |nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`while i <= #v do` + | |nbsp| |nbsp| |nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`if type(v[i]) ~= 'table' then` + | |nbsp| |nbsp| |nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`line = line .. v[i] .. ' '` + | |nbsp| |nbsp| |nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`end` + | |nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`i = i + 1` + | |nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`end` + | |nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`table.insert(ta, line)` + | |nbsp| |nbsp| |nbsp| |nbsp|:codenormal:`end` + | |nbsp| |nbsp| :codenormal:`return ta` | :codenormal:`end!` | :codenormal:`console.delimiter('')!` @@ -684,6 +685,31 @@ A list of all ``box.space`` functions follows, then comes a list of all | :codenormal:`- '514 1 archive memtx 0 '` | :codenormal:`...` +.. _boxspaceexample: + + EXAMPLE. The following requests will create a space using + :code:`box.schema.space.create` with a :code:`format` clause. + Then it retrieves the _space tuple for the new space. + This illustrates the typical use of the :code:`format` clause, + it shows the recommended names and data types for the fields. + + | :codenormal:`tarantool>` :codebold:`box.schema.space.create('TM',{format={[1]={["name"]="field#1"},[2]={["type"]="num"}}})` + | :codenormal:`---` + | :codenormal:`- index: []` + | |nbsp| |nbsp| :codenormal:`on_replace: 'function: 0x41c67338'` + | |nbsp| |nbsp| :codenormal:`temporary: false` + | |nbsp| |nbsp| :codenormal:`id: 522` + | |nbsp| |nbsp| :codenormal:`engine: memtx` + | |nbsp| |nbsp| :codenormal:`enabled: false` + | |nbsp| |nbsp| :codenormal:`name: TM` + | |nbsp| |nbsp| :codenormal:`field_count: 0` + | :codenormal:`- created` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`box.space._space:select(522)` + | :codenormal:`---` + | :codenormal:`- - [522, 1, 'TM', 'memtx', 0, '', [{'name': 'field#1'}, {'type': 'num'}]]` + | :codenormal:`...` + .. data:: _index ``_index`` is a system tuple set. Its tuples contain these fields: diff --git a/doc/sphinx/reference/shard.rst b/doc/sphinx/reference/shard.rst index 25534b05216fed9125cd742a433da4a4a1e73d3a..24c5de02c3627f6922417d3ad6deb1b204894315 100644 --- a/doc/sphinx/reference/shard.rst +++ b/doc/sphinx/reference/shard.rst @@ -141,7 +141,7 @@ are on `the shard section of github`_. | :codenormal:`rm -r *.xlog` | :codenormal:`~/tarantool-master/src/tarantool` | :codenormal:`box.cfg{listen = 3301}` - | :codenormal:`box.schema.create_space('tester')` + | :codenormal:`box.schema.space.create('tester')` | :codenormal:`box.space.tester:create_index('primary', {})` | :codenormal:`box.schema.user.passwd('admin', 'password')` | :codenormal:`console = require('console')` @@ -209,7 +209,7 @@ and shard.tester, should look approximately like this: | :codenormal:`rm -r *.xlog` | :codenormal:`~/tarantool-master/src/tarantool` | :codenormal:`box.cfg{listen = 3301}` - | :codenormal:`box.schema.create_space('tester')` + | :codenormal:`box.schema.space.create('tester')` | :codenormal:`box.space.tester:create_index('primary', {})` | :codenormal:`box.schema.user.passwd('admin', 'password')` | :codenormal:`console = require('console')` @@ -236,7 +236,7 @@ and shard.tester, should look approximately like this: | :codenormal:`rm -r *.xlog` | :codenormal:`~/tarantool-master/src/tarantool` | :codenormal:`box.cfg{listen = 3302}` - | :codenormal:`box.schema.create_space('tester')` + | :codenormal:`box.schema.space.create('tester')` | :codenormal:`box.space.tester:create_index('primary', {})` | :codenormal:`box.schema.user.passwd('admin', 'password')` | :codenormal:`console = require('console')`