Console
Run the console by executing console.sh under bin directory from the arcadedb directory:
$ bin/console.sh
ArcadeDB Console v26.5.1 - Copyrights (c) 2021 Arcade Data Ltd (https://arcadedb.com)
>
A warning WARNING: Using incubator modules: jdk.incubator.vector in the log can be safely ignored.
|
The following command-line arguments are supported by the console:
-
-Dallows to pass settings, -
-benables batch mode which exits after executing all commands passed via the command-lines. -
-faefail-at-end if error occurs during batch (normally batch mode breaks execution at an error).
The console supports these direct commands (not evaluated by the query engine):
Console |
HELP / ? |
QUIT / EXIT |
PWD |
|---|---|---|---|
Server |
CONNECT |
CLOSE |
LIST DATABASES |
User |
CREATE USER |
DROP USER |
|
Database |
CREATE DATABASE |
DROP DATABASE |
CHECK DATABASE |
Schema |
INFO TYPES |
INFO TYPE |
INFO TRANSACTION |
Transaction |
BEGIN |
COMMIT |
ROLLBACK |
Scripting |
SET LANGUAGE |
LOAD |
|
for which you can retrieve the following help by typing HELP or just ?:
begin -> begins a new transaction
check database -> check database integrity
close |<path>|remote:<url> <user> <pw> -> closes the database
commit -> commits current transaction
connect <path>|local:<url>|remote:<url> <user> <pw> -> connects to a database
create database <path>|remote:<url> <user> <pw> -> creates a new database
create user <user> identified by <pw> [grant connect to <db>[:<group>]*] -> creates a user
drop database <path>|remote:<url> <user> <pw> -> deletes a database
drop user <user> -> deletes a user
help|? -> ask for this help
info types -> prints available types
info type <type> -> prints details about type
info transaction -> prints current transaction
list databases |remote:<url> <user> <pw> -> lists databases
load <path> -> runs local script
pwd -> returns current directory
rollback -> rolls back current transaction
set language = sql|sqlscript|cypher|gremlin|mongo|graphql -> sets console query language
-- <comment> -> comment (no operation)
quit|exit -> exits from the console
The close command can be used without path or url, then it closes the currently connected database.
|
It can be useful to wrap longer scripts called via LOAD myscript.sql in a transaction via BEGIN; LOAD myscript.sql; COMMIT; to ensure completion of write operations.
|
The comment command -- is useful for scripts.
|
The console does line-by-line processing, so commands and queries need to be in a single line; however, a line break can be escaped by \.
|
The multi-line comment syntax /* … */ is not supported in the console, since the console reads from the terminal and script files line by line. It is required and recommended to use the single-line comment syntax -- for inline code docu or headers.
|
Tutorial
Let’s create our first database, located in our local filesystem. To identify the database you specify in a connection string. It could be either absolute, or relative to the database directory. The database directory can be explicitly set, when you start the console, like
$ ./bin/console.sh -Darcadedb.server.databaseDirectory=/databases
If no database directory is given at startup, it is the databases directory under the root path of the arcadedb server by default.
To create a new database under the database directory, you would run the following command in the console
> CREATE DATABASE mydb
If you want to create your database somewhere else in the local filesystem, you can specify a different path to the database:
> CREATE DATABASE data/mydb
Once the database has been created, you can simply connect to it:
> CONNECT mydb
Or if on a different path, specify the path where the database is located:
> CONNECT data/mydb
If you’re using the ArcadeDB Server, you can create the database through the server:
> CREATE DATABASE remote:localhost/mydb root arcadedb-password
Once created, you can always connect to the server with the following command:
> CONNECT remote:localhost/mydb root arcadedb-password
Let’s also create a user with access to "mydb":
> CREATE USER albert IDENTIFIED BY einstein GRANT CONNECT TO mydb
Now let’s create a "Profile" type:
{mydb}> CREATE DOCUMENT TYPE Profile
+---------+--------------------+
|NAME |VALUE |
+---------+--------------------+
|operation|create document type|
|typeName |Profile |
+---------+--------------------+
Command executed in 99ms
Check your new type is there:
{mydb}> INFO TYPES
AVAILABLE TYPES
+-------+--------+-----------+-------------------------------------+-----------+-------------+
|NAME |TYPE |SUPER TYPES|BUCKETS |PROPERTIES |SYNC STRATEGY|
+-------+--------+-----------+-------------------------------------+-----------+-------------+
|Profile|Document|0[] |8[Profile_0,...,Profile_7]|0[] |round-robin| |
+-------+--------+-----------+-------------------------------------+-----------+-------------+
You can also query the defined types by executing the following SQL query: select from schema:types.
Finally, let’s create a document of type "Profile":
{mydb}> INSERT INTO Profile SET name = 'Jay', lastName = 'Miner'
DOCUMENT @type:Profile @rid:#1:0
+--------+-----+
|NAME |VALUE|
+--------+-----+
|name |Jay |
|lastName|Miner|
+--------+-----+
Command executed in 17ms
You can see your brand new record with RID #1:0.
Now let’s query the database to see if our new document can be found:
{mydb}> SELECT FROM Profile
DOCUMENT @type:Profile @rid:#1:0
+--------+-----+
|NAME |VALUE|
+--------+-----+
|name |Jay |
|lastName|Miner|
+--------+-----+
Command executed in 37ms
Here we go: our document is there.
Remember that a transaction is automatically started. In order to make changes persistent, execute a COMMIT command.
When the console exists (exit or quit command), the pending transaction is committed automatically.
Settings
The console provides specific settings accessible via:
> SET <setting> = <value>
The following console settings are available:
| Setting | Type | Default |
|---|---|---|
asyncmode |
boolean |
false |
expandresultset |
boolean |
false |
language |
string |
sql |
limit |
integer |
20 |
maxmultivalueentries |
integer |
10 |
maxwidth |
integer |
150 |
transactionbatchsize |
integer |
0 |
verbose |
integer |
3 |
The language setting can be sql, sqlscript, cypher, gremlin, mongo, or graphql.
|
| Other settings can be changed this way, too. |
Here is an example using SQLscript:
{mydb}> SET language = sqlscript
{mydb}> IF (1 = 1) { \ SELECT 1; \ }
Scripting
The console can also run local SQL scripts using the LOAD command:
$ bin/console.sh -b "LOAD myscript.sql"
or passing the commands as string argument:
$ bin/console.sh "CREATE DATABASE test; CREATE DOCUMENT TYPE doc; BACKUP DATABASE; exit;"
Make sure to create database or connect to a database first in the script before using SQL commands.
|
| All commands (of a script) are executed, disregarding if a previous command failed. |
Console-Server Interaction
| The console cannot access a database via local connection when a server is running. |
When the server is running it locks all (opened) databases,
hence the console cannot access these databases via local connection which utilizes the file system.
Nonetheless, the console can still connect to these databases via a remote connection,
particularly, using localhost if the console is running on the same machine as the server:
> CONNECT remote:localhost/mydb root arcadedb-password