Metadata-Version: 2.5
Name: glyff-sqlite
Version: 0.14.0
Summary: SQLite-backed durable execution backend for glyff.
License: MIT License
        
        Copyright (c) 2026 nueruyu
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: AsyncIO
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: glyff>=0.14.0
Description-Content-Type: text/markdown

# glyff-sqlite

SQLite-backed durable `ExecutionRepository` implementation for
[glyff](https://pypi.org/project/glyff/).

This is the **production** backend: one row per execution in a SQLite
`glyff_executions` table, WAL mode, indexed lookups, and native transaction
atomicity. Execution `result` and `metadata` columns are stored as readable JSON
text, so serializers used with this backend must produce JSON text.

`table_prefix` (default `glyff`) names the two tables the store owns:
`<prefix>_executions` and `<prefix>_meta`, which records the format version so a
store written by an incompatible build is refused. Pass `table_prefix=` to
cohabit an application's own database; `PRAGMA user_version` is left to the
application.

## Install

```bash
pip install glyff-sqlite
```

This package depends on `glyff>=0.14.0` (no additional runtime dependencies —
`sqlite3` is part of the standard library).

## Usage

```python
from glyff_sqlite import SQLiteBackend

backend = SQLiteBackend("executions.sqlite3")
```

## Public API

| Name                        | Description                                          |
| --------------------------- | ---------------------------------------------------- |
| `SQLiteBackend`             | Bundle exposing the store's collaborators.           |
| `SQLiteExecutionRepository` | Durable repository backed by local SQLite.           |
| `SQLiteTransactionProvider` | Transaction provider for the SQLite backend.         |

The underlying `SQLiteClient` is internal and not part of the public API.

## Storage model

- One row per execution; `arguments`, `result` and `metadata` are JSON text
  columns, readable in place with any SQLite client.
- `arguments` holds the canonical arguments verbatim — the row's key is their
  digest, so the column is stored and returned byte-for-byte rather than
  re-encoded.
- Records are keyed by `(session_id, path)`; a `<prefix>_session_domains` row
  carries the version one session claimed for one domain, and a single
  `<prefix>_meta` row the store's format version.
- Per-execution metadata (see the
  [glyff README](https://pypi.org/project/glyff/)) commits atomically with the
  execution's `COMPLETED` status and result, and is removed with the execution's
  row when the record is deleted.

## Transaction model

- Enumeration streams the range scan a batch of rows at a time, so a sweep over
  a large table costs bounded memory.
- Writes are staged in-memory per transaction and flushed on commit.
- Nested transactions (child scopes) commit independently of their parent.
- `BEGIN IMMEDIATE` prevents writer contention; WAL mode keeps reads fast. A
  session's version for a domain is claimed inside one, so workers racing to
  resume the same session agree on a single winner.
- A per-database asyncio write lock serialises concurrent write transactions.

## Planned

- **Store migrations** — nothing yet converts a store from one format version to
  the next ([#41](https://github.com/nueruyu/glyff/issues/41)).
- **External transaction enlistment** — running inside an application's own
  connection ([#42](https://github.com/nueruyu/glyff/issues/42)).

## Status

Pre-1.0 — the API is unstable and will change.

## License

MIT
