Documentation
¶
Index ¶
- type RecordFilter
- type Storage
- func (s *Storage) AdvanceResumeOffset(ctx context.Context, identityHash string, resumeOffset int64) error
- func (s *Storage) Close() error
- func (s *Storage) CompleteFileParse(ctx context.Context, identityHash string, completedSize int64, mtime time.Time, ...) error
- func (s *Storage) CreateFileGeneration(ctx context.Context, state *models.FileState) error
- func (s *Storage) CreateSlowLogIndexes() error
- func (s *Storage) DB() *sql.DB
- func (s *Storage) DedupeSlowLogs(ctx context.Context) error
- func (s *Storage) DropSlowLogIndexes() error
- func (s *Storage) FilterOptions(ctx context.Context) (users, dbs, hosts, tables, sourceHosts []string, err error)
- func (s *Storage) FilterRecords(ctx context.Context, f RecordFilter, orderBy, orderDir string, ...) (*models.ReportResult, error)
- func (s *Storage) FinalizeIngestion(ctx context.Context) error
- func (s *Storage) GetFileStats(ctx context.Context) (map[string]interface{}, error)
- func (s *Storage) GetLatestFileState(ctx context.Context, canonicalPath string) (*models.FileState, error)
- func (s *Storage) GetRecordByID(ctx context.Context, id int64) (*models.ReportResult, error)
- func (s *Storage) GetStats(ctx context.Context) (map[string]interface{}, error)
- func (s *Storage) InsertSlowLogBatch(ctx context.Context, entries []*models.SlowLogEntry, fileHash string) error
- func (s *Storage) ListRecords(ctx context.Context, orderBy, orderDir string, limit, offset int) (*models.ReportResult, error)
- func (s *Storage) Query(ctx context.Context, query string, args ...interface{}) (*models.ReportResult, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RecordFilter ¶
type RecordFilter struct {
Users, Hosts, DBs, Tables, SourceHosts []string
FingerprintID string
QueryTimeGT, QueryTimeLT *float64
LockTimeGT, LockTimeLT *float64
RowsExaminedGT *int64
TSFrom, TSTo *time.Time
FilePath string
}
RecordFilter holds validated record filters (nil pointer = filter absent).
func (RecordFilter) BuildWhere ¶
func (f RecordFilter) BuildWhere() (string, []interface{})
BuildWhere renders f as a parameterized "WHERE ..." clause (or "" when empty) plus its bound args, in statement order. Exported so downstream consumers reuse this one SQLi-safe filter implementation: every value is bound as a `?` placeholder instead of being spliced into the SQL text.
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage handles DuckDB operations
func NewStorage ¶
NewStorage creates a new Storage instance When readOnly is true, opens the database in read-only mode (no writes allowed) When readOnly is false, opens with read-write access and initializes schema
func (*Storage) AdvanceResumeOffset ¶
func (s *Storage) AdvanceResumeOffset(ctx context.Context, identityHash string, resumeOffset int64) error
AdvanceResumeOffset sets resume_offset = MAX(resume_offset, ?) after a durable insert [L12].
func (*Storage) CompleteFileParse ¶
func (s *Storage) CompleteFileParse(ctx context.Context, identityHash string, completedSize int64, mtime time.Time, tailHash string, tailLen int64) error
CompleteFileParse records successful completion of a full/incremental parse run.
func (*Storage) CreateFileGeneration ¶
CreateFileGeneration inserts a new generation row (prefix frozen, offsets 0) [L5].
func (*Storage) CreateSlowLogIndexes ¶
CreateSlowLogIndexes creates all indexes on slow_logs. Safe to call repeatedly (uses IF NOT EXISTS).
func (*Storage) DedupeSlowLogs ¶
DedupeSlowLogs keeps MAX(id) per (file_hash, event_offset); NULL-safe [R2-3].
func (*Storage) DropSlowLogIndexes ¶
DropSlowLogIndexes drops all indexes on slow_logs for faster bulk inserts.
func (*Storage) FilterOptions ¶
func (s *Storage) FilterOptions(ctx context.Context) (users, dbs, hosts, tables, sourceHosts []string, err error)
FilterOptions returns distinct users/dbs/hosts/tables/source_hosts. These queries take no user input (static DISTINCT scans), so no parameterization is needed.
func (*Storage) FilterRecords ¶
func (s *Storage) FilterRecords(ctx context.Context, f RecordFilter, orderBy, orderDir string, limit, offset int) (*models.ReportResult, error)
FilterRecords returns individual (ungrouped) filtered rows, ordered by an allow-listed column/dir, paginated. Grouped aggregations are not provided here (a downstream consumer composes BuildWhere with its own templates). The WHERE clause is f.BuildWhere()'s parameterized output, and LIMIT/OFFSET are bound as `?` ints appended after the WHERE args (never interpolated).
func (*Storage) FinalizeIngestion ¶
FinalizeIngestion runs post-ingest maintenance: dedupe+repair then indexes [D6].
func (*Storage) GetFileStats ¶
GetFileStats returns statistics about recorded files [L16].
func (*Storage) GetLatestFileState ¶
func (s *Storage) GetLatestFileState(ctx context.Context, canonicalPath string) (*models.FileState, error)
GetLatestFileState returns the newest generation row for canonicalPath, or nil if unseen.
func (*Storage) GetRecordByID ¶
GetRecordByID returns the single full row for a numeric id, or Count==0 if absent. `WHERE id = ?` binds id as an int64 — no string value can ever reach this clause.
func (*Storage) InsertSlowLogBatch ¶
func (s *Storage) InsertSlowLogBatch(ctx context.Context, entries []*models.SlowLogEntry, fileHash string) error
InsertSlowLogBatch inserts multiple slow log entries using the DuckDB Appender API. Appender writes full rows in table column order [L9].
func (*Storage) ListRecords ¶
func (s *Storage) ListRecords(ctx context.Context, orderBy, orderDir string, limit, offset int) (*models.ReportResult, error)
ListRecords returns individual slow-log rows (preview columns), ordered by an allow-listed column/dir, paginated. orderBy outside the allow-list falls back to "id". LIMIT/OFFSET are bound as `?` ints (never string-interpolated).