Officially out now: The TypeDB 3.0 Roadmap

Quickstart

This Quickstart guide shows how to set up a TypeDB database and run queries using TypeDB Studio. The guide is available in both video and text formats.

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 more about the changes from our 3.0 Roadmap. 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 autumn 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.

Ensure TypeDB Core is installed.

To start a locally installed TypeDB Core server:

typedb server

To create a new Docker container with TypeDB Core server:

docker volume create typedb-data
docker create --name typedb -v typedb-data:/opt/typedb-all-linux-x86_64/server/data -p 1729:1729 --platform linux/amd64 vaticle/typedb:latest

Connect to TypeDB

In this guide, we will use TypeDB Studio, the standalone GUI-based client for TypeDB. Ensure Studio is installed, then launch the application.

  • Cloud

  • Core

TypeDB Studio connect window
  1. Click Connect to TypeDB on the right side of the top toolbar.

  2. Switch the Server field drop-down to TypeDB Cloud.

  3. Click Manage Cloud Addresses button.

  4. Add address and port for at least one server from your TypeDB Cloud deployment, then close the Address Management window.

  5. Fill in the Username and Password fields with valid user credentials.

    For newly created deployments, the default username and password are admin and password. After connecting for the first time, you will be required to change the password before queries can be run.

  6. Turn on the Enable TLS option and leave the CA Certificate field empty. For self-hosted deployments, encryption parameters may vary.

  7. Click Connect.

TypeDB Studio connect window
  1. Click Connect to TypeDB on the right side of the top toolbar.

  2. Make sure the TypeDB Core option is selected in the Server field.

  3. Enter the address and port of the server to connect to (e.g. localhost:1729).

  4. Click Connect.

Create a project

TypeDB Studio stores queries you create as TypeQL files in a local project directory. To select a project directory, click either Open Project in the Project panel, or the studio projects Open Project Directory button in the top toolbar.

Create a new database

To create a new database:

  1. Click the studio dbs Manage Databases button in the top toolbar.

  2. Enter a name for a new database and click Create.

  3. Select the new database from the Select Database dropdown (database none) in the top toolbar.

Define a schema

A new database needs a schema before we can load any data:

  1. Ensure the session type toggle (session schema) is set to schema and the transaction type toggle (transaction write) is set to write.

  2. Open a studio new New Tab in the Text Editor and paste in the following Define query.

    define
      user sub entity,
        owns id @key,
        owns name,
        owns birth-date,
        plays purchase:buyer;
      order sub entity,
        owns id @key,
        owns timestamp,
        owns status,
        plays purchase:order;
    
      purchase sub relation,
        relates order,
        relates buyer;
    
      id sub attribute, value string;
      name sub attribute, value string;
      birth-date sub attribute, value datetime;
      timestamp sub attribute, value datetime;
      status sub attribute,
        value string,
        regex "^(paid|dispatched|delivered|returned|canceled)$";
  3. Click the studio run Run Query button.

  4. When the query has completed, click studio check Commit Transaction.

With the schema defined, we can now insert data into the database.

Load data

Let’s insert sample data for our newly defined schema:

  1. Ensure the session toggle is set to data and the transaction toggle is set to write.

  2. Open a new tab and paste in the following Insert query.

    insert
      $user-1 isa user,
        has id "u0001",
        has name "Kevin Morrison",
        has birth-date 1995-10-29;
      $user-2 isa user,
        has id "u0002",
        has name "Cameron Osborne",
        has birth-date 1954-11-11;
      $user-3 isa user,
        has id "u0003",
        has name "Keyla Pineda";
      $order-1 isa order,
        has id "o0001",
        has timestamp 2022-08-03T19:51:24.324,
        has status "canceled";
      $order-2 isa order,
        has id "o0002",
        has timestamp 2021-04-27T05:02:39.672,
        has status "dispatched";
      $order-6 isa order,
        has id "o0006",
        has timestamp 2020-08-19T20:21:54.194,
        has status "paid";
      (order: $order-1, buyer: $user-1) isa purchase;
      (order: $order-2, buyer: $user-1) isa purchase;
      (order: $order-6, buyer: $user-2) isa purchase;
  3. Click the studio run Run Query button.

  4. When the query has completed, click studio check Commit Transaction.

The data should now be persisted in the database, and is ready to be queried.

Read data

Let’s retrieve some details for orders that are currently dispatched. The following Fetch query matches any dispatched orders, and returns the order timestamp, order status, and the name of the buyer. Using a data session and read transaction, studio run run this query.

match
  $order has status "dispatched";
  (order: $order, buyer: $buyer) isa purchase;
fetch
  $order: timestamp, status;
  $buyer: name;

Update data

To update data in a database, we match the existing data, delete it, and then insert new data to replace it. The following Update query updates the status of the order with ID "o0006". Using a data session and write transaction, studio run run this query, then studio check commit the transaction.

match
  $order-6 isa order,
    has id "o0006",
    has status $old-status;
delete
  $order-6 has $old-status;
insert
  $order-6 has status "dispatched";

After committing the transaction, the updated information is persisted in the database and becomes available for querying. If we then re-run the above Fetch query, we should see the results have updated to reflect the change.

What’s next?

Continue learning how to use TypeDB with the Crash Course and TypeDB Academy, or explore other sections of the documentation.

A concise overview of the main aspects of TypeDB and TypeQL, with multiple pathways based on previous database experience.

An end-to-end learning experience for TypeDB and TypeQL, showing how to take advantage of TypeDB’s unique features.

Practice-oriented guides on using TypeDB, including the TypeDB Studio and TypeDB Console manuals.

Installation guides, tutorials, and API references for the official TypeDB drivers in all supported languages.