akkudoktoreos.core.database.SQLiteDatabase
- class akkudoktoreos.core.database.SQLiteDatabase(*args: Any, **kwargs: Any)
Bases:
DatabaseBackendABCSQLite implementation that stores a namespace column to emulate namespaces.
Methods
__init__(**kwargs)Initialize SQLite backend.
close()Close SQLite connection.
count_records([start_key, end_key, namespace])Count records in [start_key, end_key) excluding metadata.
delete_records(keys[, namespace])Delete multiple records by key.
deserialize_data(data)Optionally decompress stored data.
flush([namespace])Commit any pending transactions to disk (no-op if autocommit).
get_backend_stats([namespace])Return SQLite-specific stats and namespace metrics.
get_key_range([namespace])Return (min_key, max_key) for the namespace or (None, None) if empty.
get_metadata([namespace])Load metadata for a given namespace.
iterate_records([start_key, end_key, ...])Iterate records for a namespace within optional bounds.
open([namespace])Open SQLite connection and optionally set default namespace.
Return the unique identifier for the database provider.
Resets the singleton instance, forcing it to be recreated on next access.
save_records(records[, namespace])Bulk insert or replace records.
serialize_data(data)Optionally compress raw pickled data before storage.
set_metadata(metadata, *[, namespace])Save metadata for a given namespace.
vacuum()Run SQLite VACUUM to reduce file size.
Attributes
Whether to compress stored values.
Compression level for database record data.
Return whether the database connection is open.
Storage path for the database.
- db_file: Path
- provider_id() str
Return the unique identifier for the database provider.
- open(namespace: str | None = None) None
Open SQLite connection and optionally set default namespace.
- Parameters:
namespace – Optional default namespace to use when operations omit namespace.
- flush(namespace: str | None = None) None
Commit any pending transactions to disk (no-op if autocommit).
- set_metadata(metadata: bytes | None, *, namespace: str | None = None) None
Save metadata for a given namespace.
Metadata is treated separately from data records and stored as a single object.
- Parameters:
metadata (bytes) – Arbitrary metadata to save or None to delete metadata.
namespace (Optional[str]) – Optional namespace under which to store metadata.
- get_metadata(namespace: str | None = None) bytes | None
Load metadata for a given namespace.
Returns None if no metadata exists.
- Parameters:
namespace (Optional[str]) – Optional namespace whose metadata to retrieve.
- Returns:
The loaded metadata, or None if not found.
- Return type:
Optional[bytes]
- save_records(records: Iterable[tuple[bytes, bytes]], namespace: str | None = None) int
Bulk insert or replace records.
- Returns:
Number of records written.
- delete_records(keys: Iterable[bytes], namespace: str | None = None) int
Delete multiple records by key.
Returns True if at least one row was deleted.
- iterate_records(start_key: bytes | None = None, end_key: bytes | None = None, namespace: str | None = None, reverse: bool = False) Iterator[Tuple[bytes, bytes]]
Iterate records for a namespace within optional bounds.
Snapshot-based iteration: - Query results are materialized while holding the lock. - Yields happen after releasing the lock. - Metadata key is excluded. - Range semantics: [start_key, end_key)
- Parameters:
start_key – Inclusive lower bound or None.
end_key – Exclusive upper bound or None.
namespace – Optional namespace.
reverse – If True iterate descending.
- Yields:
(key, value) tuples ordered by key.
- count_records(start_key: bytes | None = None, end_key: bytes | None = None, *, namespace: str | None = None) int
Count records in [start_key, end_key) excluding metadata.
- get_key_range(namespace: str | None = None) Tuple[bytes | None, bytes | None]
Return (min_key, max_key) for the namespace or (None, None) if empty.
- get_backend_stats(namespace: str | None = None) Dict[str, Any]
Return SQLite-specific stats and namespace metrics.
- static __new__(cls: Type[SingletonMixin], *args: Any, **kwargs: Any) SingletonMixin
Creates or returns the singleton instance of the class.
Ensures thread-safe instance creation by locking during the first instantiation.
- Parameters:
*args – Positional arguments for instance creation (ignored if instance exists).
**kwargs – Keyword arguments for instance creation (ignored if instance exists).
- Returns:
The singleton instance of the derived class.
- Return type:
- property compression: bool
Whether to compress stored values.
- property compression_level: int
Compression level for database record data.
- config = ConfigEOS(general=GeneralSettings(home_assistant_addon=False, version='0.2.0.dev58204789', data_folder_path=Path('/home/docs/.local/share/net.akkudoktor.eos'), data_output_subpath='output', latitude=52.52, longitude=13.405, timezone='Europe/Berlin', data_output_path=Path('/home/docs/.local/share/net.akkudoktor.eos/output'), config_folder_path=Path('/home/docs/checkouts/readthedocs.org/user_builds/akkudoktor-eos/checkouts/latest/docs'), config_file_path=Path('/home/docs/checkouts/readthedocs.org/user_builds/akkudoktor-eos/checkouts/latest/docs/EOS.config.json')), cache=CacheCommonSettings(subpath='cache', cleanup_interval=300.0), database=DatabaseCommonSettings(provider=None, compression_level=9, initial_load_window_h=None, keep_duration_h=None, autosave_interval_sec=10, compaction_interval_sec=604800, batch_size=100, providers=['LMDB', 'SQLite']), ems=EnergyManagementCommonSettings(startup_delay=5, interval=300.0, mode=None), logging=LoggingCommonSettings(console_level='INFO', file_level=None, file_path=Path('/home/docs/.local/share/net.akkudoktor.eos/output/eos.log')), devices=DevicesCommonSettings(batteries=None, max_batteries=None, electric_vehicles=None, max_electric_vehicles=None, inverters=None, max_inverters=None, home_appliances=None, max_home_appliances=None, measurement_keys=[]), measurement=MeasurementCommonSettings(historic_hours=17520, load_emr_keys=None, grid_export_emr_keys=None, grid_import_emr_keys=None, pv_production_emr_keys=None, keys=[]), optimization=OptimizationCommonSettings(horizon_hours=24, interval=3600, algorithm='GENETIC', genetic=GeneticCommonSettings(individuals=300, generations=400, seed=None, penalties=None), keys=[]), prediction=PredictionCommonSettings(hours=48, historic_hours=48), elecprice=ElecPriceCommonSettings(provider=None, charges_kwh=None, vat_rate=1.19, elecpriceimport=ElecPriceImportCommonSettings(import_file_path=None, import_json=None), energycharts=ElecPriceEnergyChartsCommonSettings(bidding_zone=<EnergyChartsBiddingZones.DE_LU: 'DE-LU'>), providers=['ElecPriceAkkudoktor', 'ElecPriceEnergyCharts', 'ElecPriceImport']), feedintariff=FeedInTariffCommonSettings(provider=None, provider_settings=FeedInTariffCommonProviderSettings(FeedInTariffFixed=None, FeedInTariffImport=None), providers=['FeedInTariffFixed', 'FeedInTariffImport']), load=LoadCommonSettings(provider=None, provider_settings=LoadCommonProviderSettings(LoadAkkudoktor=None, LoadVrm=None, LoadImport=None), providers=['LoadAkkudoktor', 'LoadAkkudoktorAdjusted', 'LoadVrm', 'LoadImport']), pvforecast=PVForecastCommonSettings(provider=None, provider_settings=PVForecastCommonProviderSettings(PVForecastImport=None, PVForecastVrm=None), planes=None, max_planes=0, providers=['PVForecastAkkudoktor', 'PVForecastVrm', 'PVForecastImport'], planes_peakpower=[], planes_azimuth=[], planes_tilt=[], planes_userhorizon=[], planes_inverter_paco=[]), weather=WeatherCommonSettings(provider=None, provider_settings=WeatherCommonProviderSettings(WeatherImport=None), providers=['BrightSky', 'ClearOutside', 'WeatherImport']), server=ServerCommonSettings(host='127.0.0.1', port=8503, verbose=False, startup_eosdash=True, eosdash_host=None, eosdash_port=None), utils=UtilsCommonSettings(), adapter=AdapterCommonSettings(provider=None, homeassistant=HomeAssistantAdapterCommonSettings(config_entity_ids=None, load_emr_entity_ids=None, grid_export_emr_entity_ids=None, grid_import_emr_entity_ids=None, pv_production_emr_entity_ids=None, device_measurement_entity_ids=None, device_instruction_entity_ids=None, solution_entity_ids=None, homeassistant_entity_ids=[], eos_solution_entity_ids=[], eos_device_instruction_entity_ids=[]), nodered=NodeREDAdapterCommonSettings(host='127.0.0.1', port=1880), providers=['HomeAssistant', 'NodeRED']))
- deserialize_data(data: bytes) bytes
Optionally decompress stored data.
- Parameters:
data – Stored bytes.
- Returns:
Raw pickled bytes (decompressed if needed).
- property is_open: bool
Return whether the database connection is open.
- classmethod reset_instance() None
Resets the singleton instance, forcing it to be recreated on next access.
- serialize_data(data: bytes) bytes
Optionally compress raw pickled data before storage.
- Parameters:
data – Raw pickled bytes.
- Returns:
Possibly compressed bytes.
- property storage_path: Path
Storage path for the database.
- connection: Any
- lock: allocate_lock