persistence

package
v0.0.0-...-9d1b2fd Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The maximum number of torrents to return in a single page.
	MaxResults = 15
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

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

func NewSqlite3Database

func NewSqlite3Database(filename string) (*Database, error)

func (*Database) AddNewTorrent

func (db *Database) AddNewTorrent(infoHash []byte, name string, files []File) error

func (*Database) Close

func (db *Database) Close() error

func (*Database) DoesTorrentExist

func (db *Database) DoesTorrentExist(infoHash []byte) (bool, error)

func (*Database) GetFiles

func (db *Database) GetFiles(infoHash []byte) ([]File, error)

func (*Database) GetNumberOfTorrents

func (db *Database) GetNumberOfTorrents(ctx context.Context) (int, error)

Returns an approximate number of torrents in the database.

func (*Database) GetTorrent

func (db *Database) GetTorrent(infoHash []byte) (*TorrentMetadata, error)

func (*Database) QueryTorrents

func (db *Database) QueryTorrents(
	query string,
	orderBy OrderingCriteria,
	ascending bool,
	offset int,
) ([]TorrentMetadata, error)

func (*Database) QueryTorrentsCount

func (db *Database) QueryTorrentsCount(
	ctx context.Context,
	query string,
) (int, error)

type File

type File struct {
	Size int64  `json:"size"`
	Path string `json:"path"`
}

type OrderingCriteria

type OrderingCriteria uint8
const (
	ByRelevance OrderingCriteria = iota
	ByName
	ByTotalSize
	ByDiscovered
	ByNFiles
	ByUpdatedOn
)

type TorrentMetadata

type TorrentMetadata struct {
	ID        uint64  `json:"id"`
	InfoHash  []byte  `json:"infoHash"` // marshalled differently
	Name      string  `json:"name"`
	Size      uint64  `json:"size"`
	CreatedAt int64   `json:"createdAt"`
	UpdatedAt int64   `json:"updatedAt"`
	NFiles    uint    `json:"nFiles"`
	Relevance float64 `json:"relevance"`
}

Jump to

Keyboard shortcuts

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