database

package
v0.0.10 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned if record is not found in the database.
	ErrNotFound = errors.New("not found")

	// ErrAlreadyExists is returned if record insertion failed due to uniqueness constraint.
	ErrAlreadyExists = errors.New("error already exists")
)

Functions

This section is empty.

Types

type DB

type DB struct {
	*sql.DB
	// contains filtered or unexported fields
}

DB is the main database wrapping *sql.DB and have functions that can operate on nar and narinfos.

func Open

func Open(logger log15.Logger, dbpath string) (*DB, error)

Open opens a sqlite3 database, and creates it if necessary.

func (*DB) DeleteNarInfoRecord added in v0.0.10

func (db *DB) DeleteNarInfoRecord(tx *sql.Tx, hash string) error

DeleteNarInfoRecord deletes the narinfo record.

func (*DB) DeleteNarRecord added in v0.0.10

func (db *DB) DeleteNarRecord(tx *sql.Tx, hash string) error

DeleteNarInfoRecord deletes the narinfo record.

func (*DB) GetNarInfoRecord added in v0.0.6

func (db *DB) GetNarInfoRecord(tx *sql.Tx, hash string) (NarInfoModel, error)

func (*DB) GetNarRecord added in v0.0.6

func (db *DB) GetNarRecord(tx *sql.Tx, hash string) (NarModel, error)

func (*DB) InsertNarInfoRecord

func (db *DB) InsertNarInfoRecord(tx *sql.Tx, hash string) (sql.Result, error)

InsertNarInfoRecord creates a new narinfo record in the database.

func (*DB) InsertNarRecord

func (db *DB) InsertNarRecord(tx *sql.Tx, narInfoID int64,
	hash, compression string, fileSize uint64,
) (sql.Result, error)

InsertNarRecord creates a new nar record in the database.

func (*DB) TouchNarInfoRecord

func (db *DB) TouchNarInfoRecord(tx *sql.Tx, hash string) (sql.Result, error)

TouchNarInfoRecord updates the last_accessed_at of a narinfo record in the database.

func (*DB) TouchNarRecord

func (db *DB) TouchNarRecord(tx *sql.Tx, hash string) (sql.Result, error)

type NarInfoModel

type NarInfoModel struct {
	ID   int64
	Hash string

	CreatedAt      time.Time
	UpdatedAt      *time.Time
	LastAccessedAt time.Time
}

NarInfoModel represents a narinfo record in the database; This is not the same as narinfo.NarInfo!

type NarModel

type NarModel struct {
	ID          int64
	NarInfoID   int64
	Hash        string
	Compression string
	FileSize    uint64

	CreatedAt      time.Time
	UpdatedAt      *time.Time
	LastAccessedAt time.Time
}

NarModel represents a nar record in the database.

Jump to

Keyboard shortcuts

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