db

package
v0.0.0-...-4377792 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SchemaMigrations

func SchemaMigrations() []*gomigrate.Migration

SchemaMigrations gives each caller a new copy of the migrations. This is mostly useful to allow unit tests to run in parallel.

func TestFixtures

func TestFixtures() []*gomigrate.Migration

TestFixtures gives the standard fixtures for db testing

Types

type FeedInfo

type FeedInfo struct {
	ID                int64     `jsonapi:"primary,feeds"`
	Name              string    `jsonapi:"attr,name"`
	URL               string    `jsonapi:"attr,url"`
	SiteURL           string    `db:"site_url" jsonapi:"attr,site-url"`
	LastPollTime      time.Time `db:"last_poll_time" jsonapi:"attr,last-poll-time,iso8601"`
	LastPollError     string    `db:"last_poll_error" jsonapi:"attr,last-poll-error"`
	LastErrorResponse string    `db:"last_error_response"`
	Users             []User    ``
}

FeedInfo represents a feed (atom, rss or rdf) that rss2go is polling.

type FeedItem

type FeedItem struct {
	ID         int64
	FeedInfoID int64 `db:"feed_info_id"`
	GUID       string
	AddedOn    time.Time `db:"added_on"`
}

FeedItem represents an individual iteam from a feed. It only captures the Guid for that item and is mainly used to check if a particular item has been seen before.

type Handle

type Handle struct {
	// contains filtered or unexported fields
}

Handle controls access to the database and makes sure only one operation is in process at a time.

func NewDBHandle

func NewDBHandle(dbPath string, logger logrus.FieldLogger) *Handle

NewDBHandle creates a new DBHandle

dbPath: the path to the database to use.
verbose: when true database accesses are logged to stdout

func NewMemoryDBHandle

func NewMemoryDBHandle(logger logrus.FieldLogger, loadFixtures bool) *Handle

NewMemoryDBHandle creates a new in memory database. Only used for testing. The name of the database is a random string so multiple tests can run in parallel with their own database.

func (*Handle) AddFeed

func (d *Handle) AddFeed(name string, feedURL string) (*FeedInfo, error)

AddFeed creates a new FeedInfo entry in the database and returns it.

func (*Handle) AddFeedsToUser

func (d *Handle) AddFeedsToUser(u *User, feeds []*FeedInfo) error

AddFeedsToUser creates a UserFeed entry between the given user and feeds. This 'subscribes' the user to those feeds to they will get email updates for that feed.

func (*Handle) AddUser

func (d *Handle) AddUser(name string, email string, pass string) (*User, error)

AddUser creates a User record in the database.

func (*Handle) GetAllFeeds

func (d *Handle) GetAllFeeds() ([]*FeedInfo, error)

GetAllFeeds returns all feeds from the database.

func (*Handle) GetAllFeedsWithUsers

func (d *Handle) GetAllFeedsWithUsers() ([]*FeedInfo, error)

GetAllFeedsWithUsers returns all feeds from the database that have subscribers

func (*Handle) GetAllUsers

func (d *Handle) GetAllUsers() ([]User, error)

GetAllUsers returns all Users from the database.

func (*Handle) GetFeedByID

func (d *Handle) GetFeedByID(id int64) (*FeedInfo, error)

GetFeedByID returns the FeedInfo for the given id.

func (*Handle) GetFeedByURL

func (d *Handle) GetFeedByURL(url string) (*FeedInfo, error)

GetFeedByURL returns the FeedInfo for the given URL.

func (*Handle) GetFeedItemByGUID

func (d *Handle) GetFeedItemByGUID(feedID int64, guid string) (*FeedItem, error)

GetFeedItemByGUID returns a FeedItem for the given FeedInfo.Id and guid.

func (*Handle) GetFeedUsers

func (d *Handle) GetFeedUsers(feedURL string) ([]User, error)

GetFeedUsers returns all the users subscribed to a given feedURL

func (*Handle) GetFeedsByName

func (d *Handle) GetFeedsByName(name string) ([]*FeedInfo, error)

GetFeedsByName returns all feeds that contain the given string in their name.

func (*Handle) GetFeedsWithErrors

func (d *Handle) GetFeedsWithErrors() ([]*FeedInfo, error)

GetFeedsWithErrors returns all feeds that had an error on their last check.

func (*Handle) GetMostRecentGUIDsForFeed

func (d *Handle) GetMostRecentGUIDsForFeed(feedID int64, max int) ([]string, error)

GetMostRecentGUIDsForFeed retrieves the most recent GUIDs for a given feed up to max. GUIDs are returned ordered with the most recent first.

func (*Handle) GetStaleFeeds

func (d *Handle) GetStaleFeeds() ([]*FeedInfo, error)

GetStaleFeeds returns all feeds that haven't gotten new content in more than 14 days.

func (*Handle) GetUser

func (d *Handle) GetUser(name string) (*User, error)

GetUser returns the user with the given name from the database.

func (*Handle) GetUserByEmail

func (d *Handle) GetUserByEmail(email string) (*User, error)

GetUserByEmail returns the user with the given email from the database.

func (*Handle) GetUserByID

func (d *Handle) GetUserByID(id int64) (*User, error)

GetUserByID returns the user with the given id from the database.

func (*Handle) GetUserFeedsWithErrors

func (d *Handle) GetUserFeedsWithErrors(user *User) ([]*FeedInfo, error)

GetUserFeedsWithErrors returns all feeds that had an error on their last check that a given user is subscribed to.

func (*Handle) GetUserReport

func (d *Handle) GetUserReport(u *User) (*UserReport, error)

func (*Handle) GetUserStaleFeeds

func (d *Handle) GetUserStaleFeeds(user *User) ([]*FeedInfo, error)

GetUserStaleFeeds returns all feeds that haven't gotten new content in more than 14 days.

func (*Handle) GetUsersFeeds

func (d *Handle) GetUsersFeeds(u *User) ([]*FeedInfo, error)

GetUsersFeeds returns all the FeedInfos that a user is subscribed to.

func (*Handle) GetUsersFeedsByName

func (d *Handle) GetUsersFeedsByName(user *User, name string) ([]*FeedInfo, error)

GetUsersFeedsByName returns all feeds that contain the given string in their name.

func (*Handle) Migrate

func (d *Handle) Migrate(m []*gomigrate.Migration) error

Migrate uses the migrations at the given path to update the database.

func (*Handle) RecordGUID

func (d *Handle) RecordGUID(feedID int64, guid string) error

RecordGUID adds a FeedItem record for the given feedID and guid.

func (*Handle) RemoveFeed

func (d *Handle) RemoveFeed(url string) error

RemoveFeed removes a FeedInfo from the database given it's URL

func (*Handle) RemoveFeedsFromUser

func (d *Handle) RemoveFeedsFromUser(u *User, feeds []*FeedInfo) error

RemoveFeedsFromUser does the opposite of AddFeedsToUser

func (*Handle) RemoveUser

func (d *Handle) RemoveUser(user *User) error

RemoveUser removes the given user from the database.

func (*Handle) RemoveUserByEmail

func (d *Handle) RemoveUserByEmail(email string) error

RemoveUserByEmail removes the user with the given email from the database.

func (*Handle) SaveFeed

func (d *Handle) SaveFeed(f *FeedInfo) error

SaveFeed updates the given FeedInfo in the database.

func (*Handle) SaveFeedItem

func (d *Handle) SaveFeedItem(f *FeedItem) error

SaveFeedItem updates the information for a given FeedItem

func (*Handle) SaveUser

func (d *Handle) SaveUser(u *User) error

SaveUser creates or updates the given User in the database.

func (*Handle) SetUserReport

func (d *Handle) SetUserReport(u *User) error

func (*Handle) UpdateUsersFeeds

func (d *Handle) UpdateUsersFeeds(u *User, feedIDs []int64) error

UpdateUsersFeeds replaces a users subscribed feeds with the given list of feedIDs

type Service

type Service interface {
	GetFeedByURL(string) (*FeedInfo, error)
	GetFeedUsers(string) ([]User, error)
	SaveFeed(*FeedInfo) error
	GetMostRecentGUIDsForFeed(int64, int) ([]string, error)
	RecordGUID(int64, string) error
	GetFeedItemByGUID(int64, string) (*FeedItem, error)
}

Service defines the interface that the RSS2Go database provides. Useful for mocking out the databse layer in tests.

type User

type User struct {
	ID       int64      `jsonapi:"primary,feeds"`
	Name     string     `jsonapi:"attr,name"`
	Email    string     `jsonapi:"attr,email"`
	Enabled  bool       ``
	Password string     ``
	Feeds    []FeedInfo `jsonapi:"relation,feeds"`
}

User represents a user/email address that can subscribe to Feeds

func (*User) SetPassword

func (u *User) SetPassword(pass string) error

SetPassword takes a plain text password, crypts it and sets the Password field to that.

type UserReport

type UserReport struct {
	ID         int64
	UserID     int64     `db:"user_id"`
	LastReport time.Time `db:"last_report"`
}

UserReport represents the last time we sent a report of stale or errored out feeds. Used to ensure that we don't spam users with them over restarts.

Jump to

Keyboard shortcuts

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