Files
photocli/internal/manifest/sqlite/log_writer.go
T
Ein Anderssono c9ac014473
pipeline / test (push) Has been cancelled
pipeline / build (push) Has been cancelled
v0.10.0: ports and adapters refactor
- Extract shared manifest types into internal/manifest/types leaf package.
- Extract SQLite adapter into internal/manifest/sqlite.
- Extract JSONL adapter into internal/manifest/jsonl.
- Isolate modernc.org/sqlite import to sqlite/adapter.go.
- Add adapter-backed registry with manifest.Default.
- Adapter-agnostic ConvertManifest in types/.
- MemoryAdapter for in-memory manifest testing.
- CLI uses manifest.Default registry directly.
- SQLite LogWriter type assertion moved into SQLiteAdapter.
- Manifest interface includes Entries(); EntryReader removed.
- No behavior changes. 100% coverage across all 6 packages.
2026-06-15 08:27:38 +02:00

44 lines
1.0 KiB
Go

package sqlite
import (
"database/sql"
"gitea.k3s.k0.nu/tools/photocli/internal/manifest/types"
)
type LogWriter struct {
db *sql.DB
}
func NewLogWriter(db *sql.DB) (types.LogWriter, error) {
_, err := db.Exec(`CREATE TABLE IF NOT EXISTS logs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
ts INTEGER NOT NULL,
level TEXT NOT NULL,
event TEXT NOT NULL,
asset_id TEXT,
album TEXT,
filename TEXT,
size INTEGER,
cloud TEXT,
duration_ms INTEGER,
message TEXT
)`)
if err != nil {
return nil, err
}
_, _ = db.Exec(`CREATE INDEX IF NOT EXISTS idx_logs_ts ON logs(ts)`)
_, _ = db.Exec(`CREATE INDEX IF NOT EXISTS idx_logs_event ON logs(event)`)
return &LogWriter{db: db}, nil
}
func (w *LogWriter) Log(e types.LogEntry) {
if w.db == nil {
return
}
w.db.Exec(`INSERT INTO logs (ts, level, event, asset_id, album, filename, size, cloud, duration_ms, message) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
e.Timestamp, e.Level, e.Event, e.AssetID, e.Album, e.Filename, e.Size, e.Cloud, e.DurationMs, e.Message)
}
func (w *LogWriter) Close() { _ = w }