Spaces:
Sleeping
Sleeping
File size: 910 Bytes
caf8059 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | """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
|