fleche.storage.sql

Attributes

Base

SQLITE_FOREIGN_KEYS_ON

Classes

Sql

SQLAlchemy-backed CallStorage with JSON metadata and DB-backed expand().

Functions

_coerce_sqlite_url(→ str)

_enable_sqlite_foreign_keys(→ None)

Module Contents

fleche.storage.sql.Base[source]
fleche.storage.sql._coerce_sqlite_url(path_or_url: str | None) str[source]
fleche.storage.sql.SQLITE_FOREIGN_KEYS_ON = 'PRAGMA foreign_keys=ON'[source]
fleche.storage.sql._enable_sqlite_foreign_keys(engine) None[source]
class fleche.storage.sql.Sql[source]

Bases: fleche.storage.base.CallStorage

SQLAlchemy-backed CallStorage with JSON metadata and DB-backed expand().

url: str | None = None[source]
echo: bool = False[source]
engine: Any[source]
session: Any[source]
__post_init__() None[source]
__getstate__()[source]
__setstate__(state)[source]
_save(call: fleche.call.Call) fleche.digest.Digest[source]
_load(key: fleche.digest.Digest) 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.

_evict(key: fleche.digest.Digest) None[source]
_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]
_apply_argument_filters(stmt: Any, arguments: dict[str, Any] | None) Any[source]
_apply_metadata_filters(stmt: Any, meta_specs: dict[str, dict[str, Any]] | None) 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.