storage

package
v2.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CoreMigrations embed.FS

Functions

func DeleteAttachmentRows

func DeleteAttachmentRows(ctx context.Context, db *sql.DB, table string, eventUUIDs []string) error

DeleteAttachmentRows removes the rows of an attachments table (columns event_uuid, …) that belong to the given events. Modules call it from OnEventsDeleted; the files themselves are removed by AttachmentStore.

func Open

func Open(dsn string) (*sql.DB, error)

Open creates a new SQLite database connection with a single connection.

func OpenPooled

func OpenPooled(dsn string, maxOpen int) (*sql.DB, error)

OpenPooled opens the database with a pool of maxOpen connections.

A single connection is only required for writing: in WAL mode readers block neither the writer nor each other, while one shared connection turns every heavy SELECT into a queue for ingestion — the UI and the incoming events wait for each other.

There is one correctness requirement: WAL still allows a single writer, so with maxOpen > 1 the DSN needs busy_timeout, otherwise a second write fails with SQLITE_BUSY instead of waiting. Both that and _txlock=immediate are added when absent.

Types

type AttachmentStore

type AttachmentStore struct {
	// contains filtered or unexported fields
}

AttachmentStore provides file storage for attachments. Supports in-memory (default) and filesystem modes.

func NewAttachmentStore

func NewAttachmentStore(mode, dir string) *AttachmentStore

NewAttachmentStore creates an attachment store. mode: "memory" (default) or "filesystem" dir: base directory for filesystem mode (ignored for memory)

func (*AttachmentStore) DeleteByEvent

func (s *AttachmentStore) DeleteByEvent(eventUUID string)

DeleteByEvent removes all files for an event. An empty UUID or one that is not a single path element is ignored, so a bad value can never remove the base directory or a path outside it.

func (*AttachmentStore) Get

func (s *AttachmentStore) Get(path string) ([]byte, error)

Get retrieves attachment content.

func (*AttachmentStore) GetReader

func (s *AttachmentStore) GetReader(path string) (io.ReadCloser, error)

GetReader returns a reader for the attachment.

func (*AttachmentStore) Store

func (s *AttachmentStore) Store(path string, content []byte) error

Store saves attachment content. path format: "{eventUUID}/{filename}"

type Migration

type Migration struct {
	Name    string // e.g., "2024_01_01_000000_create_events_table.sql"
	Module  string // e.g., "core", "profiler"
	Content string
}

Migration represents a single SQL migration file.

type Migrator

type Migrator struct {
	// contains filtered or unexported fields
}

Migrator collects and runs SQL migrations from all modules.

func NewMigrator

func NewMigrator(db *sql.DB) *Migrator

func (*Migrator) AddFromFS

func (m *Migrator) AddFromFS(moduleName string, fsys embed.FS, dir string) error

AddFromFS registers all .sql files from an embedded filesystem. Files are expected to be named like: 2024_01_01_000000_description.sql

func (*Migrator) AddSQL

func (m *Migrator) AddSQL(moduleName, name, content string)

AddSQL registers a raw SQL migration with a given name and module.

func (*Migrator) Run

func (m *Migrator) Run() error

Run executes all collected migrations sorted by filename. Uses a migrations tracking table to avoid re-running.

type SQLiteStore

type SQLiteStore struct {
	// contains filtered or unexported fields
}

SQLiteStore implements event.Store using SQLite.

func NewSQLiteStore

func NewSQLiteStore(db *sql.DB) *SQLiteStore

func (*SQLiteStore) Delete

func (s *SQLiteStore) Delete(ctx context.Context, uuid string) error

func (*SQLiteStore) DeleteAll

func (s *SQLiteStore) DeleteAll(ctx context.Context, opts event.DeleteOptions) error

func (*SQLiteStore) FindAll

func (s *SQLiteStore) FindAll(ctx context.Context, opts event.FindOptions) ([]event.Event, error)

func (*SQLiteStore) FindByUUID

func (s *SQLiteStore) FindByUUID(ctx context.Context, uuid string) (*event.Event, error)

func (*SQLiteStore) OnDelete

func (s *SQLiteStore) OnDelete(fn func(uuids []string))

OnDelete registers fn to run after Delete or DeleteAll removed events. fn gets the UUIDs of the removed rows, so files kept outside SQLite (attachments, trace files) can be removed with them. Register hooks at startup, before the store is used.

func (*SQLiteStore) Pin

func (s *SQLiteStore) Pin(ctx context.Context, uuid string) error

func (*SQLiteStore) Store

func (s *SQLiteStore) Store(ctx context.Context, ev event.Event) error

func (*SQLiteStore) Unpin

func (s *SQLiteStore) Unpin(ctx context.Context, uuid string) error

func (*SQLiteStore) UpdatePayload

func (s *SQLiteStore) UpdatePayload(ctx context.Context, uuid string, payload json.RawMessage) error

Jump to

Keyboard shortcuts

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