Database

class bedrock_server_manager.db.database.Database(db_url: str)

Bases: object

Manages database connections and sessions.

db_url

The database connection URL.

Type:

str

engine

The SQLAlchemy engine.

Type:

Engine

SessionLocal

The session factory.

Type:

sessionmaker

_tables_created

Flag indicating if tables have been created.

Type:

bool

__init__(db_url: str)

Initializes the Database instance.

Parameters:

db_url (str, optional) – The database connection URL. If not provided, it will be loaded from the application configuration.

initialize()

Initializes the database engine and session.

Creates the SQLAlchemy engine and the session factory. This method is idempotent.

session_manager()

Context manager for database sessions.

Yields:

Session – A database session.

close()

Closes the database connection engine.

async shutdown()

Gracefully closes the database connection asynchronously.