mud_server.db.connection

SQLite connection primitives for the MUD server DB layer.

This module owns connection creation and low-level SQLite runtime pragmas so repository code can stay focused on queries and transaction intent.

Functions

get_db_path()

Resolve the absolute SQLite database path from runtime configuration.

configure_connection(connection)

Apply connection-level SQLite pragmas required by the application.

get_connection()

Create and configure a new SQLite connection.

connection_scope(*[, write])

Yield a configured connection with guaranteed cleanup semantics.

Module Contents

mud_server.db.connection.get_db_path()[source]

Resolve the absolute SQLite database path from runtime configuration.

mud_server.db.connection.configure_connection(connection)[source]

Apply connection-level SQLite pragmas required by the application.

Notes

  • foreign_keys=ON is required because SQLite does not enforce foreign-key constraints by default.

  • busy_timeout reduces transient lock failures during short-lived concurrent writes in tests and local multi-process development.

mud_server.db.connection.get_connection()[source]

Create and configure a new SQLite connection.

mud_server.db.connection.connection_scope(*, write=False)[source]

Yield a configured connection with guaranteed cleanup semantics.

Parameters:

write (bool) – When True, commit on success and rollback on exceptions.

Yields:

Configured SQLite connection ready for cursor operations.

Behavior:
  • Always closes the connection in finally.

  • For write scopes, commits at the end of a successful block.

  • For write scopes, attempts rollback before re-raising failures.