Skip to content

orcalib.temp_database#

TemporaryDatabase #

TemporaryDatabase(db_name=None, verbose=False)

A context manager for creating and dropping temporary databases.

Examples:

>>> with TemporaryDatabase(db_name="my_temp_db", verbose=True) as temp_db:
...     # Use the temporary database within this block

Parameters:

  • db_name (str | None, default: None ) –

    The name of the temporary database. If not provided, a random name will be generated.

  • verbose (bool, default: False ) –

    Whether to log verbose information about the creation and dropping of the temporary database.

TemporaryTable #

1
2
3
TemporaryTable(
    db, table_name=None, verbose=False, **columns
)

A context manager for creating and dropping temporary tables in a database.

Examples:

>>> with TemporaryTable(db, table_name="my_temp_table", verbose=True, columns=["id INT", "name TEXT"]) as table:
...     # Use the temporary table within this block

Parameters:

  • db (OrcaDatabase) –

    The database object where the temporary table will be created.

  • table_name (str | None, default: None ) –

    The name of the temporary table. If not provided, a unique name will be generated.

  • verbose (bool, default: False ) –

    Whether to log information about creating and dropping the temporary table.

  • columns (OrcaTypeHandle, default: {} ) –

    Additional keyword arguments to be passed to the create_table method of the database.