storage

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

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

func NewStorage(dsn string, readOnly bool) (*Storage, error)

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) Close

func (s *Storage) Close() error

Close closes the database connection and connector

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

func (s *Storage) CreateFileGeneration(ctx context.Context, state *models.FileState) error

CreateFileGeneration inserts a new generation row (prefix frozen, offsets 0) [L5].

func (*Storage) CreateSlowLogIndexes

func (s *Storage) CreateSlowLogIndexes() error

CreateSlowLogIndexes creates all indexes on slow_logs. Safe to call repeatedly (uses IF NOT EXISTS).

func (*Storage) DB

func (s *Storage) DB() *sql.DB

DB exposes the underlying *sql.DB for tests.

func (*Storage) DedupeSlowLogs

func (s *Storage) DedupeSlowLogs(ctx context.Context) error

DedupeSlowLogs keeps MAX(id) per (file_hash, event_offset); NULL-safe [R2-3].

func (*Storage) DropSlowLogIndexes

func (s *Storage) DropSlowLogIndexes() error

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

func (s *Storage) FinalizeIngestion(ctx context.Context) error

FinalizeIngestion runs post-ingest maintenance: dedupe+repair then indexes [D6].

func (*Storage) GetFileStats

func (s *Storage) GetFileStats(ctx context.Context) (map[string]interface{}, error)

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

func (s *Storage) GetRecordByID(ctx context.Context, id int64) (*models.ReportResult, error)

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) GetStats

func (s *Storage) GetStats(ctx context.Context) (map[string]interface{}, error)

GetStats returns basic statistics about stored slow logs

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).

func (*Storage) Query

func (s *Storage) Query(ctx context.Context, query string, args ...interface{}) (*models.ReportResult, error)

Query executes a raw SQL query (optional bound args) and returns results.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL