Quickstart
This Quickstart guide shows how to set up a TypeDB database and run queries using TypeDB Studio.
TypeDB & TypeQL are in the process of being rewritten in Rust. There will be significant refinement to the language, and minor breaks in backwards compatibility. Learn about the changes on our roadmap issue on GitHub. The biggest change to TypeDB 3.0 will be our storage data structure and architecture that significantly boosts performance. We’re aiming to release 3.0 in the summer this year, along with preliminary benchmarks of TypeDB. |
Run TypeDB
To start TypeDB, select the TypeDB edition below and follow the instructions.
-
Cloud
-
Core
Log in to TypeDB Cloud and create a new deployment on the Deployments page.
For self-hosted TypeDB Cloud installation and setup, see the Self-hosted deployment page.
TypeDB Core needs to be installed first.
To start a local TypeDB Core server:
$ typedb server
To create and run a new Docker container with TypeDB Core server:
$ docker run --name typedb -d -v typedb-data:/opt/ -p 1729:1729 --platform linux/amd64 vaticle/typedb:latest
Connect to TypeDB
There are several ways to connect to a running TypeDB server. In this quickstart guide we will use TypeDB Studio, a standalone TypeDB Client with GUI that needs to be installed and launched separately from a TypeDB server.
Find the TypeDB Studio binary and run it. Click Connect to TypeDB on the right side of the top toolbar.
-
Cloud
-
Core
-
Click Connect to TypeDB on the right side of the top toolbar.
-
Switch the
Server
field drop-down toTypeDB Cloud
. -
Click Manage Cloud Addresses button.
-
Add address and port for at least one server from your TypeDB Cloud deployment. Close the Address management window.
-
Fill in the
Username
andPassword
fields with valid user credentials. -
Turn on the
Enable TLS
option and leave theCA Certificate
field empty.
For self-hosted deployments, encryption parameters may vary. -
Click
Connect
.
On your first login you will be asked to change the password for the |
Select a project folder
To enable TypeDB Studio’s IDE functionality, you now need to select a project folder to store your project files. Select a project folder by clicking either Open Project in the Project panel or Open Project Directory button in the top toolbar.
Create a new database
Create a database to play with:
-
Click the database icon () in the top toolbar.
-
Enter a name for a new database, for example,
typedb-1
, and click Create. -
Select the new database from the dropdown to the right of the database icon.
Define a schema
A new database needs a schema before we can load any data:
-
Ensure the Session toggle (
schema
/data
) is set toschema
and the Transaction toggle (write
/read
) is set towrite
. -
Open a new tab and copy-paste the following Define query:
define id sub attribute, abstract, value string; email sub id, value string; name sub id, value string; path sub id, value string; username sub id, value string; size-kb sub attribute, value long; updated sub attribute, value datetime; permission sub relation, owns updated, relates object, relates subject, relates action; action sub entity, owns name @key, plays permission:action; file sub entity, owns path @key, owns size-kb, plays permission:object; person sub entity, owns name; user sub person, owns username @key, owns email @unique, plays permission:subject;
-
Click the Run Query button.
-
When the query has completed, click Commit Transaction ().
Now that the schema has been defined, data can be inserted into the database.
Load data
Now let’s insert some sample data into the newly created database to be able to query in future steps:
-
Ensure the Session toggle is set to
data
and the Transaction toggle is set towrite
. -
Open a new tab and copy-paste the following Insert queries:
insert $p isa person, has name "Charlie"; $u1 isa user, has name "Bob", has username "bob_93", has email "bob@typedb.com"; $u2 isa user, has name "Alex", has username "al-capucino"; $f1 isa file, has path "README.md"; $f2 isa file, has path "docs/quickstart-guide.adoc", has size-kb 3458761; $full isa action, has name "full"; $write isa action, has name "write"; $read isa action, has name "read"; $p1(subject:$u1, object:$f1, action:$full) isa permission, has updated 2023-10-27T12:04:36; $p2(subject:$u2, object:$f2, action:$write) isa permission;
-
Execute all queries in the file by clicking the Run Query button.
-
When the queries have completed, click Commit Transaction ().
Assuming there were no errors in the process, the data is persisted in the database.
Finish
Congratulations on completing the TypeDB quickstart guide! Now you can try sending your first queries to the database.
To learn about TypeDB’s advanced and unique features such as polymorphic queries, type inference, type inheritance, rule-based reasoning, and n-ary relations, we recommend you check the Learn more section.