db

package
v0.3.10 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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"`
	Exclude      string    `db:"exclude"`
	URL          string    `db:"url"`
	Created      time.Time `db:"created_at"`
	Updated      time.Time `db:"updated_at"`
	ExcludeUsers 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) DelExclude

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

DelExclude removes user from an exclude 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) 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