persistence

package
v0.6.1-0...-39aad92 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2018 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Sqlite3  databaseEngine = 1
	Postgres databaseEngine = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	Engine() databaseEngine
	DoesTorrentExist(infoHash []byte) (bool, error)
	AddNewTorrent(infoHash []byte, name string, files []File) error
	Close() error

	// GetNumberOfTorrents returns the number of torrents saved in the database. Might be an
	// approximation.
	GetNumberOfTorrents() (uint, error)
	GetTotalSizeOfTorrents() (uint64, error)
	// QueryTorrents returns @pageSize amount of torrents,
	// * that are discovered before @discoveredOnBefore
	// * that match the @query if it's not empty, else all torrents
	// * ordered by the @orderBy in ascending order if @ascending is true, else in descending order
	// after skipping (@page * @pageSize) torrents that also fits the criteria above.
	QueryTorrents(
		query string,
		epoch int64,
		orderBy OrderingCriteria,
		ascending bool,
		limit uint,
		lastOrderedValue uint64,
		lastID uint64,
		backward bool,
	) ([]TorrentMetadata, error)
	// GetTorrents returns the TorrentExtMetadata for the torrent of the given InfoHash. Will return
	// nil, nil if the torrent does not exist in the database.
	GetTorrent(infoHash []byte) (*TorrentMetadata, error)
	GetFiles(infoHash []byte) ([]File, error)
	GetStatistics(n uint, from string) (*Statistics, error)
	GenerateStatisticData(from time.Time) error
	GetFirstTorrentDate() (*time.Time, error)
	GetLastTorrentDate() (*time.Time, error)
	GetLatestStatisticsDate() (*time.Time, error)
}

func MakeDatabase

func MakeDatabase(dbURL *url.URL, logger *zap.Logger) (Database, error)

type File

type File struct {
	Size uint64
	Path string
}

type Granularity

type Granularity int
const (
	Year Granularity = iota
	Month
	Week
	Day
	Hour
)

func ParseISO8601

func ParseISO8601(s string) (*time.Time, Granularity, error)

ParseISO8601 is **not** a function to parse all and every kind of valid ISO 8601 date, nor it's intended to be, since we don't need that.

type OrderingCriteria

type OrderingCriteria uint8
const (
	ByRelevance OrderingCriteria = iota
	BySize
	ByDiscoveredOn
	ByNFiles
	ByNSeeders
	ByNLeechers
)

type Statistics

type Statistics struct {
	N uint

	// All these slices below have the exact length equal to the Period.
	NTorrents []uint64
	NFiles    []uint64
	TotalSize []uint64
}

type TorrentMetadata

type TorrentMetadata struct {
	InfoHash     []byte
	Name         string
	Size         uint64
	DiscoveredOn int64
	NFiles       uint
	ID           uint
}

Jump to

Keyboard shortcuts

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