jdxi_editor.core.db.session

SQLAlchemy base and session management for JD-Xi Editor.

This module provides the declarative base and session management utilities for SQLAlchemy ORM operations.

Classes

DatabaseSession

Manages SQLAlchemy database sessions and connections.

Module Contents

class jdxi_editor.core.db.session.DatabaseSession(db_path: pathlib.Path | None = None)[source]

Manages SQLAlchemy database sessions and connections.

db_path = None[source]
engine[source]
SessionLocal[source]
create_indexes()[source]

Create database indexes for better query performance.

An Index attaches itself to the table definition, which is shared by every session in the process. Building new ones on each call left duplicates there, and the next session’s create_tables() on a new database failed with “index … already exists”. Existing ones are reused instead.

create_tables()[source]

Create all database tables, and add columns that newer versions introduced to tables made by older ones.

add_missing_columns() → list[source]

Upgrade an older database in place: add each optional (nullable) column of the models that its tables lack. create_all() makes missing tables but never changes existing ones. Returns “table.column” for each column added.

allow_songs_without_program() → bool[source]

Let a playlist song have no program.

SQLite cannot relax NOT NULL in place, so a table whose program_id is still required is rebuilt. The foreign key stays: a null program matches nothing, and deleting a program still removes only the songs that use it.

Returns:

bool True when the table was rebuilt

get_session()[source]

Context manager for database sessions.

Usage:
with db_session.get_session() as session:

job = session.query(JobQueue).filter_by(job_id=”123”).first()

get_session_sync() → sqlalchemy.orm.Session[source]

Get a synchronous session (caller must close it).

Returns:

SQLAlchemy session