db

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConstraintUnique = errors.New("failed unique constraint")
)

Functions

This section is empty.

Types

type DB

type DB interface {
	Close() error
	Migrate(context.Context) error
	CreateSubscription(*Subscription) error
	GetSubscription(id string) (*Subscription, error)
	UpdateSubscription(*Subscription) error
	GetUserSubscriptions(userID string) ([]TermSubscription, error)
	FindSubscriptionsToNotify(window time.Duration, limit int) ([]TermSubscription, error)
	SetNotified(subIDs ...string) error
	DeleteUserSubscriptions(userID string, ids ...string) error
	CreateTerm(*Term) error
	GetTerm(id string) (*Term, error)
	FilterBySeenItems(items []Item) ([]Item, error)
	TrackItems(items ...Item) error
	CleanupItems(window time.Duration) error
}

func NewSQLite

func NewSQLite(dsn string) (DB, error)

type Item

type Item struct {
	ID             string
	Shop           sendico.Shop
	Code           string
	SubscriptionID string
}

type SQLite

type SQLite struct {
	*sql.DB
}

func (*SQLite) CleanupItems

func (s *SQLite) CleanupItems(window time.Duration) error

func (*SQLite) CreateSubscription

func (s *SQLite) CreateSubscription(subscription *Subscription) error

func (*SQLite) CreateTerm

func (s *SQLite) CreateTerm(term *Term) error

func (*SQLite) DeleteUserSubscriptions

func (s *SQLite) DeleteUserSubscriptions(userID string, ids ...string) error

func (*SQLite) FilterBySeenItems

func (s *SQLite) FilterBySeenItems(items []Item) ([]Item, error)

func (*SQLite) FindSubscriptionsToNotify

func (s *SQLite) FindSubscriptionsToNotify(window time.Duration, limit int) ([]TermSubscription, error)

func (*SQLite) GetSubscription

func (s *SQLite) GetSubscription(id string) (*Subscription, error)

func (*SQLite) GetTerm

func (s *SQLite) GetTerm(id string) (*Term, error)

func (*SQLite) GetUserSubscriptions

func (s *SQLite) GetUserSubscriptions(userID string) ([]TermSubscription, error)

func (*SQLite) Migrate

func (s *SQLite) Migrate(ctx context.Context) error

func (*SQLite) SetNotified

func (s *SQLite) SetNotified(subIDs ...string) error

func (*SQLite) TrackItems

func (s *SQLite) TrackItems(items ...Item) error

func (*SQLite) UpdateSubscription

func (s *SQLite) UpdateSubscription(subscription *Subscription) error

type Subscription

type Subscription struct {
	ID             string
	UserID         string
	TermID         string
	LastNotifiedAt time.Time
	ShopsBitField  int
	MinPrice       *int
	MaxPrice       *int
}

func (*Subscription) AddShop

func (s *Subscription) AddShop(shop sendico.Shop)

func (*Subscription) Shops

func (s *Subscription) Shops() []sendico.Shop

type Term

type Term struct {
	ID string
	EN string
	JP string
}

type TermSubscription

type TermSubscription struct {
	Term         Term
	Subscription Subscription
}

Jump to

Keyboard shortcuts

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