sqlite

package
v0.49.1 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB is an implementation of fab.HashDB that uses a Sqlite3 file for persistent storage.

func Open

func Open(path string, opts ...Option) (*DB, error)

Open opens the given file and returns it as a *DB. The file is created if it doesn't already exist. Callers should call Close when finished operating on the database.

func (*DB) Add

func (db *DB) Add(ctx context.Context, h []byte) error

Add adds a hash to db. If it is already present, its last-access time is updated. If db was opened with the Keep option, entries with old last-access times are evicted.

func (*DB) Close

func (db *DB) Close() error

Close releases the resources of s.

func (*DB) Has

func (db *DB) Has(ctx context.Context, h []byte) (bool, error)

Has tells whether db contains the given hash. If found, it also updates the last-access time of the hash.

type Option

type Option func(*DB)

Option is the type of a config option that can be passed to Open.

func Keep

func Keep(d time.Duration) Option

Keep is an Option that sets the amount of time to keep a database entry. By default, DB keeps all entries. Using Keep(d) allows DB to evict entries whose last-access time is older than d.

func UpdateOnAccess added in v0.7.0

func UpdateOnAccess(update bool) Option

UpdateOnAccess is an Option controlling whether to update a db entry's timestamp when accessed with Has. The default is true: each Has of a value refreshes its timestamp to prevent its expiration.

func WithClock added in v0.7.0

func WithClock(clk clock.Clock) Option

WithClock is an Option that sets the database's clock. By default it's clock.New(), i.e. the normal time-telling clock. For testing this can be set to a mock clock.

Jump to

Keyboard shortcuts

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