type_bridge.session¶
session
¶
Session and transaction management for TypeDB.
Database
¶
Main database connection and session manager.
Initialize database connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
TypeDB server address |
'localhost:1729'
|
database
|
str
|
Database name |
'typedb'
|
username
|
str | None
|
Optional username for authentication |
None
|
password
|
str | None
|
Optional password for authentication |
None
|
driver
|
Driver | None
|
Optional pre-existing Driver instance to use. If provided, the Database will use this driver instead of creating a new one. The caller retains ownership and is responsible for closing it. |
None
|
Source code in type_bridge/session.py
connect
¶
Connect to TypeDB server.
If a driver was injected via init, this method does nothing (the driver is already connected). Otherwise, creates a new driver.
Source code in type_bridge/session.py
close
¶
Close connection to TypeDB server.
If the driver was injected via init, this method only clears the reference without closing the driver (the caller retains ownership). If the driver was created internally, it will be closed.
Source code in type_bridge/session.py
__enter__
¶
__exit__
¶
__del__
¶
Destructor that warns if driver was not properly closed.
Source code in type_bridge/session.py
create_database
¶
Create the database if it doesn't exist.
Source code in type_bridge/session.py
delete_database
¶
Delete the database.
Source code in type_bridge/session.py
database_exists
¶
transaction
¶
transaction(transaction_type: TransactionType) -> TransactionContext
transaction(transaction_type: str = 'read') -> TransactionContext
Create a transaction context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transaction_type
|
TransactionType | str
|
TransactionType or string ("read", "write", "schema") |
'read'
|
Returns:
| Type | Description |
|---|---|
TransactionContext
|
TransactionContext for use as a context manager |
Source code in type_bridge/session.py
execute_query
¶
Execute a query and return results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
TypeQL query string |
required |
transaction_type
|
str
|
Type of transaction ("read", "write", or "schema") |
'read'
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of result dictionaries |
Source code in type_bridge/session.py
get_schema
¶
Get the schema definition for this database.
Source code in type_bridge/session.py
Transaction
¶
Wrapper around TypeDB transaction.
Initialize transaction wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tx
|
Transaction
|
TypeDB transaction |
required |
Source code in type_bridge/session.py
execute
¶
Execute a query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
TypeQL query string |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of result dictionaries |
Source code in type_bridge/session.py
commit
¶
rollback
¶
TransactionContext
¶
Context manager for sharing a TypeDB transaction across operations.
Source code in type_bridge/session.py
execute
¶
commit
¶
rollback
¶
manager
¶
Get a TypeDBManager bound to this transaction.
Source code in type_bridge/session.py
ConnectionExecutor
¶
Delegate that handles query execution across connection types.
This class encapsulates the logic for executing queries against different connection types (Database, Transaction, TransactionContext, or proxy equivalents), providing a unified interface for CRUD operations.
Initialize the executor with a connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection
|
Connection
|
Database, Transaction, TransactionContext, or proxy equivalent |
required |
Source code in type_bridge/session.py
execute
¶
Execute query, using existing transaction or creating a new one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
TypeQL query string |
required |
tx_type
|
TransactionType
|
Transaction type (used only when creating new transaction) |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of result dictionaries |