TypeDB Console
TypeDB Console is a standalone TypeDB client with a command line interface (CLI). It serves as a lightweight and powerful CLI tool to manage and query TypeDB databases.
Console is the default client distributed with TypeDB, but it can also be installed separately.
For installation instructions, see the TypeDB Studio install page. |
Connect to TypeDB
TypeDB Console can connect to TypeDB CE, TypeDB Cloud instances, or TypeDB Enterprise deployments. Running TypeDB Console initiates a network connection to a TypeDB server.
typedb console --address=<server-address> --username=<username>
You will be prompted for a password.
Use --tls-disabled
to connect to a server without encryption.
The default username and password are |
As a result, you get a welcome message from TypeDB Console followed by a command line prompt.
Welcome to TypeDB Console. >>
Interactive mode
TypeDB Console provides two levels of interaction via Read–eval–print loop (REPL): Server level and Transaction level.
At any level you can use common commands: help
, clear
, exit
.
Server level
Server level is the first level of interaction, i.e., first-level REPL. From this level, you can use commands for managing databases and users on the server. You also can open a transaction to a database, which gets you to the second level of REPL.
Transaction level
Transaction level is the second level of interaction, i.e., second-level REPL. You can control a transaction and send queries in the transaction.
To send a query, while in Transaction level, type in or insert a TypeQL query and push btn:[Enter] twice. |
Example
The following example illustrates how to create a database, define a schema, and insert some data into the database.
-
Run Console in the interactive mode and connect it to TypeDB:
typedb console --address=<server-address> --username=<username>
-
Now, run the following command to create a database:
database create sample_db
-
To define a schema, run the
transaction
command to open aschema
transaction to the database. This command opens a Transaction level REPL. Use it to send a define query and commit changes:transaction schema sample_db define entity user; commit
To send a query in the Transaction level, push btn:[Enter] twice, as a single push of the btn:[Enter] is recognized as a line break in the query.
-
Insert data with a
write
transaction:transaction write sample_db insert $u isa user; commit
The above example creates a database with the name sample_db
, defines a simple schema with a single user
type, then inserts a single instance of the type into the database.
Non-interactive mode
You can run Console commands using the --command
argument:
typedb console --command=<command1> --command=<command2>
The following example achieves the same results as the one in the interactive mode via the command line arguments. Run the following command in a terminal to start TypeDB and execute queries:
typedb console --address=<server-address> --username=<username> \
--command="database create sample_db" \
--command="database list" \
--command="transaction schema sample_db" \
--command="define entity user;" \
--command="commit" \
--command="transaction write sample_db" \
--command='insert $u isa user;' \
--command="commit"
Scripting
You can create a script file that contains the list of commands to run. These are the very same commands that are used in the interactive mode or non-interactive mode.
To use a script file with commands, run Console with the --script
argument and a path to the script file:
typedb console --script=<script-file-path>
By convention, console scripts, which can manipulate transactions and server state, use the .tqls
extension.
In contrast, files containing only TypeQL queries normally use the .tql
extension.
Scripts use the exact same format as the interactive REPL. This means queries in the script must be terminated with an empty newline. |
Script example
Prepare the script to run and save it to a local file.
For example, let’s try the following script.tqls
file:
database create test transaction schema test define entity user owns name; attribute name value string; commit transaction write test insert $u isa user, has name "Bob"; commit transaction read test match $u isa user, has name $n; select $n; close database delete test
Execute the script with TypeDB Console non-interactively:
typedb console --username=<username> --password=<password> --script=<PATH/script.tqls>
Where <PATH/script.tqls>
is the path to the file and the filename.
Run query(ies) from a file
To run a series of TypeQL queries stored in a file from within a REPL, use the source <filename>
command. Each query should be separated with an end;
statement and a newline. Multi-clause queries over multiple lines are considered one pipeline until an end;
clause is encountered or the query unambiguously ends (such as a fetch
clause).
This command is available from the Transaction level REPL:
transaction schema sample_db
source schema.tql
commit
The schema.tql
file should be located in the working directory or be an absolute path.
Troubleshooting
Non-ASCII characters
TypeDB can use type and variable labels and store string value attributes that have characters outside the ASCII range, for example, non-English letters, symbols, and emojis. To manipulate them using Console, the Console’s terminal must use a locale with a compatible code set, such as Unicode.
If it doesn’t, these characters will most likely be rendered as ?
symbols in Console.
If this issue occurs, you can use the following fix:
-
Linux
-
macOS
-
Windows
Use locale -a
to list all installed locales, and use export
to set the environment.
For example, to use en_US.UTF-8
run:
export LANG=en_US.UTF-8 && export LC_ALL=en_US.UTF-8
Use locale -a
to list all installed locales, and use export
to set the environment.
For example, to use en_US.UTF-8
run:
export LANG=en_US.UTF-8 && export LC_ALL=en_US.UTF-8
Use Windows Terminal
or run chcp in the terminal (e.g., chcp 936
for Chinese text).
Most systems also allow us to set the system-wide locale. However, this impacts the appearance of other applications.
References
Console CLI arguments
The following arguments can be used when invoking TypeDB Console:
Argument |
Alias |
Description |
|
Address to which Console will connect to: IP address and IP port separated by colon.
Note that by default, TLS is enabled, which will require an |
|
|
|
Show help message. |
|
Username. |
|
|
Explicitly pass in the password (not recommended). Interactive sessions should let the console safely request for the password. |
|
|
Disable TLS connections. For TypeDB Cloud deployments, there is no reason to use this setting as they can only operate with network TLS encryption. Typically used for development or local work. When using this option, username/password will be sent over the network in plaintext. |
|
|
Path to the TLS root CA file, when the server is using self-managed certificates. |
|
|
Commands to run in the Console, without interactive mode. Repeated invocations will be run in the order provided. |
|
|
Script with commands to run in the Console, without interactive mode. Repeated invocations will be run in order provided Repeated invocations will be run in the order provided. |
|
|
|
Print version information and exit. |
|
Disable anonymous error reporting. |
Server level commands
Use these commands at the Server level of TypeDB’s REPL:
Command | Description |
---|---|
Database management |
|
|
Create a database with the name |
|
List all databases on the server. |
|
Delete a database with the name |
|
Print the schema of the database with the name |
|
Export a database into a schema definition and a data files. |
|
Create a database with the given name based on another previously exported database. |
User management |
|
|
List all users on the server. |
|
Create a user with the name |
|
Set password for the user with the name |
|
Delete a user with the name |
Open a transaction |
|
|
Start a transaction to the database with the name |
Common |
|
|
Print help menu. |
|
Clear console screen. |
|
Exit console. |
Transaction level commands
Use these commands in the Transaction level of TypeDB Console’s REPL.
The prompt at the Transaction level contains the database name and the transaction type, for example,
sample_db::read>
.
Command | Description |
---|---|
Querying |
|
|
Type in TypeQL query directly. Push btn:[Enter] once for a line break in a query. Push btn:[Enter] twice (once more on a new line) to send a query. |
|
Run TypeQL queries from a file. You can use a relative or absolute path. On Windows escape |
Transaction control |
|
|
Commit the changes and close the transaction. |
|
Rollback the transaction — remove any uncommitted changes, while leaving the transaction open. |
|
Close the transaction without committing changes. |
Common |
|
|
Print help menu. |
|
Clear console screen. |
|
Exit console. |
Navigation
TypeDB console has several commonly-used REPL features:
-
Use the UP and DOWN arrows to navigate the current REPL’s history - server and transaction histories are retained separately
-
Type in a search prefix, then use UP and DOWN arrows to search the history for previous commands that share the written prefix
-
Use ctrl+r to search through history for a specific term or phrase
Version Compatibility
For older TypeDB versions, you’ll need a compatible version of TypeDB Console. Select the correct TypeDB Console version from the version compatibility table, and download it from Cloudsmith.