Console
OrientDB provides a Console Tool, which is a Java application that connects to and operates on OrientDB databases and Server instances.
Console Modes
There are two modes available to you, while executing commands through the OrientDB Console: interactive mode and batch mode.
Interactive Mode
By default, the Console starts in interactive mode. In this mode, the Console loads to an orientdb>
prompt. From there you can execute commands and SQL statements as you might expect in any other database console.
You can launch the console in interactive mode by executing the console.sh
for Linux OS systems or console.bat
for Windows systems in the bin
directory of your OrientDB installation. Note that running this file requires execution permissions.
$ cd $ORIENTDB_HOME/bin
$ ./console.sh
OrientDB console v.X.X.X (build 0) www.orientdb.com
Type 'HELP' to display all the commands supported.
Installing extensions for GREMLIN language v.X.X.X
orientdb>
From here, you can begin running SQL statements or commands. For a list of these commands, see commands.
Batch mode
When the Console runs in batch mode, it takes commands as arguments on the command-line or as a text file and executes the commands in that file in order. Use the same console.sh
or console.bat
file found in bin
at the OrientDB installation directory.
Command-line: To execute commands in batch mode from the command line, pass the commands you want to run in a string, separated by a semicolon.
$
$ORIENTDB_HOME/bin/console.sh "CONNECT REMOTE:localhost/demo;SELECT FROM Profile"
Script Commands: In addition to entering the commands as a string on the command-line, you can also save the commands to a text file as a semicolon-separated list.
$
vim commands.txt
CONNECT REMOTE:localhost/demo;SELECT FROM Profile
$$ORIENTDB_HOME/bin/console.sh commands.txt
Ignoring Errors
When running commands in batch mode, you can tell the console to ignore errors, allowing the script to continue the execution, with the ignoreErrors
setting.
$ vim commands.txt
SET ignoreErrors TRUE
Enabling Echo
Regardless of whether you call the commands as an argument or through a file, when you run console commands in batch mode, you may also need to display them as they execute. You can enable this feature using the echo
setting, near the start of your commands list.
$ vim commands.txt
SET echo TRUE
Enabling Date in prompt
Starting from v2.2.9, to enable the date in the prompt, set the variable promptDateFormat
with the date format following the SimpleDateFormat specs.
orientdb {db=test1}> set promptDateFormat "yyy-MM-dd hh:mm:ss.sss"
orientdb {db=test1 (2016-08-26 09:34:12.012)}>
Console commands
OrientDB implements a number of SQL statements and commands that are available through the Console. In the event that you need information while working in the console, you can access it using either the HELP
or ?
command.
Command | Description |
---|---|
ALTER CLASS |
Changes the class schema |
ALTER CLUSTER |
Changes the cluster attributes |
ALTER DATABASE |
Changes the database attributes |
ALTER PROPERTY |
Changes the class's property schema |
BACKUP DATABASE |
Backup a database |
BEGIN |
Begins a new transaction |
BROWSE CLASS |
Browses all the records of a class |
BROWSE CLUSTER |
Browses all the records of a cluster |
CLASSES |
Displays all the configured classes |
CLUSTER STATUS |
Displays the status of distributed cluster of servers |
CLUSTERS |
Displays all the configured clusters |
COMMIT |
Commits an active transaction |
CONFIG |
Displays the configuration where the opened database is located (local or remote) |
CONFIG GET |
Returns a configuration value |
CONFIG SET |
Set a configuration value |
CONNECT |
Connects to a database |
CREATE CLASS |
Creates a new class |
CREATE CLUSTER |
Creates a new cluster inside a database |
CREATE CLUSTER |
Creates a new record cluster |
CREATE DATABASE |
Creates a new database |
CREATE EDGE |
Create a new edge connecting two vertices |
CREATE INDEX |
Create a new index |
CREATE LINK |
Create a link reading a RDBMS JOIN |
CREATE VERTEX |
Create a new vertex |
DECLARE INTENT |
Declares an intent |
DELETE |
Deletes a record from the database using the SQL syntax. To know more about the SQL syntax go here |
DICTIONARY KEYS |
Displays all the keys in the database dictionary |
DICTIONARY GET |
Loookups for a record using the dictionary. If found set it as the current record |
DICTIONARY PUT |
Inserts or modify an entry in the database dictionary. The entry is composed by key=String, value=record-id |
DICTIONARY REMOVE |
Removes the association in the dictionary |
DISCONNECT |
Disconnects from the current database |
DISPLAY RECORD |
Displays current record's attributes |
DISPLAY RAW RECORD |
Displays current record's raw format |
DROP CLASS |
Drop a class |
DROP CLUSTER |
Drop a cluster |
DROP DATABASE |
Drop a database |
DROP INDEX |
Drop an index |
DROP PROPERTY |
Drop a property from a schema class |
EXPLAIN |
Explain a command by displaying the profiling values while executing it |
EXPORT DATABASE |
Exports a database |
EXPORT RECORD |
Exports a record in any of the supported format (i.e. json) |
FIND REFERENCES |
Find the references to a record |
FREEZE DATABASE |
Freezes the database locking all the changes. Use this to raw backup. Once frozen it uses the RELEASE DATABASE to release it |
GET |
Returns the value of a property |
GRANT |
Grants a permission to a user |
GREMLIN |
Executes a Gremlin script |
IMPORT DATABASE |
Imports a database previously exported |
INDEXES |
Displays information about indexes |
INFO |
Displays information about current status |
INFO CLASS |
Displays information about a class |
INSERT |
Inserts a new record in the current database using the SQL syntax. To know more about the SQL syntax go here |
JS |
Executes a Javascript in the console |
JSS |
Executes a Javascript in the server |
LIST DATABASES |
List the available databases |
LIST CONNECTIONS |
List the available connections |
LOAD RECORD |
Loads a record in memory and set it as the current one |
LOAD SCRIPT |
Loads a script and execute it |
PROFILER |
Controls the Profiler |
PROPERTIES |
Returns all the configured properties |
pwd |
Display current path |
REBUILD INDEX |
Rebuild an index |
RELEASE DATABASE |
Releases a Console Freeze Database database |
RELOAD RECORD |
Reloads a record in memory and set it as the current one |
RELOAD SCHEMA |
Reloads the schema |
ROLLBACK |
Rollbacks the active transaction started with begin |
RESTORE DATABASE |
Restore a database |
SELECT |
Executes a SQL query against the database and display the results. To know more about the SQL syntax go here |
REVOKE |
Revokes a permission to a user |
SET |
Changes the value of a property |
SLEEP |
Sleep for the time specified. Useful on scripts |
TRAVERSE |
Traverse a graph of records |
TRUNCATE CLASS |
Remove all the records of a class (by truncating all the underlying configured clusters) |
TRUNCATE CLUSTER |
Remove all the records of a cluster |
TRUNCATE RECORD |
Truncate a record you can't delete because it's corrupted |
UPDATE |
Updates a record in the current database using the SQL syntax. To know more about the SQL syntax go here |
HELP |
Prints this help |
EXIT |
Closes the console |
Custom Commands
In addition to the commands implemented by OrientDB, you can also develop custom commands to extend features in your particular implementation. To do this, edit the OConsoleDatabaseApp class and add to it a new method. There's an auto-discovery system in place that adds the new method to the available commands. To provide a description of the command, use annotations. The command name must follow the Java code convention of separating words using camel-case.
For instance, consider a case in which you might want to add a MOVE CLUSTER
command to the console:
@ConsoleCommand(description = "Move the physical location of cluster files")
public void moveCluster(
@ConsoleParameter(name = "cluster-name", description = "The name or the id of the cluster to remove") String iClusterName,
@ConsoleParameter(name = "target-path", description = "path of the new position where to move the cluster files") String iNewPath ) {
checkCurrentDatabase(); // THE DB MUST BE OPENED
System.out.println("Moving cluster '" + iClusterName + "' to path " + iNewPath + "...");
}
Once you have this code in place, MOVE CLUSTER
now appears in the listing of available commands shown by HELP
.
orientdb> HELP
AVAILABLE COMMANDS:
* alter class Alter a class in the database schema
* alter cluster Alter class in the database schema
... ...
* move cluster Move the physical location of cluster files
... ...
* help Print this help
* exit Close the console
orientdb> MOVE CLUSTER foo /temp
Moving cluster 'foo' to path /tmp...
In the event that you develop a custom command and find it especially useful in your deployment, you can contribute your code to the OrientDB Community!