database

package
v1.0.1-0...-32d7d0a Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: Unlicense Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultMemConfig = MemConfig{
		Compressed: false,
	}
	DefaultMongoConfig = MongoConfig{
		Host:       "localhost",
		Port:       "27017",
		RetryTimes: 4,
		RetryPause: 5 * time.Second,
		Timeout:    30 * time.Second,
		LRU:        1,
		Compressed: false,
	}
	DefaultBadgerConfig = BadgerConfig{
		InMemory:        true,
		GcRatio:         0,
		CleanupInterval: 0,
		LRU:             1,
		Compressed:      false,
	}
)

Functions

func New

Types

type Badger

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

func NewBadger

func NewBadger(conf BadgerConfig) (*Badger, error)

func (*Badger) AlbumsToBeDeleted

func (b *Badger) AlbumsToBeDeleted(_ context.Context) ([]model.Album, error)

func (*Badger) Close

func (b *Badger) Close(_ context.Context) error

func (*Badger) CountImages

func (b *Badger) CountImages(_ context.Context, album uint64) (int, error)

func (*Badger) CountImagesCompressed

func (b *Badger) CountImagesCompressed(_ context.Context, album uint64) (int, error)

func (*Badger) DeleteAlbum

func (b *Badger) DeleteAlbum(_ context.Context, album uint64) error

func (*Badger) GetEdges

func (b *Badger) GetEdges(_ context.Context, album uint64) (map[uint64]map[uint64]int, error)

func (*Badger) GetImageSrc

func (b *Badger) GetImageSrc(_ context.Context, album uint64, image uint64) (string, error)

func (*Badger) GetImagesIds

func (b *Badger) GetImagesIds(_ context.Context, album uint64) ([]uint64, error)

func (*Badger) GetImagesOrdered

func (b *Badger) GetImagesOrdered(_ context.Context, album uint64) ([]model.Image, error)

func (*Badger) Health

func (b *Badger) Health(_ context.Context) (bool, error)

func (*Badger) Monitor

func (b *Badger) Monitor(ctx context.Context)

func (*Badger) Reset

func (b *Badger) Reset() error

func (*Badger) SaveAlbum

func (b *Badger) SaveAlbum(_ context.Context, alb model.Album) error

func (*Badger) SaveVote

func (b *Badger) SaveVote(_ context.Context, album uint64, imageFrom uint64, imageTo uint64) error

func (*Badger) UpdateCompressionStatus

func (b *Badger) UpdateCompressionStatus(_ context.Context, album uint64, image uint64) error

func (*Badger) UpdateRatings

func (b *Badger) UpdateRatings(_ context.Context, album uint64, vector map[uint64]float64) error

type BadgerConfig

type BadgerConfig struct {
	InMemory        bool          `mapstructure:"DATABASE_BADGER_IN_MEMORY"`
	GcRatio         float64       `mapstructure:"DATABASE_BADGER_GC_RATIO"         validate:"required"`
	CleanupInterval time.Duration `mapstructure:"DATABASE_BADGER_CLEANUP_INTERVAL" validate:"required"`
	LRU             int           `mapstructure:"DATABASE_BADGER_LRU"              validate:"required"`
	Compressed      bool
}

type DatabaseConfig

type DatabaseConfig struct {
	Database string       `mapstructure:"APP_DATABASE" validate:"required"`
	Mem      MemConfig    `mapstructure:",squash"`
	Mongo    MongoConfig  `mapstructure:",squash"`
	Badger   BadgerConfig `mapstructure:",squash"`
}

type Mem

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

func NewMem

func NewMem(conf MemConfig) *Mem

func (*Mem) AlbumsToBeDeleted

func (m *Mem) AlbumsToBeDeleted(_ context.Context) ([]model.Album, error)

func (*Mem) CountImages

func (m *Mem) CountImages(_ context.Context, album uint64) (int, error)

func (*Mem) CountImagesCompressed

func (m *Mem) CountImagesCompressed(_ context.Context, album uint64) (int, error)

func (*Mem) DeleteAlbum

func (m *Mem) DeleteAlbum(_ context.Context, album uint64) error

func (*Mem) GetEdges

func (m *Mem) GetEdges(_ context.Context, album uint64) (map[uint64]map[uint64]int, error)

func (*Mem) GetImageSrc

func (m *Mem) GetImageSrc(_ context.Context, album uint64, image uint64) (string, error)

func (*Mem) GetImagesIds

func (m *Mem) GetImagesIds(_ context.Context, album uint64) ([]uint64, error)

func (*Mem) GetImagesOrdered

func (m *Mem) GetImagesOrdered(_ context.Context, album uint64) ([]model.Image, error)

func (*Mem) Health

func (m *Mem) Health(_ context.Context) (bool, error)

func (*Mem) Reset

func (m *Mem) Reset() error

func (*Mem) SaveAlbum

func (m *Mem) SaveAlbum(_ context.Context, alb model.Album) error

func (*Mem) SaveVote

func (m *Mem) SaveVote(_ context.Context, album uint64, imageFrom uint64, imageTo uint64) error

func (*Mem) UpdateCompressionStatus

func (m *Mem) UpdateCompressionStatus(_ context.Context, album uint64, image uint64) error

func (*Mem) UpdateRatings

func (m *Mem) UpdateRatings(_ context.Context, album uint64, vector map[uint64]float64) error

type MemConfig

type MemConfig struct {
	Compressed bool
}

type Mongo

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

func NewMongo

func NewMongo(ctx context.Context, conf MongoConfig) (*Mongo, error)

func (*Mongo) AlbumsToBeDeleted

func (m *Mongo) AlbumsToBeDeleted(ctx context.Context) ([]model.Album, error)

func (*Mongo) Close

func (m *Mongo) Close(ctx context.Context) error

func (*Mongo) CountImages

func (m *Mongo) CountImages(ctx context.Context, album uint64) (int, error)

func (*Mongo) CountImagesCompressed

func (m *Mongo) CountImagesCompressed(ctx context.Context, album uint64) (int, error)

func (*Mongo) DeleteAlbum

func (m *Mongo) DeleteAlbum(ctx context.Context, album uint64) error

func (*Mongo) GetEdges

func (m *Mongo) GetEdges(ctx context.Context, album uint64) (map[uint64]map[uint64]int, error)

func (*Mongo) GetImageSrc

func (m *Mongo) GetImageSrc(ctx context.Context, album uint64, image uint64) (string, error)

func (*Mongo) GetImagesIds

func (m *Mongo) GetImagesIds(ctx context.Context, album uint64) ([]uint64, error)

func (*Mongo) GetImagesOrdered

func (m *Mongo) GetImagesOrdered(ctx context.Context, album uint64) ([]model.Image, error)

func (*Mongo) Health

func (m *Mongo) Health(ctx context.Context) (bool, error)

func (*Mongo) Reset

func (m *Mongo) Reset() error

func (*Mongo) SaveAlbum

func (m *Mongo) SaveAlbum(ctx context.Context, alb model.Album) error

func (*Mongo) SaveVote

func (m *Mongo) SaveVote(ctx context.Context, album uint64, imageFrom uint64, imageTo uint64) error

func (*Mongo) UpdateCompressionStatus

func (m *Mongo) UpdateCompressionStatus(ctx context.Context, album uint64, image uint64) error

func (*Mongo) UpdateRatings

func (m *Mongo) UpdateRatings(ctx context.Context, album uint64, vector map[uint64]float64) error

type MongoConfig

type MongoConfig struct {
	Host       string        `mapstructure:"DATABASE_MONGO_HOST"        validate:"required"`
	Port       string        `mapstructure:"DATABASE_MONGO_PORT"        validate:"required"`
	RetryTimes int           `mapstructure:"DATABASE_MONGO_RETRY_TIMES" validate:"required"`
	RetryPause time.Duration `mapstructure:"DATABASE_MONGO_RETRY_PAUSE" validate:"required"`
	Timeout    time.Duration `mapstructure:"DATABASE_MONGO_TIMEOUT"     validate:"required"`
	LRU        int           `mapstructure:"DATABASE_MONGO_LRU"         validate:"required"`
	Compressed bool
}

Jump to

Keyboard shortcuts

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