On this page
API reference for the db package — SQLite database tracking all saferm deletions with WAL mode and busy_timeout for concurrency safety.
#internal/db
#internal/db
Package db manages the SQLite database tracking all saferm deletions. It uses WAL mode and busy_timeout for concurrency safety across multiple simultaneous sessions.
#SchemaSQL
const SchemaSQL = `#ErrNotFound
var ErrNotFound = errors.New("record not found")ErrNotFound is returned when a queried record does not exist.
#DB
type DB structDB wraps a *sql.DB connection to the saferm SQLite database.
#DeletionRecord
type DeletionRecord structDeletionRecord represents a single archived deletion in the database.
#Open
func Open(dbPath string) (*DB, error)Open opens (or creates) the SQLite database at dbPath with WAL mode and busy_timeout=5000ms, then runs the schema DDL.
#DB.Close
func (d *DB) Close() errorClose closes the underlying database connection.
#DB.Insert
func (d *DB) Insert(rec *DeletionRecord) (int64, error)Insert inserts a DeletionRecord and returns the auto-increment ID.
#DB.QueryByID
func (d *DB) QueryByID(id int64) (*DeletionRecord, error)QueryByID retrieves a single record by ID. Returns ErrNotFound if it does not exist.
#DB.QueryByPath
func (d *DB) QueryByPath(path string) ([]*DeletionRecord, error)QueryByPath returns all non-restored records matching the given original_path, ordered by deleted_at DESC (newest first).
#DB.QueryAll
func (d *DB) QueryAll(includeRestored bool) ([]*DeletionRecord, error)QueryAll returns all records ordered by deleted_at DESC. If includeRestored is false, restored records are excluded.
#DB.MarkRestored
func (d *DB) MarkRestored(id int64, restoredTo string) errorMarkRestored sets restored_at to now and restored_to to the given path. Returns ErrNotFound if the record does not exist.
#DB.Delete
func (d *DB) Delete(id int64) errorDelete permanently removes a record by ID (used for purge). Returns ErrNotFound if the record does not exist.
#DB.QueryOlderThan
func (d *DB) QueryOlderThan(before time.Time) ([]*DeletionRecord, error)QueryOlderThan returns all non-restored records deleted before the given time.