Qt/C++ connector
for Tarantool database.
Implemented the basic methods of managing the base and getting statistical information from the Tarantool server.
The connector methods and a description of how they work can be found in the API
section of this document.
In the Demo directory of examples of how to use the connector, you will find - TNT-Viewer, which can be used to view and make some changes to the existing Tarantool
database.
EN RU | # Sources | # Documentation | # Releases |
---|
Tarantool
is a Lua
application server that includes a resident NoSQL
database,
which has high speed compared to traditional RDBMS with the same properties:
persistence, ACID transactivity, replications - master-slave, master-master.
more info..
Server | User | Space | Index | Service | +++ |
---|
All connector methods are blocking
.
Control will be returned if a server reply is received (with any status
) or by timeout
.
- connectToServer(const QString &uri)
type | brief | |
---|---|---|
return | bool | Current server connection status |
uri | QString | The URI server string in the format: protocol://location:port |
Connects to the Tarantool
server. It also generate signalConnected( bool )
signal. If there was an established server connection at the time the method was called, it connection will be disconnected.
#include "../../src/qtarantool.h"
using namespace QTNT;
QTarantool tnt;
/*** Standard TCP connection to the server ***/
qDebug() << tnt.connectToServer("http://localhost:3301");
// OR
qDebug() << tnt.connectToServer("tcp://localhost:3301");
/*** UNIX-sockets connection ***/
qDebug() << tnt.connectToServer("unix:/tmp/tnt.sock");
/*** Secure SSL/TLS TCP-connection (if it is supported by the server) ***/
qDebug() << tnt.connectToServer("https://localhost:3301");
- disconnectServer()
Disconnects the previously established connection to the Tarantool
server.
Also generates signalConnected( bool )
signal.
qDebug() << tnt.disconnectServer();
- isConnected()
type | brief | |
---|---|---|
return | bool | Current server connection status |
if(tnt.isConnected())
{
// TODO
}
- ping()
type | brief | |
---|---|---|
return | qint64 | Measured server reply time in `nanoseconds' |
qDebug("server ping: %lld nS", tnt.ping());
- cfg()
type | brief | |
---|---|---|
return | QVariantMap | All non-zero server Tarantool configuration parameters that box.cfg returns |
qDebug("%s", QJsonDocument::fromVariant(tnt.cfg())
.toJson(QJsonDocument::Indented)
.data());
- slab(const SLAB type)
type | brief | |
---|---|---|
return | QVariantMap | Information on memory usage by the server. Read more... |
type | SLAB::INFO | Show aggregated memory usage report |
SLAB::DETAIL | Show detailed memory usage report | |
SLAB::RUNTIME | Show memory usage report for the Lua runtime environment |
qDebug("%s", QJsonDocument::fromVariant(QVariantMap {
{"slab::info", tnt.slab(SLAB::INFO)},
{"slab::detail", tnt.slab(SLAB::DETAIL)},
{"slab::runtime", tnt.slab(SLAB::RUNTIME)}})
.toJson(QJsonDocument::Indented)
.data());
- info()
type | brief | |
---|---|---|
return | QVariantMap | All server status information returned by the `box.info' module |
qDebug("%s", QJsonDocument::fromVariant(tnt.info())
.toJson(QJsonDocument::Indented)
.data());
- stat(const STAT type)
type | brief | |
---|---|---|
return | QVariantMap | Statistics on server network usage and requests. Read more... |
type | STAT::REQUESTS | Shows the total number of requests since start-up and the average number of requests per second |
STAT::NETWORK | Shows statistics for network requests | |
STAT::VINYL | Shows the activity of the Vinyl -engine |
qDebug("%s", QJsonDocument::fromVariant(QVariantMap {
{"stat::requests", tnt.stat(STAT::REQUESTS)},
{"stat::network", tnt.stat(STAT::NETWORK)},
{"stat::vinyl", tnt.stat(STAT::VINYL)}})
.toJson(QJsonDocument::Indented)
.data());
- getServerDirectory()
type | brief | notes | |
---|---|---|---|
return | QString | Server working directory | The one marked '.' in the box.cfg configuration |
qDebug() << tnt.getServerDirectory();
- startLocalServer(const QString &filename)
not implemented
- stopLocalServer()
not implemented
- login(const QString &userName, const QString &password)
type | brief | |
---|---|---|
return | bool | Authentication result |
userName | QString | User name |
password | QString | User password |
The authentication procedure is mandatory once a connection to the server has been established. Empty password is only allowed for the guest
user.
if(tnt.login("Alice", "alice-password"))
qDebug("Auth Success!");
else
qDebug("Auth Failed.");
- logout()
type | brief | |
---|---|---|
return | bool | Authentication result as guest user |
Closes the current user's session and login as guest
.
tnt.logout();
- getUserName()
type | brief | notes | |
---|---|---|---|
return | QString | Current user name | the current user must have execute privilege to execute this request |
The current user name will be requested from the server.
qDebug() << tnt.getUserName();
- createUser(const QString &userName, const QString &userPassword)
type | brief | notes | |
---|---|---|---|
return | bool | Result of creating a new user | The current user must have create privilege to create new users. The user password is mandatory and cannot be empty. |
userName | QString | Name of new user | |
userPassword | QString | Password of new user |
The method creates a new user with the specified password. If the user already existed the method will fail and return false
.
qDebug() << tnt.createUser("Bob", "123");
- grantUser(const QString &userName, const QString &userPrivileges, const QString &objectType, const QString &objectName)
type | brief | notes | |
---|---|---|---|
return | bool | The result of granting the user new privileges. If the user already had the specified privileges, the request will be ignored and the method will return true |
The specified object must exist. Current user must have the privilege to modify the specified object. |
userName | QString | Name of the user who will be granted the new privileges | |
userPrivileges | QString | A string of comma-separated privileges to will be granted to the user | Valid values: read , write , execute , session , usage , create , drop , alter , reference , trigger , insert , update , delete |
objectType | QString | The type of object for which the privileges are granted. | Valid values: 'space' , 'user' , 'role' , 'sequence' , 'function' , 'trigger' , 'universe' (by default 'universe' ). Values other than null /nil is necessarily enclosed in single quotes ' |
objectName | QString | Object name | Arbitrary (by default null ). Must be enclosed in single quotes ' |
More about user privileges ..
Why the user cannot make requests like EVAL, i.e. - all of this connector ..
// full access to 'Test' space for user 'Bob'
qDebug() << tnt.grantUser("Bob", "read,write,execute,create,drop", "'space'", "'Test'");
- grantUserByRole(const QString &userName, const QString &userRole)
type | brief | |
---|---|---|
return | bool | Result of adding a new role to a user |
userName | QString | User name |
userRole | QString | Name of the existing new user role |
The method adds a new role to the user.
- resetGrants(const QString &userName, const QString &newUserPrivileges, const QString &objectType, const QString &objectName)
not implemented
- deleteUser(const QString &userName)
type | brief | notes | |
---|---|---|---|
return | bool | Result of deleting the specified user | If the user does not exist, the method will fail and return false |
userName | QString | User name |
Deletes the specified user.
qDebug() << tnt.deleteUser("Bob");
- isUserExist(const QString &userName)
type | brief | |
---|---|---|
return | bool | true if the user exists, otherwise false |
userName | QString | User name |
Checks if a user with the specified name exists
qDebug() << tnt.isUserExist("John");
- user()
type | brief | notes | |
---|---|---|---|
return | QString | Current user name | The name of the last successfully authenticated user stored by the QTarantool instance will be returned without requesting the Tarantool server |
qDebug() << tnt.user();
- users()
type | brief | |
---|---|---|
return | QVariantList | List of users, roles and their attributes |
Method returns list of users and roles containing lists of their attributes.
Equivalent to call box.space._user:select{}
qDebug("%s", QJsonDocument::fromVariant(tnt.users())
.toJson(QJsonDocument::Indented)
.data());
- grants(const QString &userName)
type | brief | |
---|---|---|
return | QVariantList | List of lists containing user privileges and types/names of objects to which these privileges apply |
userName | QString | User name |
qDebug("%s", QJsonDocument::fromVariant(tnt.grants("Alice"))
.toJson(QJsonDocument::Indented)
.data());
- createSpace(const QString &spaceName, const QStringList &options)
type | brief | notes | |
---|---|---|---|
return | uint | The identifier of the space created. 0 if failed. |
|
spaceName | QString | Name of the new space | |
options | QStringList | List of strings with options for space creation. | Not mandatory. Available options: engine , field_count , format , id , if_not_exists , is_local , is_sync , temporary , user read more.. |
Creates a new space with the specified name and optional parameters.
tnt.createSpace("Tester2", {"engine =memtx",
"format ={{'field1'}, {'field2'}, {'field3'}}"
});
Possible variations of the format option...
- changeSpace(const QString &spaceName, const QStringList &newParams)
type | brief | notes | |
---|---|---|---|
return | bool | Result of changing space parameters | Tarantool server version >= 2.7 (Error: attempt to call method ''alter'' (a nil value)') |
spaceName | QString | Name of Space | |
newParams | QStringList | New Space Parameters. Changeable parameters: field_count , user , format , temporary , is_sync , name |
The list of strings representing new parameter values has the same format as options for createSpace . |
Modifies some parameters of an existing space by a specified list of parameters and their values.
// create space with format
tnt.createSpace("Tester2", {"format ={{'field1'}, {'field2'}, {'field3'}, {'field4'}, {'field5'}}"});
// then, change format of space
tnt.changeSpace("Tester2", {"format ={{'F1'}, {'F2'}, {'F3'}}"});
- clearSpace(const QString &spaceName)
type | brief | |
---|---|---|
return | bool | Result of deleting a Space's data |
spaceName | QString | Space name |
Totally clears the specified space of data. All indexes and format of the space are saved.
qDebug() << tnt.clearSpace("Tester");
- deleteSpace(const QString &spaceName)
type | brief | notes | |
---|---|---|---|
return | bool | Result of deleting the specified space | Method will fail if space with the specified name does not exist |
spaceName | QString | Space name |
Deletes the specified space.
qDebug() << tnt.deleteSpace("Tester");
- isSpaceExist(const QString &spaceName)
type | brief | notes | |
---|---|---|---|
return | bool | Result of checking the existence of a space with the specified name | Does not fail with an error if the space does not exist |
spaceName | QString | Space name |
Checks if a space with the specified name exists.
qDebug() << tnt.isSpaceExist("Tester");
- spaces()
type | brief | notes | |
---|---|---|---|
return | QVariantList | A list containing all attributes of all existing spaces. | The result of the call is fully equivalent to the Lua function box.space._space:select{} Read more about the meaning of the _space fields |
The method returns a list of lists containing attributes of all existing database spaces, including system spaces. Returned values will contain only metadata of the spaces without data stored in them.
qDebug("%s", QJsonDocument::fromVariant(tnt.spaces())
.toJson(QJsonDocument::Indented)
.data());
- getData(const QString &spaceName, const Selector &selectorFrom, const Selector &selectorTo, const uint limit)
type | brief | notes | |
---|---|---|---|
return | QVariantList | List (array) of space tuples according to the specified selection criterions | |
spaceName | QString | Space name | |
selectorFrom | Selector | Structure determining the start of tuples selection. | Mandatory. Also specifies the index in which tuples will be searched. |
selectorTo | Selector | Structure determining the end of tuples selection. | Not mandatory. By default, empty - the selection is not limited. |
limit | uint | Maximum quantity of tuples to return | Not mandatory. By default =1000 |
The method returns a list of tuples by selection conditions specified by selectorFrom
/ selectorTo
and limited by limit
. With this method, tuples cannot be searched by different indexes. The index specified in selectorFrom
(by default primary
) will be applied.
Keep in mind, that:
- The Selectors must becounter-directional
- TheselectorTo
must be on the search directionselectorFrom
. Otherwise the selection will end at the Space boundary before reaching the specified search boundary.
QVariant data;
// All data of Space "Tester".
// Here the "Tester" space has a primary index named "primary":
data =tnt.getData("Tester", {});
// Data of Space "Tester" - with 'primary' index >= 100 And <= 300:
data =tnt.getData("Tester", {GE, {100}}, {LE, {300}});
// same data but in reverse sorting
data =tnt.getData("Tester", {LE, {300}}, {GE, {100}});
qDebug("%s", QJsonDocument::fromVariant(data)
.toJson(QJsonDocument::Indented)
.data());
-
-
Selector - a simple structure for specifying boundary conditions when selecting tuples from a space:
struct Selector { OPERATOR Operator; IndexKey Key; QString IndexName; };
where,
Operator
- an enumeration of possible comparison operators:Operator Semantics Symbol Brief ALL Synonym for GE
EQ EQual == Exact match GE Greater-or-Equal >= Greater than or equal to GT Greater-Than > Greater LE Less-or-Equal <= Less than or equal to (reverse direction) LT Less-Than < Less (reverse direction) REQ Reverse-EQual Same as EQ
but the reverse direction of searchKey
- a list of values ofparticular types
of arbitrary length representing the key being searched for.
Valid types of values in fields of key:<any number type>
,boolean
,string
.IndexKey
as a inherit class ofQList
is initialized from a initialization list of the key being created or from a string representing it. An instance of a key object can be serialized to text using thetext()
instance method:IndexKey key {286, "test", "текст", -3.086}; IndexKey key2("{286, \"test\", \"текст\", -3.086}"); qDebug() << key.text(); qDebug("%s", key.text().toUtf8().data()); qDebug() << key2.text(); qDebug("%s", key2.text().toUtf8().data()); // output // "{286,\"test\",\"текст\",-3.086}" // {286,"test","текст",-3.086}
Examples of simple keys on a single tuple index field:
{152} {"test value"} {3.14159265359}
multi-part keys for multi-part indexes:
{333, 2.71828, "text", true} {29, 01, 2023}
Multi-part keys with a complex structure -
Hierarchical
, not supported byTarantool
:{500, {{{555, 666}, 666}, 777}, 888, {600, {700, {"800"}}}, 900}
IndexName
- the name of the index that will be searched for. Defaults isprimary
, but can be anyunique/non-unique
index. It is not necessary to enclose the index name in single quotes.
-
-
getData(const QString &spaceName, const IndexKey &key, const uint field, const QString &indexName)
type | brief | notes | |
---|---|---|---|
return | QVariant & |
Value of the tuple field | The return value is a constant reference. |
spaceName | QString | Space name | |
key | IndexKey | The tuple key in the indexName index |
|
field | uint | Field number of the tuple | Fields are numbered with 1 from the beginning of the tuple. Negative values are not allowed. |
indexName | QString | Index name | Not mandatory Name of index in which key will be searched for. Can be any unique index of space spaceName . |
Returns the value of the tuple field by the specified tuple key and field number.
qDebug() << tnt.getData("Tester", {5}, 3);
- setData(const QString &spaceName, const QVariantList &tuple, const bool bIfExist =true)
type | brief | notes | |
---|---|---|---|
return | bool | Result of changing/adding a new tuple of data | |
spaceName | QString | Space name | |
tuple | QVariantList | New data tuple | |
bIfExist | bool | true - change only existing tuple with new tuple key, otherwise error: "Key not found", false - set in any case. If an old tuple is found by new key then the new tuple will replace the old one, if the key does not exist then the specified tuple will be inserted as a new tuple. |
By default true |
Changes data of existing tuple, by primary index of new tuple, or inserts new tuple (see bIfExist
).
// In this example it is expected that there is a 'Tester' space with a primary index.
qDebug() << tnt.setData("Tester", {1, "hello", true}, false);
- insertData(const QString &spaceName, const QVariantList &tuple)
type | brief | |
---|---|---|
return | bool | Result of adding a new tuple of data |
spaceName | QString | Space name |
tuple | QVariantList | New tuple of data |
Adds a new tuple of data by primary tuple key. The tuple will be added if does not exist the old tuple with the primary index of the new one, otherwise the method will end with an error.
qDebug() << tnt.insertData("Tester", {2, "hello", true}); // OK, then
qDebug() << tnt.insertData("Tester", {2, "hello", true}); // Error
- changeData(const QString &spaceName, const IndexKey &key, const uint field, const QVariant &value, const QString &indexName)
type | brief | notes | |
---|---|---|---|
return | bool | Result of changing the tuple field | |
spaceName | QString | Space name | |
key | IndexKey | Key of the tuple that is to be changed in the indexName index |
|
field | int | Position of the field that is to be changed in the tuple | The fields are numerated with 1 from the beginning or -1 from the end of the tuple. You cannot change the value of a field included in a unique index of space. |
value | QVariant | New field value | |
indexName | QString | Not mandatory. Name of the index in which the tuple is searched for the specified key key . |
Any unique index of space. By default, the primary index is used |
Changes the value of an existing tuple field. If the field
index is positive then it is counted from 1
from the beginning of the tuple, if negative then from -1
from the end of the tuple to the beginning of the tuple.
// Let's say there is a 'Tester' space with
// a primary index on the first field of type 'unsigned'
// And in this space, there is a tuple:
{115726, "Bob", "Marley", 36, 135.72, "Miami", "[email protected]", "«Money can’t buy life»", true}
// in which you want
// to change the value of the <5> field (field numeration in Lua is from 1) to <128.77>
// This means we need to change value to <128.77> the <5> field of tuple
// that has primary key <115726>:
qDebug() << tnt.changeData("Tester", {115726}, 5, 128.77);
// Or the last field of the same tuple (bool):
qDebug() << tnt.changeData("Tester", {115726}, -1, false);
This method performs only one action on the tuple field - assignment.
To perform other available actions on the tuple field(s), use the overloaded changeData()
method below.
- changeData(const QString &spaceName, const IndexKey &key, const Actions &actions, const QString &indexName)
type | brief | notes | |
---|---|---|---|
return | bool | Result of changing the tuple fields | |
spaceName | QString | Space name | |
key | IndexKey | Key of the tuple that is to be changed in the indexName index |
|
actions | Actions | List of Action structures describing actions on tuple fields |
|
indexName | QString | Not mandatory. Name of the index in which the tuple is searched for the specified key key . |
Any unique space index. By default is used primary index |
This method, like the previous one, changes the values of the tuple specified by the key
key. But unlike that method, it allows you to perform not only assignment, but also any other available action on one or several tuple fields in one request.
-
-
Actions - list of
Action
structures - planned actions on tuple fields. TheAction
structure looks like this:struct Action { QString Action; int Field; QVariant Value; };
where,
Action
- a string with a symbol of the action (operation) available for the field:Symbol
operatorSemantics Action brief =
Assign
Field = Value
Set field value to Value
+
Plus
Field += Value
Add to field value the Value
-
Minus
Field -= Value
Subtract from field value the Value
&
AND
Field &= Value
Bitwise AND
withValue
|
OR
Field |= Value
Bitwise OR
withValue
^
XOR
Field ^= Value
Bitwise XOR
withValue
The result of the operation will be placed in the appropriate field of the tuple as a new value.
Keep in mind, that:
- Bitwise operations are performed only onunsigned
fields. Those. do not apply tobool
(weirdness ofTarantool
). If the field type is not explicitly defined by the Space format, it can be changed by assigning a value of the desired type.
- More than one action on the same field in one transaction is not allowed
- If an error occurs while performing at least one operation from the list, none of the operations in the transaction will be appliedField
- The position of the field to change. The rules are the same as in the previous method for thefield
argument.Value
- The value that is used in the operation on the field.
-
To demonstrate how the method works, let's take a tuple from the previous example and make changes:
// * Add to <4> field value: 1
// * Subtract from <5> field value: 0.015
// * Change <3> field from the end (before penultimate) to: "[email protected]"
qDebug() << tnt.changeData("Tester", {115726}, {{"+", 4, 1},
{"-", 5, 0.015},
{"=", -3, "[email protected]"}});
- getSpaceId(const QString &spaceName)
type | brief | notes | |
---|---|---|---|
return | uint | Space identifier | Return 0 and fail if the space does not exist |
spaceName | QString | Space name |
Returns the identifier of the space by its name.
qDebug() << tnt.getSpaceId("Tester");
- getSpaceName(const uint spaceId)
type | brief | notes | |
---|---|---|---|
return | QString | Space name | Return an empty string and fail if the space does not exist |
spaceId | uint | Space identifier |
Returns the name of the space by its identifier.
qDebug() << tnt.getSpaceName(512);
- getSpaceLength(const QString &spaceName)
type | brief | notes | |
---|---|---|---|
return | qlonglong | Space size in number of stored tuples | -1 : on error 0 : if space is empty |
spaceName | QString | Space name |
Returns the number of tuples in the space.
qDebug() << tnt.getSpaceLength("Tester");
- getSpaceSize(const QString &spaceName)
type | brief | notes | |
---|---|---|---|
return | qlonglong | Size of data space in bytes | -1 : on error 0 : if space is empty |
spaceName | QString | Space name |
Returns the size of the Space data in bytes. Only the size taken by tuples without metadata of Space.
qDebug() << tnt.getSpaceSize("Tester");
- createIndex(const QString &spaceName, const QString &indexName, const Parts &parts, const QStringList &options)
type | brief | notes | |
---|---|---|---|
return | bool | Result of index creation | |
spaceName | QString | Space name | |
indexName | QString | Name of the index to be created | Must be unique to the space |
parts | Parts | List of Part structures describing the fields of tuples that will be included in the index being created |
Field positions are numbered from 1 from the beginning of the tuples. You do not need to enclose string values in single quotes. |
options | QStringList | Optional parameters for the index being created | Not mandatory. The 'parts' option should not be used here as it is passed by the parts list above. Valid Options |
-
-
parts - the list contains
Part
structures like:struct Part { QVariant Field; QString Type; }
where,
Field - unsigned integer, indexed field position in tuples or a string containing the field name if it is specified by the space format.
Type - a string with the name of the Lua-type value of the indexed field. Field types that can be included in an index:
unsigned
,string
,varbinary
,integer
,number
,double
,boolean
,decimal
,datetime
,uuid
,array
,scalar
,nil
. You do not need to enclose the type name in single quotes. Learn more about indexed types..examples of
Part
structures being passed:{3, "unsigned"} // {2, "signed"} // {"field5", "boolean"} //
The fields of the tuples are included in the created index exactly in the order in which they are located in the
Parts
list. Thus, the very firstPart
structure in theParts
list will become the most significant part of the index, and the last one in the list will be the least significant part of the index. Therefore, indexes that include the same fields on the same data can give different data selection results with the same query parameters:
-
QString sp ="test-space-index";
QVariant data;
uint spaceId;
bool bIndexExist;
// create space with format
qDebug() << "create space: "
<< (spaceId =tnt.createSpace(sp, {"format ={{'F1'}, {'F2'}, {'F3'}}"}));
if(!spaceId)
return;
// create indexes by field names
qDebug() << "create indexes: "
// primary index { F1 } (redundant in this example)
<< (bIndexExist =tnt.createIndex(sp, "primary", {{1, "unsigned"}})
// ascending index { F1, F2 }
&& tnt.createIndex(sp, "ascending", {{"F1", "unsigned"},
{"F2", "unsigned"}})
// descending index { F2, F1 }
&& tnt.createIndex(sp, "descending", {{"F2", "unsigned"},
{"F1", "unsigned"}}));
if(!bIndexExist)
return;
// set tuples: { { F1, F2, F3 }, { F1, F2, F3 }, ... }
for(int c =0; c < 6; ++c)
tnt.setData(sp, {c, 5 - c, tr("data-%1").arg(c)}, false);
// all data by 'ascending' index
data =tnt.getData(sp, {ALL, {}, "ascending"});
qDebug("%s", QJsonDocument::fromVariant(data).toJson(QJsonDocument::Indented).data());
// all data by 'descending' index
data =tnt.getData(sp, {ALL, {}, "descending"});
qDebug("%s", QJsonDocument::fromVariant(data).toJson(QJsonDocument::Indented).data());
/*** RESULTS ***
All data by 'ascending' index
[
[0, 5, "data-0"],
[1, 4, "data-1"],
[2, 3, "data-2"],
[3, 2, "data-3"],
[4, 1, "data-4"],
[5, 0, "data-5"]
]
All data by 'descending' index
[
[5, 0, "data-5"],
[4, 1, "data-4"],
[3, 2, "data-3"],
[2, 3, "data-2"],
[1, 4, "data-1"],
[0, 5, "data-0"]
]
**************/
-
- options - a list of Lua-expression strings, like:
where, values of
{ "<option> = <value>", "<option> = <value>", ... }
Lua
-typestring
are enclosed in single quotes'
.
Table of available options:
- options - a list of Lua-expression strings, like:
Space engine | Option | Lua-Type | Brief | By default |
---|---|---|---|---|
memtx |
type |
string |
'HASH' or 'TREE' or 'BITSET' or 'RTREE' |
'TREE' |
id |
number |
last index’s id + 1 | ||
unique |
boolean |
true |
||
if_not_exists |
boolean |
false |
||
dimension |
number |
2 |
||
distance |
string |
'euclid' or 'manhattan' |
'euclid' |
|
sequence |
number|string |
|||
func |
string |
|||
hint |
boolean |
true |
||
vinyl |
bloom_fpr |
number |
vinyl_bloom_fpr |
|
page_size |
number |
vinyl_page_size |
||
range_size |
number |
vinyl_range_size |
||
run_count_per_level |
number |
vinyl_run_count_per_level |
||
run_size_ratio |
number |
vinyl_run_size_ratio |
More about the meaning of options createIndex(..)
- isIndexExist(const QString &spaceName, const QString &indexName)
type | brief | notes | |
---|---|---|---|
return | bool | The fact that the index exists | Does not fail if the index does not exist |
spaceName | QString | Space name | |
indexName | QString | Index name |
Checks if an index with the specified name exists in the space.
qDebug() << tnt.isIndexExist("Tester", "primary");
- deleteIndex(const QString &spaceName, const QString &indexName)
type | brief | |
---|---|---|
return | bool | The result of deleting the space index |
spaceName | QString | Space name |
indexName | QString | The name of the index to be deleted |
Keep in mind, that:
- You cannot delete a primary index if any other indexes exist in the space except for it.
- Deleting the primary index will delete all tuples of the space.
qDebug() << tnt.deleteIndex("Tester", "secondary");
- indexes()
type | brief | |
---|---|---|
return | QUIntMap | An object of type QMap <uint, QVariant> containing attributes of all indexes for all spaces of database. |
The method executes a Lua
-function on the server box.space._index:select{} whose result will be converted into an object of type QUIntMap
with the following structure:
*** QUIntMap ***
[spaceId]: List {
[0]: Map { <attributes> }
[1]: Map { <attributes> }
...
},
[spaceId]: List {
[0]: Map { <attributes> }
...
},
...
where, <attributes> is a QVariantMap like:
{
"iid": 0, // index identifier
"name": "", // index name
"type": "", // index type
"opts": [], // a list of the index's optional parameters
"parts": [] // list of fields included in the index
}
i.e. this is a map whose value keys are identifiers of spaces. Each map value is a list of type QVariantList
whose length is number of indexes in the corresponding space. Each element of such a list is again a map, where the keys are attribute names of the corresponding index.
- call(const QString &function, const QVariantList &args)
type | brief | |
---|---|---|
return | const REPLY & |
Result of server function call |
function | QString | Function name |
args | QVariantList |
Not mandatory. Function argument list |
The method calls the specified Lua
-function on the Tarantool
server.
The result of the function call will be placed in the server response in the format of the REPLY structure.
qDebug() << tnt.call("os.date", {"%A %B %d"}).Data[QTNT::IPROTO_DATA].toList();
- exec(const QString &script, const QVariantList &args)
type | brief | |
---|---|---|
return | const REPLY & |
The result of the script execution |
script | QString | Script to execute |
args | QVariantList |
List of script arguments |
The method executes an arbitrary Lua
-script on the Tarantool
server.
The script arguments are passed to the location marked (...
) in the body of the script.
The result of the script execution will be placed in the server response in the format of the REPLY structure.
qDebug() << tnt.exec("return box.info.version").Data[QTNT::IPROTO_DATA].toList();
qDebug() << tnt.exec("return box.info[...]", {"version"}).Data[QTNT::IPROTO_DATA].toList();
- execSQL(const QString &query, const QVariantList &args, const QVariantList &options)
Implementation not completed.
- getLastError()
type | brief | notes | |
---|---|---|---|
return | ERROR |
Information about the last error while executing the request | - the code field is reset to 0 before each request to the server - in the same format, the slot-receiving the signal error( ERROR ) will receive information about the error |
Returns information about the last error reported by the server in structure format:
struct ERROR {
int code; // Error code reported by the server
QString text; // Text message about the error reported by the server
}
- sendRequest(QUIntMap &header, const QUIntMap &body)
type | brief | |
---|---|---|
return | const REPLY & |
Server reply |
header | QUIntMap | Request header in protocol format IPROTO |
body | QUIntMap | Request data in protocol format IPROTO |
This is the only class method that sends requests directly to the server. All of the methods listed above, except for ping()
, work through it.
The server's response after unpacking the MessagePack
is placed in the Reply
structure of the QTarantool
instance. When unpacking, the execution status of the request is checked, if the status does not equal to IPROTO_OK
then the structure flag IsValid
will be reset to false
and an error( ERROR )
signal will be generated.
struct REPLY {
uint Size;
QUIntMap Header;
QUIntMap Data;
bool IsValid;
}
1. Add sources Directory "../QTarantool/src"
> Right-click on your project name in the projects window, then:
"Add Existing Directory..." >
"Browse..." >
"Start Parsing" >
"Select files matching: *.cpp; *.h;" >
"Apply Filters" >
"OK"
2. Add 'network' Qt-module to your project *.pro file:
QT += network
3. Add QTarantool header to your source file(s):
"..<relative-path-to>/qtarantool.h"
You can find test Qt-projects for QTarantool
in the Demo directory of this repository.