repo

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package repo is an abstraction layer over the database connection. It provides simplified CRUD services to work with persistent entities.

Index

Constants

This section is empty.

Variables

View Source
var NoRowsWereAffected = errors.New("no rows were affected")
View Source
var ResultsPerPage int

Functions

func FormatPackageName

func FormatPackageName(uid int64, name string) string

FormatPackageName returns the full name of the package.

Types

type AliasService

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

AliasService is like an extension of FavService but to list all saved aliases of a user. It works with Favs and Aliases internally but returns only the latter as strings.

func NewAliasService

func NewAliasService(appenv *base.ApplicationEnv) *AliasService

func (*AliasService) Hide added in v1.0.6

func (service *AliasService) Hide(uid int64, alias string) error

Hide excludes all favs associated with a specified alias from the output of List, ListWithCounts and ListForFavsOnly methods.

func (*AliasService) List

func (service *AliasService) List(uid int64) ([]string, error)

List returns the list of the user's aliases.

func (*AliasService) ListByFile added in v1.1.0

func (service *AliasService) ListByFile(uid int64, file *wizard.File) ([]string, error)

ListByFile returns the list of the user's aliases associated with a specific file (i.e. any object which is not text nor location).

func (*AliasService) ListByLocation added in v1.1.0

func (service *AliasService) ListByLocation(uid int64, loc *wizard.LocData) ([]string, error)

ListByLocation returns the list of the user's aliases associated with a specific location fav.

func (*AliasService) ListByText added in v1.1.0

func (service *AliasService) ListByText(uid int64, text *wizard.Txt) ([]string, error)

ListByText returns the list of the user's aliases associated with a specific textual fav.

func (*AliasService) ListForFavsOnly

func (service *AliasService) ListForFavsOnly(uid int64) ([]string, error)

ListForFavsOnly returns the list of the user's aliases associated only with favs, but not with links.

func (*AliasService) ListWithCounts

func (service *AliasService) ListWithCounts(uid int64, grep string, lastAlias string) (*Page, error)

ListWithCounts prints the list in the format:

alias (1)
link -> alias

where '1' is the count of favs associated with 'alias'

func (*AliasService) Reveal added in v1.0.6

func (service *AliasService) Reveal(uid int64, alias string) error

Reveal is a reversed to Hide operation.

type FavService

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

FavService is a common CRUD service for Favs, Aliases and Texts tables. It knows about the links as well.

func NewFavsService

func NewFavsService(appenv *base.ApplicationEnv) *FavService

func (*FavService) DeleteByAlias

func (service *FavService) DeleteByAlias(uid int64, alias string) (RowsAffectedAware, error)

DeleteByAlias deletes all the user's favs associated with alias.

func (*FavService) DeleteFav

func (service *FavService) DeleteFav(uid int64, alias string, fav *dto.Fav) (RowsAffectedAware, error)

DeleteFav deletes a specific fav of the user.

func (*FavService) Find

func (service *FavService) Find(uid int64, query string, bySubstr bool, offset int) ([]*dto.Fav, error)

Find is a method to search for favs in the database. The search can be performed either by exact match or by substring match.

func (*FavService) Save

func (service *FavService) Save(uid int64, alias string, fav *dto.Fav) (RowsAffectedAware, error)

Save a fav associated with the user and alias.

type LinkService

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

LinkService is a simple "create" service for the Link entity. https://github.com/kozalosev/SadFavBot/wiki/Glossary#link

func NewLinkService

func NewLinkService(appenv *base.ApplicationEnv) *LinkService

func (*LinkService) Create

func (service *LinkService) Create(uid int64, name, refAlias string) error

Create a link to refAlias for the user with the specified UID.

func (*LinkService) Delete added in v1.1.5

func (service *LinkService) Delete(uid int64, name string) error

type PackageInfo

type PackageInfo struct {
	UID  int64
	Name string
}

PackageInfo is a simple struct which consists of the UID of the package's owner and the Name of the package.

type PackageService

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

PackageService is a CRUD service for the Package entity. It's also responsible for installation of packages. https://github.com/kozalosev/SadFavBot/wiki/Glossary#package

func NewPackageService

func NewPackageService(appenv *base.ApplicationEnv) *PackageService

func (*PackageService) Create

func (service *PackageService) Create(uid int64, name string, aliases []string) (string, error)

Create a new package.

func (*PackageService) Delete

func (service *PackageService) Delete(uid int64, name string) error

Delete some package.

func (*PackageService) Exists added in v1.2.2

func (service *PackageService) Exists(pkgInfo *PackageInfo) (exists bool, err error)

Exists returns true if the package exists in the database.

func (*PackageService) FindByAliases added in v1.2.2

func (service *PackageService) FindByAliases(uid int64, aliases []string) (packageNames []string, err error)

FindByAliases returns the list of all user's packages associated with the given aliases.

func (*PackageService) Install

func (service *PackageService) Install(uid int64, pkgInfo *PackageInfo) ([]string, error)

Install the package for a specific user.

func (*PackageService) ListAliases

func (service *PackageService) ListAliases(pkgInfo *PackageInfo) (items []string, err error)

ListAliases returns the list of aliases in the package.

func (*PackageService) ListWithCounts

func (service *PackageService) ListWithCounts(uid int64, lastPackage string) (*Page, error)

ListWithCounts prints the list of saved packages of some user in the format:

package (1)

where '1' is the count of aliases associated with 'package'

func (*PackageService) Recreate added in v0.4.2

func (service *PackageService) Recreate(uid int64, name string, aliases []string) (string, error)

Recreate is a combination of Delete and Create executing in one transaction.

func (*PackageService) ResolveName added in v1.1.10

func (service *PackageService) ResolveName(uuid string) (string, error)

ResolveName fetches the name of a package by its unique_id.

type Page added in v1.1.1

type Page struct {
	Items       []string
	HasNextPage bool
	// contains filtered or unexported fields
}

func (Page) GetLastItem added in v1.1.1

func (p Page) GetLastItem() string

type RowsAffectedAware

type RowsAffectedAware interface {
	RowsAffected() int64
}

type UserService

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

UserService is a service for working with user settings.

func NewUserService

func NewUserService(appenv *base.ApplicationEnv) *UserService

func (*UserService) ChangeLanguage

func (service *UserService) ChangeLanguage(uid int64, lang settings.LangCode) error

ChangeLanguage updates the value of the user's language option.

func (*UserService) ChangeSubstringMode

func (service *UserService) ChangeSubstringMode(uid int64, value bool) error

ChangeSubstringMode updates the value of the user's substring_mode option.

func (*UserService) Create

func (service *UserService) Create(uid int64) (bool, error)

Create a new user as a row in the database. Returns false if the user was already saved there.

func (*UserService) FetchUserOptions

func (service *UserService) FetchUserOptions(uid int64, defaultLang string) (settings.LangCode, settings.UserOptions)

FetchUserOptions from the database if they exist.

Jump to

Keyboard shortcuts

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