Variable

Can be used to assign a value to a variable which can be used within a query.

Variable can be created with READ privileges since they do not modify the collection’s data.

To create a variable, just assign a value to a valid name.

Some valid examples:

  • _ = ...
  • tmp = ...
  • var1 = ...

Variables created within a block become local. They can only be used within the block. See the example below:

a = 'This is a variable!!!';
b = 'Hello';
{
    /* This will create a new variable `a` within this block */
    a = 'New variable within this block';

    /* This will update the global variable `b` */
    b += ' World';
};
[a, b];

Return value in JSON format

[
    "This is a variable!!!",
    "Hello World"
]

Injecting variable

When running a query to ThingsDB, it is possible to inject variables into the code. This can be both easy for some data and in some cases necessary when inserting binary data.

Python example:

    # inject a variable into the code:
    client.query('.a = a;', a=1)