Skip to main content
`Ctrl`+`K`

# Transaction

class beets.dbcore.db.Transaction(db: Database)

  Bases: `object`

  A context manager for safe, concurrent access to the database. All SQL commands should be executed through a transaction.

  __init__(db: Database) → None

  Public methods summary

  `mutate`(statement[, subvals]) | Run one write statement with shared mutation/error handling.
  `mutate_many`(statement[, subvals]) | Run batched writes with shared mutation/error handling.
  `query`(statement[, subvals]) | Execute an SQL statement with substitution values and return a list of rows from the database.
  `script`(statements) | Execute a string containing multiple SQL statements.

  Methods definition

  query(statement: str, subvals: Sequence[SQLiteType] = ()) → list[sqlite3.Row]

    Execute an SQL statement with substitution values and return a list of rows from the database.

  mutate(statement: str, subvals: Sequence[SQLiteType] = ()) → int | None

    Run one write statement with shared mutation/error handling.

  mutate_many(statement: str, subvals: Sequence[tuple[SQLiteType, ...]] = ()) → int | None

    Run batched writes with shared mutation/error handling.

  script(statements: str) → None

    Execute a string containing multiple SQL statements.