Officially out now: The TypeDB 3.0 Roadmap

Social network

Lorem ipsum dolor sit amet

Log in to TypeDB Cloud and deploy a new cluster on the Clusters page.

For self-hosted TypeDB installation and setup, see the Self-hosted deployment page.

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

  1. In the TypeDB Cloud dashboard, find the cluster you want to connect, and click Connect. Copy the displayed connection URI, replacing the password placeholder with your actual database password.

  2. In Studio, click Connect to TypeDB. Paste the copied URI into the Connection URI field and click Connect.

Click Connect to TypeDB. Your connection URI is typedb-core://<host>:<port> (e.g: typedb-core://localhost:1729).

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.