db

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Code generated by /packsql.py -- DO NOT EDIT

Index

Constants

View Source
const Q_000_Base = `` /* 2024-byte string literal not displayed */

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when a row does not exist.

Functions

This section is empty.

Types

type Adapter

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

Adapter interfaces with the database.

func EmptyDisk

func EmptyDisk(filename string) (*Adapter, error)

EmptyDisk returns an adapter to a new database, at the given file location, with all tables created.

func EmptyInMemory

func EmptyInMemory() (*Adapter, error)

EmptyInMemory returns an adapter to a new in-memory database with all tables created.

func NewAdapter

func NewAdapter(db *sql.DB) *Adapter

NewAdapter returns a new database adapter.

func (*Adapter) ChunksExist

func (a *Adapter) ChunksExist(sums []sum.Sum) ([]bool, error)

ChunksExist checks if chunks, identified by their checksum, exist in the file store. Returns a bool for each chunk.

func (*Adapter) DeleteFile

func (a *Adapter) DeleteFile(s sum.Sum) error

DeleteFile deletes a file and decrements all chunks referenced by the file by one. Returns ErrNotFound if the file does not exist.

func (*Adapter) DeletePackIndex

func (a *Adapter) DeletePackIndex(sum sum.Sum) error

DeletePackIndex deletes a pack index from the database.

func (*Adapter) GetChunkSize

func (a *Adapter) GetChunkSize(s sum.Sum) (uint64, error)

GetChunkSize gets the size of a chunk. Returns ErrNotFound if the chunk does not exist.

func (*Adapter) GetFile

func (a *Adapter) GetFile(s sum.Sum) (object.File, error)

GetFile returns a File from the database with a given sum. Returns db.ErrNotFound if the file does not exist.

func (*Adapter) GetFileChunks

func (a *Adapter) GetFileChunks(fileID sum.Sum) ([]ChunkIndex, error)

GetFileChunks returns the packfile location of each chunk in a file. Returns ErrNotFound if the file does not exist.

func (*Adapter) GetFileInfo

func (a *Adapter) GetFileInfo(s sum.Sum) (FileInfo, error)

GetFileInfo returns the FileInfo for a given file version. Returns ErrNotFound if the file does not exist.

func (*Adapter) GetFileVersions

func (a *Adapter) GetFileVersions(name string, offset int64, limit uint64, ascending bool) ([]FileInfo, error)

GetFileVersions returns the versions of a file with a given name. Pagination is achieved with the offset and limit parameters.

func (*Adapter) GetLatestFileVersion

func (a *Adapter) GetLatestFileVersion(name string) (FileInfo, error)

GetLatestFileVersion returns the latest version of a file with a given name. Returns db.ErrNotFound if the file does not exist.

func (*Adapter) GetServerStats

func (a *Adapter) GetServerStats() (Stats, error)

GetServerStats returns the Stats for the server.

func (*Adapter) GetVacuum

func (a *Adapter) GetVacuum(id string) (Vacuum, error)

GetVacuum returns the status of a vacuum process with a given ID. Returns db.ErrNotFound if the vacuum does not exist.

func (*Adapter) GetZeroRefcount

func (a *Adapter) GetZeroRefcount(createdBefore time.Time) ([]ZeroRefcount, error)

GetZeroRefcount returns the block sequence numbers in each packfile with a zero refcount.

func (*Adapter) InitSchema

func (a *Adapter) InitSchema() error

InitSchema creates the tables for a new database.

func (*Adapter) InsertFile

func (a *Adapter) InsertFile(file object.File, sum sum.Sum) error

InsertFile saves a File object to the database.

func (*Adapter) InsertPackIndex

func (a *Adapter) InsertPackIndex(index object.PackIndex, createdAt time.Time) error

InsertPackIndex saves a PackIndex to the database.

func (*Adapter) InsertVacuum

func (a *Adapter) InsertVacuum(startedAt time.Time) (string, error)

InsertVacuum inserts a row for a new vacuum. Returns the vacuum ID.

func (*Adapter) ListFiles

func (a *Adapter) ListFiles(prefix string, offset int64, limit uint64, exclude string, include string, ascending bool) ([]FileInfo, error)

ListFiles returns a FileInfo slice containing corresponding to files that match the provided prefix. Glob parametrs exclude and include are used to filter the result. Pagination is achieved using the offset and limit parameters. Results are returned in reverse-chronological order by default. Setting ascending to true reverses the order.

func (*Adapter) UpdateIndex

func (a *Adapter) UpdateIndex(newIndex object.PackIndex, createdAt time.Time, oldIndexSum sum.Sum, m map[uint64]uint64) error

UpdateIndex overwrites the contents of a pack index with a new one. The map m specifies the mapping from the sequence numbers of the new index to the sequence numbers of the old index. Any sequences in the old index which are not re-mapped will be deleted when DeletePackIndex is called on the old index.

func (*Adapter) UpdateVacuum

func (a *Adapter) UpdateVacuum(id string, completedAt time.Time, status VacuumStatus) error

UpdateVacuum updates the status and completed time of a given vacuum.

type ChunkIndex

type ChunkIndex struct {
	Sequence uint64
	PackSum  sum.Sum
	Block    object.BlockInfo
}

ChunkIndex is returned by GetFileChunks.

type FileInfo

type FileInfo struct {
	Name      string
	CreatedAt time.Time
	Size      uint64
	Sum       sum.Sum
	Versioned bool
}

FileInfo stores the metadata associated with a file.

type Stats

type Stats struct {
	NumFiles        uint64
	NumFileVersions uint64
	TotalFilesSize  uint64
	TotalDataSize   uint64
}

Stats store high-level statistics for the server -- number of file, number of file versions, total size in bytes of all files, and total size of data stored.

type Vacuum

type Vacuum struct {
	ID        string
	Status    VacuumStatus
	StartedAt int64
	// Will be zero if Status is VacuumRunning
	CompletedAt int64
}

Vacuum is returned by the GetVacuum method.

type VacuumStatus

type VacuumStatus int

VacuumStatus represents the status of a vacuum process.

const (
	VacuumRunning VacuumStatus = iota
	VacuumOK
	VacuumFailed
)

Vacuum status codes

func (VacuumStatus) String

func (s VacuumStatus) String() string

type ZeroRefcount

type ZeroRefcount struct {
	PackID    sum.Sum
	Sequences []uint64
}

ZeroRefcount is returned by GetZeroRefcount. It stores a pack ID and a sorted sequence of each block in the file with a zero refcount.

Jump to

Keyboard shortcuts

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