Skip to content

Commit d8519f0

Browse files
authored
Restructure Connectors section (#3149)
* Split the section into subparts * Separate community-supported connectors
1 parent 1d3fb18 commit d8519f0

21 files changed

+1336
-1379
lines changed

doc/book/connectors.rst

Lines changed: 104 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,30 @@
11
.. _index-box_connectors:
22

3-
-------------------------------------------------------------------------------
4-
Connectors
5-
-------------------------------------------------------------------------------
3+
Connectors
4+
==========
65

76
Connectors are APIs that allow using Tarantool with various programming languages.
87

98
Connectors can be divided into two groups -- those maintained by the Tarantool team
109
and those supported by the community.
1110
The Tarantool team maintains the :ref:`high-level C API <index_connector_c>`, the :ref:`Go <index_connector_go>`
1211
and :ref:`Java <index_connector_java>` connectors, and a synchronous :ref:`Python <index_connector_py>` connector.
13-
All other connectors are community-supported, which means that support for new Tarantool features may be delayed.
12+
All other connectors are :ref:`community-supported <connectors-community-supported>`, which means that support for new Tarantool features may be delayed.
1413
Besides, the Tarantool support team cannot prioritize issues that arise while working through these connectors.
1514

16-
This chapter documents the following connectors:
17-
18-
* :doc:`C++ <connectors/cxx/tntcxx_api>`
19-
* :ref:`Java <index_connector_java>`
20-
* :ref:`Go <index_connector_go>`
21-
* :ref:`R <index_connector_r>`
22-
* :ref:`Erlang <index_connector_erlang>`
23-
* :ref:`Perl <index_connector_perl>`
24-
* :ref:`PHP <index_connector_php>`
25-
* :ref:`Python <index_connector_py>`
26-
* :ref:`Node.js <index_connector_nodejs>`
27-
* :ref:`C# <index_connector_csharp>`
28-
* :ref:`C <index_connector_c>`
15+
This chapter documents APIs for various programming languages:
2916

3017
.. toctree::
31-
:hidden:
18+
:maxdepth: 1
3219

33-
C++ <connectors/cxx/tntcxx_api>
20+
connectors/c
21+
connectors/go
22+
connectors/java
23+
connectors/python
24+
connectors/community
3425

35-
=====================================================================
36-
Protocol
37-
=====================================================================
26+
Protocol
27+
--------
3828

3929
Tarantool's binary protocol was designed with a focus on asynchronous I/O and
4030
easy integration with proxies. Each client request starts with a variable-length
@@ -55,9 +45,9 @@ in the source tree. For detailed examples and diagrams of all binary-protocol
5545
requests and responses, see
5646
:ref:`Tarantool's binary protocol <box_protocol-iproto_protocol>`.
5747

58-
====================================================================
59-
Packet example
60-
====================================================================
48+
49+
Packet example
50+
--------------
6151

6252
The Tarantool API exists so that a client program can send a request packet to
6353
a server instance, and receive a response. Here is an example of a what the client
@@ -103,9 +93,8 @@ exist for drivers for Perl, Python, PHP, and so on.
10393

10494
.. _index-connector_setting:
10595

106-
====================================================================
107-
Setting up the server for connector examples
108-
====================================================================
96+
Setting up the server for connector examples
97+
--------------------------------------------
10998

11099
This chapter has examples that show how to connect to a Tarantool instance via
111100
the Perl, PHP, Python, node.js, and C connectors. The examples contain hard code that
@@ -131,44 +120,91 @@ script:
131120
box.schema.user.grant('guest','read,write','space','examples')
132121
box.schema.user.grant('guest','read','space','_space')
133122
134-
.. _index_connector_java:
135-
136-
.. include:: connectors/__java.rst
137-
138-
.. _index_connector_go:
139-
140-
.. include:: connectors/__go.rst
141-
142-
.. _index_connector_r:
143-
144-
.. include:: connectors/__r.rst
145-
146-
.. _index_connector_erlang:
147-
148-
.. include:: connectors/__erlang.rst
149-
150-
.. _index_connector_perl:
151-
152-
.. include:: connectors/__perl.rst
153-
154-
.. _index_connector_php:
155-
156-
.. include:: connectors/__php.rst
157-
158-
.. _index_connector_py:
159-
160-
.. include:: connectors/__python.rst
161-
162-
.. _index_connector_nodejs:
163-
164-
.. include:: connectors/__nodejs.rst
165-
166-
.. _index_connector_csharp:
167-
168-
.. include:: connectors/__csharp.rst
169-
170-
.. _index_connector_c:
171-
172-
.. include:: connectors/__c.rst
173123
174-
.. include:: connectors/__results.rst
124+
Interpreting function return values
125+
-----------------------------------
126+
127+
For all connectors, calling a function via Tarantool causes a return in the
128+
MsgPack format. If the function is called using the connector's API, some
129+
conversions may occur. All scalar values are returned as tuples (with a MsgPack
130+
type-identifier followed by a value); all non-scalar values are returned as a
131+
group of tuples (with a MsgPack array-identifier followed by the scalar values).
132+
If the function is called via the binary protocol command layer -- "eval" --
133+
rather than via the connector's API, no conversions occur.
134+
135+
In the following example, a Lua function will be created. Since it will be
136+
accessed externally by a :ref:`'guest' user<box_space-user>`, a
137+
:doc:`grant </reference/reference_lua/box_schema/user_grant>` of an execute privilege will
138+
be necessary. The function returns an empty array, a scalar string, two booleans,
139+
and a short integer. The values are the ones described in the table
140+
:ref:`Common Types and MsgPack Encodings <msgpack-common_types_and_msgpack_encodings>`.
141+
142+
.. code-block:: tarantoolsession
143+
144+
tarantool> box.cfg{listen=3301}
145+
2016-03-03 18:45:52.802 [27381] main/101/interactive I> ready to accept requests
146+
---
147+
...
148+
tarantool> function f() return {},'a',false,true,127; end
149+
---
150+
...
151+
tarantool> box.schema.func.create('f')
152+
---
153+
...
154+
tarantool> box.schema.user.grant('guest','execute','function','f')
155+
---
156+
...
157+
158+
Here is a C program which calls the function. Although C is being used for the
159+
example, the result would be precisely the same if the calling program was
160+
written in Perl, PHP, Python, Go, or Java.
161+
162+
.. code-block:: c
163+
164+
#include <stdio.h>
165+
#include <stdlib.h>
166+
#include <tarantool/tarantool.h>
167+
#include <tarantool/tnt_net.h>
168+
#include <tarantool/tnt_opt.h>
169+
void main() {
170+
struct tnt_stream *tnt = tnt_net(NULL); /* SETUP */
171+
tnt_set(tnt, TNT_OPT_URI, "localhost:3301");
172+
if (tnt_connect(tnt) < 0) { /* CONNECT */
173+
printf("Connection refused\n");
174+
exit(-1);
175+
}
176+
struct tnt_stream *arg; arg = tnt_object(NULL); /* MAKE REQUEST */
177+
tnt_object_add_array(arg, 0);
178+
struct tnt_request *req1 = tnt_request_call(NULL); /* CALL function f() */
179+
tnt_request_set_funcz(req1, "f");
180+
uint64_t sync1 = tnt_request_compile(tnt, req1);
181+
tnt_flush(tnt); /* SEND REQUEST */
182+
struct tnt_reply reply; tnt_reply_init(&reply); /* GET REPLY */
183+
tnt->read_reply(tnt, &reply);
184+
if (reply.code != 0) {
185+
printf("Call failed %lu.\n", reply.code);
186+
exit(-1);
187+
}
188+
const unsigned char *p= (unsigned char*)reply.data; /* PRINT REPLY */
189+
while (p < (unsigned char *) reply.data_end)
190+
{
191+
printf("%x ", *p);
192+
++p;
193+
}
194+
printf("\n");
195+
tnt_close(tnt); /* TEARDOWN */
196+
tnt_stream_free(arg);
197+
tnt_stream_free(tnt);
198+
}
199+
200+
When this program is executed, it will print:
201+
202+
.. code-block:: console
203+
204+
dd 0 0 0 5 90 91 a1 61 91 c2 91 c3 91 7f
205+
206+
The first five bytes -- ``dd 0 0 0 5`` -- are the MsgPack encoding for
207+
"32-bit array header with value 5" (see
208+
`MsgPack specification <http://github.com/msgpack/msgpack/blob/master/spec.md>`__).
209+
The rest are as described in the
210+
table :ref:`Common Types and MsgPack Encodings <msgpack-common_types_and_msgpack_encodings>`.

doc/book/connectors/__erlang.rst

Lines changed: 0 additions & 4 deletions
This file was deleted.

doc/book/connectors/__r.rst

Lines changed: 0 additions & 5 deletions
This file was deleted.

doc/book/connectors/__results.rst

Lines changed: 0 additions & 87 deletions
This file was deleted.

doc/book/connectors/__c.rst renamed to doc/book/connectors/c.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _index_connector_c:
2+
13
C
24
=
35

doc/book/connectors/community.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.. _connectors-community-supported:
2+
3+
Community-supported connectors
4+
==============================
5+
6+
This section provides information on several `community-supported connectors <https://www.tarantool.io/en/download/connectors>`_.
7+
Note that they may have limited support for new Tarantool features.
8+
9+
.. toctree::
10+
:maxdepth: 1
11+
12+
csharp
13+
C++ <cxx/tntcxx_api>
14+
nodejs
15+
perl
16+
php
17+
18+
For Erlang, use the `Erlang tarantool driver <https://github.com/stofel/taran>`__.
19+
20+
For R, use the `tarantoolr <https://github.com/thekvs/tarantoolr>`__ connector.
File renamed without changes.

doc/book/connectors/__go.rst renamed to doc/book/connectors/go.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _index_connector_go:
2+
13
Go
24
==
35

doc/book/connectors/__java.rst renamed to doc/book/connectors/java.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _index_connector_java:
2+
13
Java
24
====
35

File renamed without changes.
File renamed without changes.
File renamed without changes.

doc/book/connectors/__python.rst renamed to doc/book/connectors/python.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _index_connector_py:
2+
13
Python
24
======
35

@@ -8,7 +10,7 @@ of the Tarantool repository and must be installed separately (see below for deta
810
Here is a complete Python program that inserts ``[99999,'Value','Value']`` into
911
space ``examples`` via the high-level Python API.
1012

11-
.. code-block:: python
13+
.. code-block:: python
1214
1315
#!/usr/bin/python
1416
from tarantool import Connection

0 commit comments

Comments
 (0)