Skip to content

Commit 6e334cc

Browse files
committed
Getting started: net.box - restructure
1 parent 16bd4cc commit 6e334cc

File tree

2 files changed

+56
-51
lines changed

2 files changed

+56
-51
lines changed

doc/code_snippets/snippets/connectors/instances.enabled/net_box/myapp.lua

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
function net_box_session()
2-
local net_box = require('net.box')
3-
local conn = net_box.connect('sampleuser:[email protected]:3301')
2+
net_box = require('net.box')
3+
--[[
4+
---
5+
...
6+
]]
7+
8+
conn = net_box.connect('sampleuser:[email protected]:3301')
9+
--[[
10+
---
11+
...
12+
]]
13+
414
conn:ping()
15+
--[[
16+
---
17+
- true
18+
...
19+
]]
520

621
conn.space.bands:insert { 1, 'Roxette', 1986 }
722
conn.space.bands:insert { 2, 'Scorpions', 1965 }

doc/how-to/getting_started_net_box.rst

+39-49
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ In this tutorial, the application layout is prepared manually:
4747

4848
#. Inside the ``instances.enabled`` directory of the created tt environment, create the ``net_box`` directory.
4949

50-
#. Inside ``instances.enabled/net_box``, create the ``instances.yml``, ``config.yaml``, and ``myapp.lua`` files:
50+
#. Inside ``instances.enabled/net_box``, create the ``instances.yml`` and ``config.yaml`` files:
5151

5252
* ``instances.yml`` specifies instances to run in the current environment. In this example, there is one instance:
5353

@@ -59,16 +59,45 @@ In this tutorial, the application layout is prepared manually:
5959

6060
.. literalinclude:: /code_snippets/snippets/connectors/instances.enabled/net_box/config.yaml
6161
:language: yaml
62+
:end-at: iproto
6263
:dedent:
6364

64-
* ``myapp.lua`` contains ``net.box`` requests used to interact with a :ref:`sample database <getting_started_net_box_sample_db>`. These requests are explained below in the :ref:`getting_started_net_box_developing_app` section.
6565

6666

67+
.. _getting_started_net_box_interactive:
6768

68-
.. _getting_started_net_box_developing_app:
69+
Making net.box requests interactively
70+
-------------------------------------
6971

70-
Developing the application
71-
--------------------------
72+
To try out ``net.box`` requests in the interactive console, you need to start sample applications:
73+
74+
1. Start the :ref:`sample_db <getting_started_net_box_sample_db>` application using ``tt start``:
75+
76+
.. code-block:: console
77+
78+
$ tt start sample_db
79+
80+
2. Start the :ref:`net_box <getting_started_net_box_creating-app>` application:
81+
82+
.. code-block:: console
83+
84+
$ tt start net_box
85+
86+
3. Connect to ``net_box:instance001`` using ``tt connect``:
87+
88+
.. code-block:: console
89+
90+
$ tt connect net_box:instance001
91+
• Connecting to the instance...
92+
• Connected to net_box:instance001
93+
94+
net_box:instance001>
95+
96+
In the instance's console, you can create a ``net.box`` connection and try out data operations.
97+
98+
99+
100+
.. _getting_started_net_box_creating_connection:
72101

73102
Creating a net.box connection
74103
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -78,23 +107,23 @@ To load the ``net.box`` module, use the ``require()`` directive:
78107
.. literalinclude:: /code_snippets/snippets/connectors/instances.enabled/net_box/myapp.lua
79108
:language: lua
80109
:start-at: net_box = require
81-
:end-at: net_box = require
110+
:end-before: net_box.connect
82111
:dedent:
83112

84113
To create a connection, pass a database URI to the ``connect()`` method:
85114

86115
.. literalinclude:: /code_snippets/snippets/connectors/instances.enabled/net_box/myapp.lua
87116
:language: lua
88117
:start-at: net_box.connect
89-
:end-at: net_box.connect
118+
:end-before: conn:ping
90119
:dedent:
91120

92121
``ping()`` can be used to check the connection status:
93122

94123
.. literalinclude:: /code_snippets/snippets/connectors/instances.enabled/net_box/myapp.lua
95124
:language: lua
96125
:start-at: conn:ping
97-
:end-at: conn:ping
126+
:end-before: Roxette
98127
:dedent:
99128

100129

@@ -225,45 +254,6 @@ The ``connection:close()`` method can be used to close the connection when it is
225254
:end-before: end
226255
:dedent:
227256

257+
.. NOTE::
228258

229-
230-
.. _getting_started_net_box_interactive:
231-
232-
Making net.box requests interactively
233-
-------------------------------------
234-
235-
To try out ``net.box`` requests in the interactive console, you need to start sample applications:
236-
237-
1. Start the :ref:`sample_db <getting_started_net_box_sample_db>` application using ``tt start``:
238-
239-
.. code-block:: console
240-
241-
$ tt start sample_db
242-
243-
2. Start the :ref:`net_box <getting_started_net_box_creating-app>` application:
244-
245-
.. code-block:: console
246-
247-
$ tt start net_box
248-
249-
3. Connect to ``net_box:instance001`` using ``tt connect``:
250-
251-
.. code-block:: console
252-
253-
$ tt connect net_box:instance001
254-
• Connecting to the instance...
255-
• Connected to net_box:instance001
256-
257-
net_box:instance001>
258-
259-
In the instance's console, you can create a ``net.box`` connection and try out data operations described in :ref:`getting_started_net_box_developing_app`:
260-
261-
.. code-block:: console
262-
263-
net_box:instance001> net_box = require('net.box')
264-
---
265-
...
266-
267-
net_box:instance001> conn = net_box.connect('sampleuser:[email protected]:3301')
268-
---
269-
...
259+
You can find the example with all the requests above on GitHub: `net_box <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/connectors/instances.enabled/net_box>`_.

0 commit comments

Comments
 (0)