repo

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2023 License: MIT Imports: 16 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")

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) List

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

List returns the list of the user's aliases.

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) ([]string, error)

ListWithCounts prints the list in the format:

alias (1)
link -> alias

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

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 of 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) ([]*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.

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) error

Create a new package.

func (*PackageService) Delete

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

Delete some package.

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) ([]string, 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) error

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

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