Skip to content

Commit 1488da3

Browse files
committed
Getting started: net.box - update per review
1 parent 16bd4cc commit 1488da3

File tree

3 files changed

+63
-59
lines changed

3 files changed

+63
-59
lines changed

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

+23-8
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 }
@@ -12,41 +27,41 @@ function net_box_session()
1227
...
1328
]]
1429

15-
conn.space.bands:select(1)
30+
conn.space.bands:select({ 1 })
1631
--[[
1732
---
1833
- - [1, 'Roxette', 1986]
1934
...
2035
]]
2136

22-
conn.space.bands.index.band:select('The Beatles')
37+
conn.space.bands.index.band:select({ 'The Beatles' })
2338
--[[
2439
---
2540
- - [4, 'The Beatles', 1960]
2641
...
2742
]]
2843

29-
conn.space.bands:update({ 2 }, { { '=', 2, 'Pink Floyd' } })
44+
conn.space.bands:update({ 2 }, { { '=', 'band_name', 'Pink Floyd' } })
3045
--[[
3146
---
3247
- [2, 'Pink Floyd', 1965]
3348
...
3449
]]
3550

36-
conn.space.bands:upsert({ 5, 'The Rolling Stones', 1962 }, { { '=', 2, 'The Doors' } })
51+
conn.space.bands:upsert({ 5, 'The Rolling Stones', 1962 }, { { '=', 'band_name', 'The Doors' } })
3752
--[[
3853
---
3954
...
4055
]]
4156

42-
conn.space.bands:replace { 1, 'Queen', 1970 }
57+
conn.space.bands:replace({ 1, 'Queen', 1970 })
4358
--[[
4459
---
4560
- [1, 'Queen', 1970]
4661
...
4762
]]
4863

49-
conn.space.bands:delete(5)
64+
conn.space.bands:delete({ 5 })
5065
--[[
5166
---
5267
- [5, 'The Rolling Stones', 1962]

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ box.space.bands:format({
1111
-- Create indexes --
1212
box.space.bands:create_index('primary', { parts = { 'id' } })
1313
box.space.bands:create_index('band', { parts = { 'band_name' } })
14-
box.space.bands:create_index('year', { parts = { { 'year' } }, unique = false })
1514
box.space.bands:create_index('year_band', { parts = { { 'year' }, { 'band_name' } } })
1615

1716
-- Create a stored function --
1817
box.schema.func.create('get_bands_older_than', {
1918
body = [[
2019
function(year)
21-
return box.space.bands.index.year:select({ year }, { iterator = 'LT', limit = 10 })
20+
return box.space.bands.index.year_band:select({ year }, { iterator = 'LT', limit = 10 })
2221
end
2322
]]
2423
})

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)