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.
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
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.
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.
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.
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.
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.
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.
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:
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:
session.close()
Use the close method to explicitly 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:
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:
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:
session.close();
To close a session, use the close method:
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.