-
Notifications
You must be signed in to change notification settings - Fork 43
Update the example in module net.box #3186
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d0c052c
Update example
xuniq a65286e
Rewrite the example
xuniq a3d07c6
Move text to how-to section
xuniq 40f5e2e
Update the example
xuniq 7529c97
Apply suggestions from review
xuniq 03d6fe8
Translate page, update translation
xuniq 9b41bc7
Update translation
xuniq 53a5ff1
Update translation
xuniq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
.. _getting_started_net_box: | ||
|
||
Getting started with net.box | ||
============================ | ||
|
||
The tutorial shows how to work with some common ``net.box`` methods. | ||
|
||
For more information about the ``net.box`` module, | ||
check the :ref:`corresponding module reference <net_box-module>`. | ||
|
||
Sandbox configuration | ||
--------------------- | ||
|
||
The sandbox configuration for the tutorial assumes that: | ||
|
||
* The Tarantool instance is running on ``localhost 127.0.0.1:3301``. | ||
* There is a space named ``tester`` with a numeric primary key. | ||
* The space contains a tuple with the key value = ``800``. | ||
* The current user has read, write, and execute privileges. | ||
|
||
Use the commands below for a quick sandbox setup: | ||
|
||
.. code-block:: lua | ||
|
||
box.cfg{listen = 3301} | ||
s = box.schema.space.create('tester') | ||
s:create_index('primary', {type = 'hash', parts = {1, 'unsigned'}}) | ||
t = s:insert({800, 'TEST'}) | ||
box.schema.user.grant('guest', 'read,write,execute', 'universe') | ||
|
||
Creating a net.box connection | ||
----------------------------- | ||
|
||
First, load the ``net.box`` module with the ``require('net.box')`` method: | ||
|
||
.. code-block:: tarantoolsession | ||
|
||
tarantool> net_box = require('net.box') | ||
|
||
The next step is to create a new connection. | ||
In ``net.box``, self-connection is pre-established. | ||
That is, ``conn = net_box.connect('localhost:3301')`` command can be replaced with the ``conn = net_box.self`` object call: | ||
|
||
.. code-block:: tarantoolsession | ||
|
||
tarantool> conn = net_box.self | ||
|
||
Then, make a ping: | ||
|
||
.. code-block:: tarantoolsession | ||
|
||
tarantool> conn:ping() | ||
--- | ||
- true | ||
... | ||
|
||
Using data operations | ||
--------------------- | ||
|
||
Select all tuples in the ``tester`` space where the key value is ``800``: | ||
|
||
.. code-block:: tarantoolsession | ||
|
||
tarantool> conn.space.tester:select{800} | ||
--- | ||
- - [800, 'TEST'] | ||
... | ||
|
||
Insert two tuples into the space: | ||
|
||
.. code-block:: tarantoolsession | ||
|
||
tarantool> conn.space.tester:insert({700, 'TEST700'}) | ||
--- | ||
- [700, 'TEST700'] | ||
... | ||
tarantool> conn.space.tester:insert({600, 'TEST600'}) | ||
--- | ||
- [600, 'TEST600'] | ||
... | ||
|
||
After the insert, there is one tuple where the key value is ``600``. | ||
To select this tuple, you can use the ``get()`` method. | ||
Unlike the ``select()`` command, ``get()`` returns only one tuple that satisfies the stated condition. | ||
|
||
.. code-block:: tarantoolsession | ||
|
||
tarantool> conn.space.tester:get({600}) | ||
--- | ||
- [600, 'TEST600'] | ||
... | ||
|
||
To update the existing tuple, you can use either ``update()`` or ``upsert()``. | ||
The ``update()`` method can be used for assignment, arithmetic (if the field is numeric), | ||
cutting and pasting fragments of a field, and deleting or inserting a field. | ||
|
||
In this tutorial, the ``update()`` command is used to update the tuple identified by primary key value = ``800``. | ||
The operation assigns a new value to the second field in the tuple: | ||
|
||
.. code-block:: tarantoolsession | ||
|
||
tarantool> conn.space.tester:update(800, {{'=', 2, 'TEST800'}}) | ||
--- | ||
- [800, 'TEST800'] | ||
... | ||
|
||
As for the ``upsert`` function, if there is an existing tuple that matches the key field of tuple, then the command | ||
has the same effect as ``update()``. | ||
Otherwise, the effect is equal to the ``insert()`` method. | ||
|
||
.. code-block:: tarantoolsession | ||
|
||
tarantool> conn.space.tester:upsert({500, 'TEST500'}, {{'=', 2, 'TEST'}}) | ||
|
||
To delete a tuple where the key value is ``600``, run the ``delete()`` method below: | ||
|
||
.. code-block:: tarantoolsession | ||
|
||
tarantool> conn.space.tester:delete{600} | ||
--- | ||
- [600, 'TEST600'] | ||
... | ||
|
||
Then, replace the existing tuple with a new one: | ||
|
||
.. code-block:: tarantoolsession | ||
|
||
tarantool> conn.space.tester:replace{500, 'New data', 'Extra data'} | ||
--- | ||
- [500, 'New data', 'Extra data'] | ||
... | ||
|
||
Finally, select all tuples from the space: | ||
|
||
.. code-block:: tarantoolsession | ||
|
||
tarantool> conn.space.tester:select{} | ||
--- | ||
- - [800, 'TEST800'] | ||
- [500, 'New data', 'Extra data'] | ||
- [700, 'TEST700'] | ||
... | ||
|
||
Closing the connection | ||
---------------------- | ||
|
||
In the end, close the connection when it is no longer needed: | ||
xuniq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. code-block:: tarantoolsession | ||
|
||
tarantool> conn:close() | ||
--- | ||
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
locale/ru/LC_MESSAGES/how-to/getting_started_net_box.po
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
|
||
msgid "Getting started with net.box" | ||
msgstr "Начало работы с net.box" | ||
|
||
msgid "The tutorial shows how to work with some common ``net.box`` methods." | ||
msgstr "Ниже приводится пример использования большинства методов ``net.box``." | ||
|
||
msgid "" | ||
"For more information about the ``net.box`` module, " | ||
"check the :ref:`corresponding module reference <net_box-module>`." | ||
msgstr "" | ||
"Подробную информацию о модуле ``net.box`` вы найдете " | ||
"в соответствующем :ref:`разделе справочника по модулям <net_box-module>`." | ||
|
||
msgid "Sandbox configuration" | ||
msgstr "Настройка песочницы" | ||
|
||
msgid "The sandbox configuration for the tutorial assumes that:" | ||
msgstr "" | ||
"Данный пример сработает на конфигурации из песочницы, предполагается, что:" | ||
|
||
msgid "The Tarantool instance is running on ``localhost 127.0.0.1:3301``." | ||
msgstr "экземпляр Tarantool запущен на ``localhost 127.0.0.1:3301``;" | ||
|
||
msgid "There is a space named ``tester`` with a numeric primary key." | ||
msgstr "создан спейс под названием ``tester`` с первичным числовым ключом;" | ||
|
||
msgid "The space contains a tuple with the key value = ``800``." | ||
msgstr "спейс содержит кортеж, в котором есть ключ со значением = 800;" | ||
|
||
msgid "The current user has read, write, and execute privileges." | ||
msgstr "у текущего пользователя есть права на чтение, запись и выполнение." | ||
|
||
msgid "Use the commands below for a quick sandbox setup:" | ||
msgstr "Используйте команды ниже для быстрой настройки песочницы:" | ||
|
||
msgid "Creating a net.box connection" | ||
msgstr "Создание подключения" | ||
|
||
msgid "" | ||
"First, load the ``net.box`` module with " | ||
"the ``require('net.box')`` method:" | ||
msgstr "" | ||
"Чтобы начать работу, запустите модуль ``net.box``, " | ||
"используя команду ``require('net.box')``:" | ||
|
||
msgid "" | ||
"The next step is to create a new connection. " | ||
"In ``net.box``, self-connection is pre-established. That is, " | ||
"``conn = net_box.connect('localhost:3301')`` command can be " | ||
"replaced with the ``conn = net_box.self`` object call:" | ||
msgstr "" | ||
"Далее необходимо создать новое подключение. " | ||
"В ``net.box`` для локального Tarantool-сервера есть заданный объект ``self`` всегда " | ||
"установленного подключения. Таким образом, команду ``conn = net_box.connect('localhost:3301')`` " | ||
"можно заменить на вызов объекта ``conn = net_box.self``." | ||
|
||
msgid "Then, make a ping:" | ||
msgstr "Запустите команду ``ping()``:" | ||
|
||
msgid "Using data operations" | ||
msgstr "Операции с данными" | ||
|
||
msgid "Select all tuples in the ``tester`` space where the key value is ``800``:" | ||
msgstr "Сделайте выборку всех кортежей в спейсе ``tester``, у которых значение ключа равно ``800``:" | ||
|
||
msgid "Insert two tuples into the space:" | ||
msgstr "Вставьте два кортежа в спейс:" | ||
|
||
msgid "" | ||
"After the insert, there is one tuple where the key value is ``600``. " | ||
"To select this tuple, you can use the ``get()`` method. " | ||
"Unlike the ``select()`` command, ``get()`` returns only one tuple " | ||
"that satisfies the stated condition." | ||
msgstr "" | ||
"После вставки в спейсе появился один кортеж со значением ключа ``600``. " | ||
"Для выбора этого кортежа вы можете использовать метод ``get()``. " | ||
"В отличие от команды ``select()``, метод ``get()`` возвращает только один кортеж, " | ||
"удовлетворяющий заданным условиям." | ||
|
||
msgid "" | ||
"To update the existing tuple, you can use either ``update()`` or ``upsert()``. " | ||
"The ``update()`` method can be used for assignment, " | ||
"arithmetic (if the field is numeric), " | ||
"cutting and pasting fragments of a field, and deleting or inserting a field." | ||
msgstr "" | ||
"Чтобы обновить существующий кортеж, вы можете использовать как метод ``update()``, так и метод ``upsert()``. " | ||
"Функция ``update()`` может использоваться для присваивания, " | ||
"арифметических операций (если поле числовое), вырезания и вставки фрагментов" | ||
" поля, а также для удаления или вставки поля." | ||
|
||
msgid "" | ||
"In this tutorial, the ``update()`` command is used to update the tuple " | ||
"identified by primary key value = ``800``. " | ||
"The operation assigns a new value to the second field in the tuple:" | ||
msgstr "" | ||
"В этом руководстве команда ``update()`` используется для обновления кортежа, " | ||
"определенного значением ключа ``800``. " | ||
"Операция присваивает новое значение второму полю в кортеже:" | ||
|
||
msgid "" | ||
"As for the ``upsert`` function, if there is an existing tuple " | ||
"that matches the key field of tuple, then the command " | ||
"has the same effect as ``update()``. " | ||
"Otherwise, the effect is equal to the ``insert()`` method." | ||
msgstr "" | ||
"Для функции ``upsert``, если уже существует кортеж, " | ||
"который совпадает с ключевыми полями tuple, запрос приведет к тому же " | ||
"результату, что и метод ``update()``. Если подходящего кортежа нет," | ||
" запрос приведет к тому же результату, что и метод ``insert()``." | ||
|
||
msgid "" | ||
"To delete a tuple where the key value is ``600``, " | ||
"run the ``delete()`` method below:" | ||
msgstr "" | ||
"Чтобы удалить кортеж, в котором значение ключа равно ``600``, " | ||
"запустите метод ``delete()``:" | ||
|
||
msgid "Then, replace the existing tuple with a new one:" | ||
msgstr "Затем замените существующий кортеж на новый:" | ||
|
||
msgid "Finally, select all tuples from the space:" | ||
msgstr "Наконец, сделайте выборку по всем кортежам из спейса:" | ||
|
||
msgid "Closing the connection" | ||
msgstr "Закрытие подключения" | ||
|
||
msgid "In the end, close the connection when it is no longer needed:" | ||
msgstr "Закройте соединение явным образом, когда оно больше не используется:" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.