db

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanSkip added in v1.1.0

func CleanSkip(ctx context.Context, db *sql.DB) error

CleanSkip removes all skip columns from all chats.

func InTransaction

func InTransaction(ctx context.Context, db *sql.DB, f func(tx *sql.Tx) error) error

InTransaction runs method `f` inside the database transaction and does commit or rollback.

Types

type Chat

type Chat struct {
	ID           string    `db:"id"`
	Active       bool      `db:"active"`
	GPT          bool      `db:"gpt"`
	Exclude      string    `db:"exclude"`
	Skip         string    `db:"skip"`
	Days         string    `db:"days"`
	URL          string    `db:"url"`
	URLText      string    `db:"url_text"`
	Created      time.Time `db:"created_at"`
	Updated      time.Time `db:"updated_at"`
	ExcludeUsers map[string]struct{}
	SkipUsers    map[string]struct{}
	WeekDays     map[time.Weekday]map[string]struct{}
	Saved        bool
}

Chat is a struct for chat's info.

func Get

func Get(ctx context.Context, db *sql.DB, id string) (*Chat, error)

Get returns a chat's pointer by its ID.

func GetOrCreate

func GetOrCreate(ctx context.Context, db *sql.DB, id string) (*Chat, error)

GetOrCreate loads a chat by its ID or creates a new one but without saving it.

func (*Chat) AddExclude

func (chat *Chat) AddExclude(userIDs map[string]struct{})

AddExclude adds user to an exclude set.

func (*Chat) AddSkip added in v1.1.0

func (chat *Chat) AddSkip(userID string)

AddSkip adds user to an skip-set.

func (*Chat) DelExclude

func (chat *Chat) DelExclude(userIDs map[string]struct{})

DelExclude removes user from an exclude set.

func (*Chat) DelSkip added in v1.1.0

func (chat *Chat) DelSkip(userID string)

DelSkip removes user from an skip-set.

func (*Chat) Equal

func (chat *Chat) Equal(c *Chat) bool

Equal returns true if the two chats are equal.

func (*Chat) ExcludeToMap

func (chat *Chat) ExcludeToMap() error

ExcludeToMap loads exclude users set from a string.

func (*Chat) ExcludeToString

func (chat *Chat) ExcludeToString() error

ExcludeToString returns a string of exclude users set.

func (*Chat) Marshal added in v1.1.0

func (chat *Chat) Marshal() error

Marshal converts exclude and skip sets to strings.

func (*Chat) MarshalDays added in v1.2.0

func (chat *Chat) MarshalDays() error

MarshalDays converts week days to a string.

func (*Chat) SkipToMap added in v1.1.0

func (chat *Chat) SkipToMap() error

SkipToMap loads skipped users set from a string.

func (*Chat) SkipToString added in v1.1.0

func (chat *Chat) SkipToString() error

SkipToString returns a string of skipped users set.

func (*Chat) Unmarshal added in v1.1.0

func (chat *Chat) Unmarshal() error

Unmarshal converts exclude and skip strings to sets.

func (*Chat) UnmarshalDays added in v1.2.0

func (chat *Chat) UnmarshalDays() error

UnmarshalDays converts a string to week days.

func (*Chat) Update

func (chat *Chat) Update(ctx context.Context, db *sql.DB) error

Update saves chat's info.

func (*Chat) Upsert

func (chat *Chat) Upsert(ctx context.Context, db *sql.DB) error

Upsert inserts or updates a chat, make it active.

Jump to

Keyboard shortcuts

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