crud

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 20, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const CACHE_VALIDITY = 15 * time.Minute
View Source
const DB_TABLE_TEMPLATES = "bot::template"

Variables

View Source
var CACHE_LOCAL = make(map[int64]map[string][]string)
View Source
var TEST_MODE = false
View Source
var USER_CACHE = make(map[int64]*UserCacheEntry)

Functions

func EnsureApiEnabled added in v1.0.0

func EnsureApiEnabled(r *Repo, userId int64) error

func GenNonce added in v1.0.0

func GenNonce(digits int) string

func IsGroupChat added in v0.19.0

func IsGroupChat(m *tb.Message) bool

func LogDbf

func LogDbf(r *Repo, level helpers.Level, m *tb.Message, format string, v ...interface{})

Types

type Repo

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

func NewRepo

func NewRepo(db dbWrapper.DB) *Repo

func (*Repo) AddTemplate

func (r *Repo) AddTemplate(chatId int64, name, template string) error

func (*Repo) ArchiveTransactions

func (r *Repo) ArchiveTransactions(m *tb.Message) error

func (*Repo) CreateApiVerification added in v1.0.0

func (r *Repo) CreateApiVerification(userId int64) (nonce string, err error)

func (*Repo) DeleteAllCacheEntries added in v0.21.0

func (r *Repo) DeleteAllCacheEntries(m *tb.Message) error

func (*Repo) DeleteAllUserSettings added in v1.0.0

func (r *Repo) DeleteAllUserSettings(tgChatId int64) error

func (*Repo) DeleteCache

func (r *Repo) DeleteCache(m *tb.Message)

TODO: Prune cache: Free from old entries after time span (async)

func (*Repo) DeleteCacheEntries

func (r *Repo) DeleteCacheEntries(m *tb.Message, t string, value string) (sql.Result, error)

func (*Repo) DeleteTemplates added in v0.19.2

func (r *Repo) DeleteTemplates(m *tb.Message) error

func (*Repo) DeleteTransaction added in v0.20.0

func (r *Repo) DeleteTransaction(m *tb.Message, isArchived bool, elementId int) (int64, error)

func (*Repo) DeleteTransactions

func (r *Repo) DeleteTransactions(m *tb.Message) (int64, error)

func (*Repo) DeleteUser

func (r *Repo) DeleteUser(m *tb.Message) error

func (*Repo) EnrichUserData

func (r *Repo) EnrichUserData(m *tb.Message) error

func (*Repo) FillCache

func (r *Repo) FillCache(m *tb.Message) error

func (*Repo) GetCacheHints

func (r *Repo) GetCacheHints(m *tb.Message, key string) ([]string, error)

func (*Repo) GetTemplates

func (r *Repo) GetTemplates(m *tb.Message, name string) ([]*TemplateResult, error)

func (*Repo) GetTokenChatId added in v1.0.0

func (r *Repo) GetTokenChatId(token string) (chatId int64, err error)

func (*Repo) GetTransactions

func (r *Repo) GetTransactions(m *tb.Message, isArchived bool) ([]*TransactionResult, error)

func (*Repo) GetUserSetting

func (r *Repo) GetUserSetting(setting string, tgChatId int64) (exists bool, val string, err error)

func (*Repo) GetUsersToNotify

func (r *Repo) GetUsersToNotify() (*sql.Rows, error)

func (*Repo) HealthGetCacheStats

func (r *Repo) HealthGetCacheStats() (accTo, accFrom, txDesc, other int, err error)

func (*Repo) HealthGetLogs

func (r *Repo) HealthGetLogs(lastHours int) (errors int, warnings int, err error)

func (*Repo) HealthGetTransactions

func (r *Repo) HealthGetTransactions() (open int, archived int, err error)

func (*Repo) HealthGetUserCount

func (r *Repo) HealthGetUserCount() (count int, err error)

func (*Repo) HealthGetUsersActiveCounts added in v0.17.2

func (r *Repo) HealthGetUsersActiveCounts(maxDiffHours int) (count int, err error)

func (*Repo) IndividualsWithNotifications

func (r *Repo) IndividualsWithNotifications(chatId string) (recipients []string)

func (*Repo) PutCacheHints

func (r *Repo) PutCacheHints(m *tb.Message, values map[string]string) error

func (*Repo) RecordTransaction

func (r *Repo) RecordTransaction(chatId int64, tx string) error

func (*Repo) RevokeApiToken added in v1.0.0

func (r *Repo) RevokeApiToken(token string) (count int64, err error)

func (*Repo) RmTemplate

func (r *Repo) RmTemplate(chatId int64, name string) (bool, error)

func (*Repo) SetUserSetting

func (r *Repo) SetUserSetting(setting string, value string, tgChatId int64) (err error)

func (*Repo) UserGetCurrency

func (r *Repo) UserGetCurrency(m *tb.Message) string

func (*Repo) UserGetNotificationSetting

func (r *Repo) UserGetNotificationSetting(m *tb.Message) (daysDelay, hour int, err error)

func (*Repo) UserGetTag

func (r *Repo) UserGetTag(m *tb.Message) string

func (*Repo) UserGetTzOffset

func (r *Repo) UserGetTzOffset(m *tb.Message) (tzOffset int)

func (*Repo) UserIsAdmin

func (r *Repo) UserIsAdmin(m *tb.Message) (isAdmin bool)

func (*Repo) UserSetCurrency

func (r *Repo) UserSetCurrency(m *tb.Message, currency string) error

func (*Repo) UserSetNotificationSetting

func (r *Repo) UserSetNotificationSetting(m *tb.Message, daysDelay, hour int) error

* UserSetNotificationSetting sets user's notification settings. If daysDelay is < 0, schedule will be disabled.

func (*Repo) UserSetTag

func (r *Repo) UserSetTag(m *tb.Message, tag string) error

func (*Repo) UserSetTzOffset

func (r *Repo) UserSetTzOffset(m *tb.Message, timezoneOffset int) error

func (*Repo) VerifyApiToken added in v1.0.0

func (r *Repo) VerifyApiToken(userId int64, nonce string) (token string, err error)

type TemplateResult

type TemplateResult struct {
	Name     string
	Template string
}

type TransactionResult

type TransactionResult struct {
	Id   int
	Tx   string
	Date string
}

type User

type User struct {
	TgChatId   int64
	TgUsername string
}

type UserCacheEntry

type UserCacheEntry struct {
	Expiry time.Time
	Value  *User
}

Jump to

Keyboard shortcuts

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