Documentation
¶
Index ¶
- Constants
- Variables
- type Edb
- func (db *Edb) CheckAndFlagTTL(ctx context.Context, bucket, subBucket string, target []string) (bool, error)
- func (db *Edb) Close() error
- func (db *Edb) Delete(ctx context.Context, key []byte) error
- func (db *Edb) Existing() bool
- func (db *Edb) FetchAndStore(ctx context.Context, key []byte, f func(old []byte) ([]byte, error)) error
- func (db *Edb) ImportFromBadger(ctx context.Context, badgerPath string) error
- func (db *Edb) Put(ctx context.Context, key, value []byte) error
- func (db *Edb) ScanPrefix(ctx context.Context, prefix []byte) ([]KV, error)
- type KV
Constants ¶
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 ¶
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") )
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 (*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) Delete ¶ added in v0.34.0
Delete removes a key. Deleting a non-existent key is a no-op, not an error.
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 ¶
ImportFromBadger imports all data from a BadgerDB database into the current Edb.
func (*Edb) Put ¶ added in v0.34.0
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
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).