db

package
v0.0.0-...-a0b95df Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2021 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCannotSaveNonIteration = errors.New("cannot save non-iteration item")
	ErrNoTGUser               = errors.New("no such telegram user")
)
View Source
var (
	ErrNoFAUser = errors.New("no such furaffinity user")
)
View Source
var (
	ErrNoSearch = errors.New("no such search")
)

Functions

This section is empty.

Types

type DB

type DB interface {
	Close() error

	AddSearchForUser(userID TelegramID, search string) error
	DeleteSearchForUser(userID TelegramID, search string) error
	IterateSearches(cb SearchIterator) error

	AddUserSubmissionsForUser(userID TelegramID, faUser string) error
	DeleteUserSubmissionsForUser(userID TelegramID, faUser string) error
	AddUserJournalsForUser(userID TelegramID, faUser string) error
	DeleteUserJournalsForUser(userID TelegramID, faUser string) error
	IterateUsers(cb UserIterator) error

	GetTGUser(id TelegramID) (*TGUser, error)
	SaveTGUser(user *TGUser) error
}

DB is an interface that can load and store information in a database.

func New

func New(filename string) (DB, error)

New creates a new database connection.

type FAUser

type FAUser struct {

	// TODO have a way to get and store the preferred case of the username
	Username         string              `json:"username"`
	LastRun          time.Time           `json:"last_run"`
	LastSubmissionID int64               `json:"last_submission_id"`
	LastJournalID    int64               `json:"last_journal_id"`
	SubmissionUsers  map[TelegramID]bool `json:"submission_users"`
	JournalUsers     map[TelegramID]bool `json:"journal_users"`
	// contains filtered or unexported fields
}

func (*FAUser) Update

func (u *FAUser) Update() error

Update saves the current state of the user back to the database, if the user was loaded via iteration. Otherwise, ErrCannotSaveNonIteration is returned.

type Search struct {
	Search  string              `json:"search"`
	LastRun time.Time           `json:"last_run"`
	LastID  int64               `json:"last_id"`
	Users   map[TelegramID]bool `json:"tg_users"`
	// contains filtered or unexported fields
}

func (*Search) Update

func (s *Search) Update() error

Update saves the current state of the search back to the database, if the search was loaded via iteration. Otherwise, ErrCannotSaveNonIteration is returned.

type SearchIterator

type SearchIterator func(search *Search, ul UserLoader) error

type TGUser

type TGUser struct {
	Username        string          `json:"username"`
	ID              TelegramID      `json:"id"`
	Started         bool            `json:"started"`
	LastUpdated     time.Time       `json:"last_updated"`
	Searches        map[string]bool `json:"searches"`
	SubmissionUsers map[string]bool `json:"submission_users"`
	JournalUsers    map[string]bool `json:"journal_users"`
}

TGUser represents a telegram user in the database.

type TelegramID

type TelegramID int64

TelegramID is the type of Telegram entity IDs.

func (TelegramID) Key

func (id TelegramID) Key() []byte

type UserIterator

type UserIterator func(faUser *FAUser, ul UserLoader) error

type UserLoader

type UserLoader func(id TelegramID) (*TGUser, error)

UserLoader is used to load a user while iterating over saved items.

Jump to

Keyboard shortcuts

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