neosqlite.client_session module

class neosqlite.client_session.ClientSession(client: Connection, options: dict[str, Any] | None = None)[source]

Bases: object

Represents a client session for transactions in NeoSQLite.

This class provides PyMongo-compatible session and transaction management by wrapping SQLite’s native ACID transactions.

__init__(client: Connection, options: dict[str, Any] | None = None)[source]

Initialize a new ClientSession.

Parameters:
  • client (Connection) – The connection instance that created this session.

  • options (dict, optional) – Session options.

property in_transaction: bool

Check if the session is currently in a transaction.

Returns:

True if in a transaction, False otherwise.

Return type:

bool

start_transaction(write_concern: dict[str, Any] | None = None)[source]

Start a new transaction.

Parameters:

write_concern (dict, optional) – Write concern for the transaction.

commit_transaction()[source]

Commit the current transaction.

abort_transaction()[source]

Abort (rollback) the current transaction.

end_session()[source]

End the session. If in a transaction, it will be aborted.

with_transaction(callback: Callable[[ClientSession], Any], read_concern: Any | None = None, write_concern: Any | None = None, read_preference: Any | None = None, max_commit_time_ms: int | None = None) Any[source]

Execute a callback in a transaction.

This method automatically starts a transaction, executes the callback, and commits the transaction if the callback succeeds. If the callback raises an exception, the transaction is aborted.

Parameters:
  • callback – A function that takes a ClientSession as its only argument.

  • read_concern (optional) – Unused in NeoSQLite.

  • write_concern (optional) – Unused in NeoSQLite.

  • read_preference (optional) – Unused in NeoSQLite.

  • max_commit_time_ms (optional) – Unused in NeoSQLite.

Returns:

The return value of the callback.