sqlitedb

package
v0.32.6 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 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")
	ErrSqlitePrepareCheck  = errors.New("failed to prepare check key statement")
	ErrSqlitePrepareInsert = errors.New("failed to prepare insert key statement")
	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 checks if a key already exists in the database and marks it with a flag if it doesn't exist. The flag is set with a TTL of 1+ year.

The key is created by hashing a concatenation of the bucket, subBucket and target strings using SHA-256.

If the key already exists, the function returns (true, nil). If the key doesn't exist, the function marks the key and returns (false, nil) on success or (false, error) on error.

func (*Edb) Close

func (db *Edb) Close() error

Close closes database.

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 fetches a value by key, applies a given function to the value and stores the result.

It does the following steps:

1. Finds the key in the database. 2. Copies the associated value. 3. Calls the given function with the copied value as argument and stores the result. 4. Stores the result in the database with the same key and a TTL of 1+ year.

If any of the steps fail, it will return an error.

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.

Jump to

Keyboard shortcuts

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