irradiapy.database module

This module contains the Database class.

class irradiapy.database.Database(path)[source]

Bases: Connection

A SQLite database with utility methods.

Not intended to be used directly, instead use it to inherit other database classes.

Parameters:

path (Path) – Path to the SQLite database file.

optimize()[source]

Optimize the SQLite database.

This method performs two operations to optimize the database: 1. Executes the “PRAGMA optimize” command to analyze and optimize the database. 2. Executes the “VACUUM” command to rebuild the database file, repacking it into a minimal amount of disk space.

Return type:

None

path: Path
read(table, what='*', conditions='')[source]

Reads table data from the database as a generator.

Parameters:
  • table (str) – Table to read from.

  • what (str) – Columns to select.

  • conditions (str) – Conditions to filter data.

Yields:

Generator[tuple[Any, …], None, None] – Data from the database.

read_chunk(table, what='*', condition='', chunksize=10000)[source]

Reads table data from the database as a generator in chunks. It might be faster than read for huge tables.

Parameters:
  • table (str) – Table to read from.

  • what (str) – Columns to select.

  • condition (str) – Conditions to filter data.

  • chunksize (int) – Number of rows to read per chunk.

Yields:

Generator[tuple[Any, …], None, None] – Data from the database.

read_numpy(table, what, conditions='')[source]

Reads table data from the database as a NumPy structured array.

Parameters:
  • table (str) – Table to read from.

  • what (str) – Columns to select.

  • conditions (str) – Conditions to filter data.

Returns:

Data from the database as a NumPy structured array.

Return type:

NDArray

table_exists(table_name)[source]

Checks if the given table exists in the database.

Parameters:

table_name (str) – Table’s name to check.

Returns:

Whether the table already exists or not.

Return type:

bool

table_has_column(table_name, column_name)[source]

Checks if the given table has the specified column.

Parameters:
  • table_name (str) – Table’s name to check.

  • column_name (str) – Column’s name to check.

Returns:

Whether the column exists in the table or not.

Return type:

bool