sqlitedb

package
v0.34.1 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultDBPath    = ".e-dnevnik.db"
	DefaultEntryTTL  = time.Hour * 9000 // a bit more than 1 year TTL
	DefaultDBOptions = "?_pragma=journal_mode(WAL)&_pragma=synchronous(NORMAL)&_pragma=busy_timeout(8000)"
)

Variables

View Source
var (
	ErrSqliteOpen        = errors.New("could not open Sqlite database")
	ErrSqliteCreateTable = errors.New("could not create table")
	ErrDeleteBadgerDB    = errors.New("could not remove old BadgerDB directory, please delete manually")
)
View Source
var (
	ErrBadgerDBNotFound = errors.New("BadgerDB not found")
	ErrBadgerDBOpen     = errors.New("failed to open BadgerDB")
	ErrSqliteTx         = errors.New("failed to begin sqlite transaction")
	ErrSqlitePrepare    = errors.New("failed to prepare statement")
	ErrSqliteImport     = errors.New("import failed")
	ErrSqliteCommit     = errors.New("failed to commit transaction")
)

Functions

This section is empty.

Types

type Edb

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

Edb holds e-dnevnik structure including sql.DB struct.

func New

func New(ctx context.Context, filePath string) (*Edb, error)

New opens a new database, flagging if the database already preexisting.

func (*Edb) CheckAndFlagTTL

func (db *Edb) CheckAndFlagTTL(ctx context.Context, bucket, subBucket string, target []string) (bool, error)

CheckAndFlagTTL reports whether (bucket, subBucket, target) was already seen, flagging it with a 1+ year TTL if not. Returns true for an existing live key.

Runs under BEGIN IMMEDIATE on a dedicated conn (BeginTx's BEGIN DEFERRED would race the SELECT) so two callers can't both flag the same key.

A missing current-format key falls back to the legacy separator-less hash: a live legacy hit counts as seen and is re-flagged under the current key, letting the old row age out. This dual lookup stops an upgrade from re-alerting every historical event.

func (*Edb) Close

func (db *Edb) Close() error

Close closes database.

func (*Edb) Delete added in v0.34.0

func (db *Edb) Delete(ctx context.Context, key []byte) error

Delete removes a key. Deleting a non-existent key is a no-op, not an error.

func (*Edb) Existing

func (db *Edb) Existing() bool

Existing returns if the database was freshly initialized.

func (*Edb) FetchAndStore

func (db *Edb) FetchAndStore(ctx context.Context, key []byte, f func(old []byte) ([]byte, error)) error

FetchAndStore atomically reads key, passes the value to f, and writes f's result back (empty result deletes the row). The read-modify-write runs under BEGIN IMMEDIATE on a dedicated conn — BeginTx's BEGIN DEFERRED would leave the SELECT racing other writers — so concurrent callers on the same key cannot lose each other's updates. Queue rows carry no TTL.

func (*Edb) ImportFromBadger

func (db *Edb) ImportFromBadger(ctx context.Context, badgerPath string) error

ImportFromBadger imports all data from a BadgerDB database into the current Edb.

func (*Edb) Put added in v0.34.0

func (db *Edb) Put(ctx context.Context, key, value []byte) error

Put stores a key/value pair with no TTL (expires_at NULL), replacing any existing row. Queue rows use this: they must never expire via the TTL cleanup pass — queue aging is handled at fetch time by MaxQueueAge.

func (*Edb) ScanPrefix added in v0.34.0

func (db *Edb) ScanPrefix(ctx context.Context, prefix []byte) ([]KV, error)

ScanPrefix returns all rows whose key starts with prefix, ordered by key ascending. The upper bound is computed by incrementing the last prefix byte; a prefix ending in a run of 0xFF bytes falls back to a full ordered scan filtered client-side (never the case for our queue prefixes, which end in a 0x00 separator).

type KV added in v0.34.0

type KV struct {
	Key   []byte
	Value []byte
}

KV is a single key/value row returned by ScanPrefix.

Jump to

Keyboard shortcuts

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