storage

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	ID          string
	RuleID      string
	Fingerprint string
	TxHash      string
	PayloadJSON string
	CreatedAt   time.Time
}

Alert represents an emitted alert record.

type Send

type Send struct {
	AlertID      string
	SinkID       string
	Status       string
	ResponseCode int
	CreatedAt    time.Time
}

Send represents a sink delivery record.

type Store

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

Store wraps SQLite-backed persistence for cursors, alerts, sends, and dedupe.

func Open

func Open(path string) (*Store, error)

Open initializes a SQLite database and runs minimal schema setup.

func (*Store) Close

func (s *Store) Close() error

Close releases the underlying database handle.

func (*Store) GetCursor

func (s *Store) GetCursor(ctx context.Context, sourceID string) (height uint64, hash string, ok bool, err error)

GetCursor retrieves the cursor for a source.

func (*Store) InsertAlert

func (s *Store) InsertAlert(ctx context.Context, a Alert) error

InsertAlert stores an alert; primary key enforces exactly-once insertion.

func (*Store) InsertSend

func (s *Store) InsertSend(ctx context.Context, srec Send) error

InsertSend records a sink delivery attempt; primary key enforces exactly-once per alert/sink.

func (*Store) IsDuplicate

func (s *Store) IsDuplicate(ctx context.Context, key string, now time.Time) (bool, error)

IsDuplicate returns true if the key exists and is not expired; expired entries are pruned.

func (*Store) MarkDedupe

func (s *Store) MarkDedupe(ctx context.Context, key string, expiresAt time.Time) error

MarkDedupe sets or refreshes a dedupe key until expiresAt.

func (*Store) Ping

func (s *Store) Ping(ctx context.Context) error

Ping checks database connectivity.

func (*Store) UpsertCursor

func (s *Store) UpsertCursor(ctx context.Context, sourceID string, height uint64, hash string) error

UpsertCursor records the latest processed height/hash for a source.

func (*Store) WithTx

func (s *Store) WithTx(ctx context.Context, fn func(tx *sql.Tx) error) error

WithTx executes a callback inside a transaction for callers needing atomicity.

Jump to

Keyboard shortcuts

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