fleche.storage.sql
Attributes
Classes
SQLAlchemy-backed CallStorage with JSON metadata and DB-backed expand(). |
Functions
|
|
|
Module Contents
- class fleche.storage.sql.Sql[source]
Bases:
fleche.storage.base.CallStorageSQLAlchemy-backed CallStorage with JSON metadata and DB-backed expand().
- _save(call: fleche.call.Call) fleche.digest.Digest[source]
- _load(key: str) fleche.call.Call[source]
- _contains(key: fleche.digest.Digest) bool[source]
- list() Iterable[fleche.digest.Digest][source]
- expand(key: fleche.digest.Digest | str) fleche.digest.Digest[source]
Expands a short-hand digest to the full length one.
- _normalize_value(v: Any) str[source]
Return the stored form used in SQL for argument/result matching.
We must match the generic CallStorage.query semantics which compare digest(template_value) == digest(stored_call_value). In this backend, stored argument/result values are hex-digest strings, and digest(Digest(x)) == x. Therefore we should always compare Arg.value/CallModel.result to str(digest(template_value)).
- _build_call_conditions(template: fleche.call.QueryCall) List[Any][source]
- query(template: fleche.call.QueryCall) Iterable[fleche.call.Call][source]
Find cached calls matching a template using SQL-side filtering.
Semantics match CallStorage.query: - Fields set to None are wildcards. - Arguments and result are compared by digest(template_value) == digest(stored_value). - Metadata can be filtered by providing template.metadata as a mapping of
metadata name -> dict of key/value filters. An empty dict for a given name means “presence of that metadata name”. Filters with simple types (str, bool, int, float) are pushed down to SQL via JSON-extract expressions; other types (e.g., lists) or None values fall back to client-side checks after loading.
This method builds a SELECT over calls, joining the arguments table and metadata table as needed to reduce candidate rows, then loads the resulting calls and performs any remaining client-side validation.
- Parameters:
template – A Call used as a template. None-valued fields are wildcards.
- Yields:
Call – Matching calls including their decoded metadata.