New ACM paper, free-tier cloud, and open-source license

Create a database

This guide covers creating a database, as well as other database management operations, like listing and deleting databases with Studio, Console, or one of the drivers.

Understanding database operation

TypeDB stores data in isolated databases, each comprising a schema and data. These databases operate independently, ensuring that one database cannot affect another. Nevertheless, a TypeDB client can connect to and interact with multiple databases concurrently.

Create a new database

Before you begin, make sure to follow the instructions on the Connect to server page to connect to TypeDB before proceeding. To create a new database, follow the steps below:

  • Studio

  • Console

  1. Open Studio’s Database manager window by clicking on the database icon database in the top toolbar.

  2. Enter the name for the new database

  3. Push Create.

The newly created database should appear in the drop-down selector of the top toolbar.

Connect with Console and run the following command:

database create sample_db

Where sample_db is the name of the database.

To create a new database programmatically, use drivers:

  • Rust

  • Python

  • Java

  • Node.js

  • C++

let databases = DatabaseManager::new(driver);
let _ = databases.create(DB_NAME);

Where driver is an instance of a driver, connected to TypeDB, and DB_NAME is the name of the database.

driver.databases.create(DB_NAME)

Where driver is an instance of a driver, connected to TypeDB, and DB_NAME is the name of the database.

driver.databases().create(DB_NAME);

Where driver is an instance of a driver, connected to TypeDB, and DB_NAME is the name of the database.

await driver.databases.create(DB_NAME);

Where driver is an instance of a driver, connected to TypeDB, and DB_NAME is the name of the database.

driver.databases.create(DB_NAME);

Where driver is an instance of a driver, connected to TypeDB, and DB_NAME is the name of the database.

Delete

To delete a database with all its data and schema, follow the steps below:

  • Studio

  • Console

  1. Open Studio’s Database manager window by clicking on the database icon database in the top toolbar.

  2. Select a database to delete from a list of databases and click the trashcan icon on its right.

  3. Confirm deletion by typing in the name of the database to delete and then clicking the Delete button.

database delete sample_db

Where sample_db is the name of the database.

To delete a database programmatically, use drivers:

  • Rust

  • Python

  • Java

  • Node.js

  • C++

let databases = DatabaseManager::new(driver);
let _ = databases.get(DB_NAME)?.delete();
driver.databases.get(DB_NAME).delete()
driver.databases().get(DB_NAME).delete();
if (await driver.databases.contains(DB_NAME)) {
    await (await driver.databases.get(DB_NAME)).delete();
}
driver.databases.get(DB_NAME).deleteDatabase();

List databases

To retrieve a full list of databases on a server, follow the steps below:

  • Studio

  • Console

  1. Open Studio’s Database manager window by clicking on the database icon database in the top toolbar.

  2. Open the drop-down list in the top toolbar next to the database icon database.

database list

To get a list of databases programmatically, use drivers:

  • Rust

  • Python

  • Java

  • Node.js

  • C++

for db in databases.all()? {
    println!("{}", db.name());
}
for db in driver.databases.all():
    print(db.name)
driver.databases().all().forEach( result -> System.out.println(result.name()));
let dbs = await driver.databases.all();
for (db of dbs) {
    console.log(db.name);
}
for (TypeDB::Database& db: driver.databases.all()) {
    std::cout << db.name() << std::endl;
}

Learn more

See how to manage sessions in TypeDB.

See how to manage transactions in TypeDB.

Provide Feedback