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
-
Open Studio’s Database manager window by clicking on the database icon in the top toolbar.
-
Enter the name for the new database
-
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
-
Node.js
-
Java
-
C#
-
C++
-
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.
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.
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.
databases_create(databaseManager, DB_NAME);
Where databaseManager
provides access to all database management methods for the TypeDB server,
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
-
Open Studio’s Database manager window by clicking on the database icon in the top toolbar.
-
Select a database to delete from a list of databases and click the trashcan icon on its right.
-
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
-
Node.js
-
Java
-
C#
-
C++
-
C
let databases = DatabaseManager::new(driver);
let _ = databases.get(DB_NAME)?.delete();
driver.databases.get(DB_NAME).delete()
await (await driver.databases.get(DB_NAME)).delete();
driver.databases().get(DB_NAME).delete();
driver.Databases.Get(DB_NAME).Delete();
driver.databases.get(DB_NAME).deleteDatabase();
database_delete(databases_get(databaseManager, DB_NAME));
List databases
To retrieve a full list of databases on a server, follow the steps below:
-
Studio
-
Console
-
Open Studio’s Database manager window by clicking on the database icon in the top toolbar.
-
Open the drop-down list in the top toolbar next to the database icon .
database list
To get a list of databases programmatically, use drivers:
-
Rust
-
Python
-
Node.js
-
Java
-
C#
-
C++
-
C
for db in databases.all()? {
println!("{}", db.name());
}
for db in driver.databases.all():
print(db.name)
let dbs = await driver.databases.all();
for (db of dbs) {
console.log(db.name);
}
driver.databases().all().forEach( result -> System.out.println(result.name()));
foreach (IDatabase db in driver.Databases.GetAll()) {
Console.WriteLine(db.Name);
}
for (TypeDB::Database& db: driver.databases.all()) {
std::cout << db.name() << std::endl;
}
Database* db = NULL;
while ((db = database_iterator_next(allDatabases)) != NULL) {
printf("%s\n", database_get_name(db));
}