Officially out now: The TypeDB 3.0 Roadmap

Open a session

This guide covers session control and best practices with Studio, Console, or one of the drivers. Both Studio and Console provide automated session control, so you don’t need to open and close sessions manually. To open a session, you need to choose a session type and an existing database.

Understanding sessions

A session represents an active connection to a specific database on a TypeDB server, and it can be of two types: schema and data. The schema session type is specifically employed for Define and Undefine queries.

Open a new session

Before you begin, Make sure to create a new database using instructions from the Create a database page. To open a session to a database, you need to have a connection to the server and know the name of the database.

  • Studio

  • Console

Studio controls transactions automatically when you run a query.

Use the Session type switch at the top toolbar to select the type of session to use to send a query. For the selector to be active, you need to connect Studio to TypeDB server and select a database from a drop-down list in the top toolbar.

Console controls sessions automatically.

You choose a session type when you open a transaction.

TypeDB drivers provide manual session control via native API:

  • Rust

  • Python

  • Node.js

  • Java

  • C#

  • C++

  • C

Open a session
let databases = DatabaseManager::new(driver);
let session = Session::new(databases.get(DB_NAME)?, SessionType::Schema)?;

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

Open a session
session = driver.session(DB_NAME, SessionType.SCHEMA)

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

Open a session
let session = await driver.session(DB_NAME, SessionType.SCHEMA);

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

Open a session
TypeDBSession session = driver.session(DB_NAME, TypeDBSession.Type.SCHEMA);

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

Open a session
ITypeDBSession session = driver.Session(DB_NAME, SessionType.Data);

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

Open a session
TypeDB::Session session = driver.session(DB_NAME, TypeDB::SessionType::SCHEMA, options);

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

Open a session
session = session_new(databaseManager, DB_NAME, Data, opts);

Where databaseManager provides access to all database management methods for the TypeDB server, and DB_NAME is the name of the database.

After connecting to a server and opening a session, see how to open a transaction.

Close a session

Both Studio and Console manage sessions automatically.

For manual session control, use TypeDB drivers:

  • Rust

  • Python

  • Node.js

  • Java

  • C#

  • C++

  • C

A session is automatically closed when the variable containing it is dropped from memory.

To explicitly close a session, use the force_close method:

Close a session
let _ = session.force_close();

Use a context manager to close a session when it’s longer needed, or use the close method to explicitly close a session:

Close a session
session.close()

Use the close method to explicitly close a session:

Close a session
await session.close();

Use the Try with resources statement to close a session when it’s longer needed, or use the close method to explicitly close a session:

Close a session
session.close();

A session is automatically closed when the variable containing it is dropped from memory.

To explicitly close a session, use the close method:

Close a session
session.Close();

A session is automatically closed when the variable containing it is dropped from memory.

To explicitly close a session, use the close method:

Close a session
session.close();

To close a session, use the close method:

Close a session
session_close(session);

Session management

Session timeout

Any TypeDB Client automatically exchanges internal signals with TypeDB server to keep a session alive when it’s open. If a TypeDB server doesn’t receive this signal for a period of time bigger than the timeout (default: 30 seconds) it forcibly closes the session due to inactivity.

Schema session blocks

Only one Schema session can be open at any time. An open Schema session blocks all attempt to open a write transaction in any data session. For more information on these limitations, see the Schema integrity enforcement section on the ACID guarantees page.

Learn more

See how to manage transactions in TypeDB.

See how to define a schema for your database.