storage

package
v0.0.0-...-b0fc717 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2021 License: MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Db_pool *sql.DB
View Source
var ErrNoLogin error = NewCommitAndYield("no stored credentials for telegram user")
View Source
var ErrNoTag = errors.New("no corresponding tag exists")

Functions

func AddReplacementHistory

func AddReplacementHistory(d DBLike, event *ReplacementHistory) error

func AliasUpdater

func AliasUpdater(d DBLike, input chan apitypes.TAliasData) error

func ClearAliasIndex

func ClearAliasIndex(d DBLike) error

func ClearCatsException

func ClearCatsException(d DBLike, tag string) error

func CommitAndYieldErrorf

func CommitAndYieldErrorf(format string, args ...interface{}) error

CommitAndYieldErrorf produces an unwrappable error (see fmt.Errorf) which implements CommitAndYield.

func CountTags

func CountTags(d DBLike, sfx chan string) error

func DBInit

func DBInit(dburl string) error

initialize the DAL. Closing it might be important at some point, but who cares right now.

func DefaultTransact

func DefaultTransact(callback func(DBLike) error) error

A convenience specialization of Transact which automatically uses Db_pool.

func DelTagTypoByTag

func DelTagTypoByTag(d DBLike, typo TypoData) error

func DeleteBlitByName

func DeleteBlitByName(d DBLike, name string) error

func DeleteCatByTagNames

func DeleteCatByTagNames(d DBLike, cat CatData) error

func DeleteReplacement

func DeleteReplacement(d DBLike, id int64) error

func DeleteUserCreds

func DeleteUserCreds(d DBLike, id tgtypes.UserID) error

func DeleteUserSettings

func DeleteUserSettings(d DBLike, id tgtypes.UserID) error

func DeleteUserTagRules

func DeleteUserTagRules(d DBLike, id tgtypes.UserID) error

func EnumerateAllBlits

func EnumerateAllBlits(d DBLike) (map[string]bool, error)

func EnumerateAllTags

func EnumerateAllTags(d DBLike, orderByCount bool) (apitypes.TTagInfoArray, error)

func EnumerateCatsExceptions

func EnumerateCatsExceptions(d DBLike) ([]string, error)

func EraseDialogPost

func EraseDialogPost(d DBLike, msg_id tgtypes.MsgID, chat_id tgtypes.ChatID) error

func FindCachedMp4ForWebm

func FindCachedMp4ForWebm(d DBLike, md5 string) (*tgtypes.FileID, error)

func GetAliasedTags

func GetAliasedTags(d DBLike) (apitypes.TTagInfoArray, error)

func GetAliasesFor

func GetAliasesFor(d DBLike, tag string) (apitypes.TTagInfoArray, error)

func GetBlits

func GetBlits(d DBLike, yes, no, wild bool) ([]BlitData, []BlitData, []BlitData, error)

func GetCats

func GetCats(d DBLike, yes, no bool) ([]CatData, []CatData, error)

func GetHighestPostID

func GetHighestPostID(d DBLike) (int, error)

func GetLastTag

func GetLastTag(d DBLike) (*apitypes.TTagData, error)

func GetMostRecentlyUpdatedPost

func GetMostRecentlyUpdatedPost(d DBLike) (*apitypes.TPostInfo, error)

func GetReplacementHistorySince

func GetReplacementHistorySince(d DBLike, post_ids []int, since time.Time) (map[ReplacementHistoryKey]ReplacementHistory, error)

func GetTag

func GetTag(tx *sql.Tx, id int) (*apitypes.TTagData, error)

func GetTagByName

func GetTagByName(d DBLike, name string, createPhantom bool) (*apitypes.TTagData, error)

Looks up a tag by its name. Has a special option `createPhantom`, which when set, will create a "phantom tag" in the database. the type will be inferred from the tag name (a prefix can be used to specify its type, see PrefixedTagToTypedTag. It is created with a negative tag_id (all such tags with negative IDs are phantoms). Phantom tags have all of the hallmarks of real tags but don't exist server-side. When the bot fetches an update that includes the phantom tag, its `tag_id` will be updated to reflect the true id (thus promoting it from a phantom tag to a real one) and will chain this update to all tables that use foreign keys to refer to tag_ids.

func GetTagTypos

func GetTagTypos(d DBLike, tag string) (map[string]TypoData, error)

func GetTags

func GetTags(tx *sql.Tx, ids []int) (apitypes.TTagInfoArray, error)

func GetTagsWithCountEqual

func GetTagsWithCountEqual(tx *sql.Tx, count int) (apitypes.TTagInfoArray, error)

func GetTagsWithCountGreater

func GetTagsWithCountGreater(tx *sql.Tx, count int) (apitypes.TTagInfoArray, error)

func GetTagsWithCountLess

func GetTagsWithCountLess(tx *sql.Tx, count int) (apitypes.TTagInfoArray, error)

func GetUserTagRules

func GetUserTagRules(d DBLike, id tgtypes.UserID, name string) (string, error)

func ImportPostTagsFromNameToID

func ImportPostTagsFromNameToID(d DBLike, sfx chan string) error

func MarkBlit

func MarkBlit(tx *sql.Tx, id int, mark bool) error

func MarkBlitByName

func MarkBlitByName(d DBLike, name string, mark bool) error

func MarkPostDeleted

func MarkPostDeleted(d DBLike, post_id int) error

func NewCommitAndYield

func NewCommitAndYield(message string) error

NewCommitAndYield produces an error which implements CommitAndYield.

func NewRollbackAndMask

func NewRollbackAndMask(message string) error

NewRollbackAndMask produces an error which implements RollbackAndMask.

func NewTxRequired

func NewTxRequired(message string) error

TxRequiredError produces an error which implements RequiresTransaction.

func PaginatedGetAllReplacements

func PaginatedGetAllReplacements(d DBLike, page_size int) chan ReplacersPage

func PaginatedPostsById

func PaginatedPostsById(d DBLike, ids []int, pageSize int) chan PostsPage

func PostByID

func PostByID(d DBLike, id int) (*apitypes.TPostInfo, error)

func PostByMD5

func PostByMD5(d DBLike, md5 string) (*apitypes.TPostInfo, error)

func PostDeleter

func PostDeleter(d DBLike, input chan []int) error

func PostUpdater

func PostUpdater(d DBLike, input chan apitypes.TPostInfo) error

func PostsById

func PostsById(d DBLike, ids []int) ([]apitypes.TPostInfo, error)

func PostsWithTag

func PostsWithTag(d DBLike, tag apitypes.TTagData, includeDeleted bool) (apitypes.TPostInfoArray, error)

func PrefixedTagToTypedTag

func PrefixedTagToTypedTag(name string) (string, int)

func RecalculateAliasedCounts

func RecalculateAliasedCounts(d DBLike) error

func RollbackAndMaskErrorf

func RollbackAndMaskErrorf(format string, args ...interface{}) error

RollbackAndMaskErrorf produces an unwrappable error (see fmt.Errorf) which implements RollbackAndMask.

func SaveCachedMp4ForWebm

func SaveCachedMp4ForWebm(d DBLike, md5 string, id tgtypes.FileID) error

func SavePromptPost

func SavePromptPost(d DBLike, id int, x *PromptPostInfo) error

func SetCatByTagNames

func SetCatByTagNames(d DBLike, cat CatData, marked, autofix bool) error

func SetCatsException

func SetCatsException(d DBLike, tag string) error

func SetTagTypoByTag

func SetTagTypoByTag(d DBLike, typo TypoData, marked, autofix bool) error

func TagUpdater

func TagUpdater(d DBLike, input chan apitypes.TTagData) error

func Transact

func Transact(db_connection *sql.DB, callback func(DBLike) error) (err error)

Transact wraps the provided callback in a transaction. See the package documentation for usage examples.

func UpdatePost

func UpdatePost(d DBLike, post apitypes.TPostInfo) error

func UpdateReplacement

func UpdateReplacement(d DBLike, repl Replacer) error

func WrapExec

func WrapExec(_ sql.Result, err error) error

func WriteDialogPost

func WriteDialogPost(d DBLike, dialog_id tgtypes.DialogID, msg_id tgtypes.MsgID, chat_id tgtypes.ChatID, json string, msg_ts time.Time) error

func WriteUserCreds

func WriteUserCreds(d DBLike, creds UserCreds) error

func WriteUserSettings

func WriteUserSettings(d DBLike, s *UserSettings) error

func WriteUserTagRules

func WriteUserTagRules(d DBLike, id tgtypes.UserID, name, rules string) error

Types

type BlitData

type BlitData struct {
	apitypes.TTagData

	Valid bool
}

func GetMarkedAndUnmarkedBlits

func GetMarkedAndUnmarkedBlits(tx *sql.Tx) ([]BlitData, error)

func (BlitData) String

func (b BlitData) String() string

type CatData

type CatData struct {
	Id            int64
	Merged        apitypes.TTagData
	First, Second *apitypes.TTagData
	Marked        bool
	ReplaceId     *int64
}

func (CatData) String

func (c CatData) String() string

type CommitAndYield

type CommitAndYield interface{ Yielded() }

Returning a CommitAndYield from within a function called by Transact produces special behavior, described by Transact's docs.

type CorrectionMode

type CorrectionMode int
const AutoFix CorrectionMode = 3
const Ignore CorrectionMode = 1
const Prompt CorrectionMode = 2
const Untracked CorrectionMode = 0

func (CorrectionMode) Display

func (this CorrectionMode) Display() string

type DBLike

type DBLike interface {
	InTransaction() bool
	EnsureTransaction(*error) func()
	Enter(func(Queryable) error) error
}

DBLike is a generic interface that encapsulates a database, and optionally also a transaction.

func DefaultNoTx

func DefaultNoTx() DBLike

DefaultNoTx, like DefaultTransact, is a convenience wrapper for NoTx using the default database Db_pool.

func NoTx

func NoTx(database *sql.DB) DBLike

NoTx produces a DBLike around a database, without opening a transaction, allowing for untransacted queries.

type DialogPost

type DialogPost struct {
	MsgId      tgtypes.MsgID
	MsgTs      time.Time
	ChatId     tgtypes.ChatID
	DialogId   tgtypes.DialogID
	DialogData []byte
}

func FetchDialogPost

func FetchDialogPost(d DBLike, msg_id tgtypes.MsgID, chat_id tgtypes.ChatID) (*DialogPost, error)

type PostSuggestedEdit

type PostSuggestedEdit struct {
	Prompt        tags.TagDiffArray `json:"prompt"`
	AutoFix       tags.TagDiffArray `json:"autofix"`
	SelectedEdits map[string]bool   `json:"selected_edits"`
	AppliedEdits  map[string]bool   `json:"applied_edits"`
	Represents    []int64           `json:"represents"`
}

func (PostSuggestedEdit) Append

merge two edit lists, with certain requirements. the edit list of `this` must remain index-stable, that is to say, items in its prompt and autofix lists should keep the same indices in the output. this allows us to merge multiple edit lists onto one, while not breaking the user experience by making buttons move around if we edit a post while they're pushing them.

func (*PostSuggestedEdit) Apply

func (this *PostSuggestedEdit) Apply()

func (*PostSuggestedEdit) Deselect

func (this *PostSuggestedEdit) Deselect(from string, index int)

do nothing if an invalid selector is specified

func (*PostSuggestedEdit) DeselectAll

func (this *PostSuggestedEdit) DeselectAll()

func (*PostSuggestedEdit) DeselectDirect

func (this *PostSuggestedEdit) DeselectDirect(api_string string)

func (PostSuggestedEdit) Flatten

func (this PostSuggestedEdit) Flatten() tags.TagDiff

func (PostSuggestedEdit) GetChangeToApply

func (this PostSuggestedEdit) GetChangeToApply() tags.TagDiff

func (*PostSuggestedEdit) Scan

func (this *PostSuggestedEdit) Scan(value interface{}) error

func (*PostSuggestedEdit) Select

func (this *PostSuggestedEdit) Select(from string, index int)

do nothing if an invalid selector is specified

func (*PostSuggestedEdit) SelectAll

func (this *PostSuggestedEdit) SelectAll()

func (*PostSuggestedEdit) SelectAutofix

func (this *PostSuggestedEdit) SelectAutofix()

func (*PostSuggestedEdit) SelectDirect

func (this *PostSuggestedEdit) SelectDirect(api_string string)

func (PostSuggestedEdit) Value

func (this PostSuggestedEdit) Value() (driver.Value, error)

type PostsPage

type PostsPage struct {
	Page  []int
	Posts []apitypes.TPostInfo
	Err   error
}

type PromptPostInfo

type PromptPostInfo struct {
	PostId     int
	PostType   string
	PostURL    string
	SampleURL  string
	PostMd5    string
	PostWidth  int
	PostHeight int
	MsgId      tgtypes.MsgID
	ChatId     tgtypes.ChatID
	Timestamp  time.Time
	Captioned  bool
	Edit       *PostSuggestedEdit
}

func FindPromptPost

func FindPromptPost(d DBLike, id int) (*PromptPostInfo, error)

func FindPromptPostByMessage

func FindPromptPostByMessage(d DBLike, chat_id tgtypes.ChatID, msg_id tgtypes.MsgID) (*PromptPostInfo, error)

func FindPromptPostsOlderThan

func FindPromptPostsOlderThan(d DBLike, time_ago time.Duration) ([]PromptPostInfo, error)

type Queryable

type Queryable interface {
	Exec(string, ...interface{}) (sql.Result, error)
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	Query(string, ...interface{}) (*sql.Rows, error)
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	QueryRow(string, ...interface{}) *sql.Row
	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}

Queryable is compatible with query/exec methods of both *sql.DB and *sql.Tx.

type ReplacementHistory

type ReplacementHistory struct {
	ReplacementHistoryKey

	Id             int64         `dml:"action_id"`
	TelegramUserId tgdata.UserID `dml:"telegram_user_id"`
	Timestamp      time.Time     `dml:"action_ts"`
}

type ReplacementHistoryKey

type ReplacementHistoryKey struct {
	ReplacerId int64 `dml:"replace_id"`
	PostId     int   `dml:"post_id"`
}

type Replacer

type Replacer struct {
	Id          int64  `dml:"replace_id"`
	MatchSpec   string `dml:"match_spec"`
	ReplaceSpec string `dml:"replace_spec"`
	Autofix     bool   `dml:"autofix"`
}

func AddReplacement

func AddReplacement(d DBLike, repl Replacer) (*Replacer, error)

func GetReplacements

func GetReplacements(d DBLike, after_id int64, page_size int) ([]Replacer, error)

func (*Replacer) Matcher

func (this *Replacer) Matcher() ReplacerMatcher

type ReplacerMatcher

type ReplacerMatcher struct {
	MatchSpec, ReplaceSpec tags.TagDiff
}

func (*ReplacerMatcher) Matches

func (rm *ReplacerMatcher) Matches(postTags tags.TagSet) bool

type ReplacersPage

type ReplacersPage struct {
	Replacers []Replacer
	Err       error
}

type RequiresTransaction

type RequiresTransaction interface{ RequiresTx() }

Used to flag to callers of functions which are called without transactions that they failed due to the absence of a transaction but could succeed if properly transacted.

type RollbackAndMask

type RollbackAndMask interface{ Masked() }

Returning a RollbackAndMask from within a function called by Transact produces special behavior, described by Transact's docs.

type TypoData

type TypoData struct {
	Id        int64 `dml:"typo_id"`
	Tag       apitypes.TTagData
	Fix       *apitypes.TTagData
	Marked    bool   `dml:"marked"`
	ReplaceId *int64 `dml:"replace_id"`
}

type UserCreds

type UserCreds struct {
	TelegramId       tgtypes.UserID `dml:"telegram_id"`
	User             string         `dml:"api_user"`
	ApiKey           string         `dml:"api_apikey"`
	Janitor          bool           `dml:"privilege_janitorial"`
	Blacklist        string         `dml:"api_blacklist"`
	BlacklistFetched time.Time      `dml:"api_blacklist_last_updated"`
}

func GetUserCreds

func GetUserCreds(d DBLike, id tgtypes.UserID) (UserCreds, error)

type UserSettings

type UserSettings struct {
	TelegramId    tgtypes.UserID
	AgeStatus     types.AgeStatus
	RatingMode    types.RatingMode
	BlacklistMode types.BlacklistMode
}

func GetUserSettings

func GetUserSettings(d DBLike, telegram_id tgtypes.UserID) (*UserSettings, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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