"""SQLite implementation of immutable evidence object storage.""" import sqlite3 from pathlib import Path class SqliteArtifactRepository: def __init__(self, path): self.path = Path(path) self.path.parent.mkdir(parents=True, exist_ok=True) with sqlite3.connect(self.path) as db: db.execute('CREATE TABLE IF NOT EXISTS artifacts(tenant TEXT,run_id TEXT,digest TEXT,body TEXT,PRIMARY KEY(tenant,run_id,digest))') def put(self, tenant, run_id, key, body): with sqlite3.connect(self.path) as db: db.execute('INSERT OR IGNORE INTO artifacts VALUES(?,?,?,?)', (tenant, run_id, key, body)) def get(self, tenant, run_id, key): with sqlite3.connect(self.path) as db: row = db.execute('SELECT body FROM artifacts WHERE tenant=? AND run_id=? AND digest=?', (tenant, run_id, key)).fetchone() return row[0] if row else None