storage

package
v0.0.0-...-5365f31 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package storage implements a set of functions to interact with the database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EntryPaginationBuilder

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

EntryPaginationBuilder is a builder for entry prev/next queries.

func NewEntryPaginationBuilder

func NewEntryPaginationBuilder(store *Storage, userID, entryID int64, direction string) *EntryPaginationBuilder

NewEntryPaginationBuilder returns a new EntryPaginationBuilder.

func (*EntryPaginationBuilder) Entries

func (e *EntryPaginationBuilder) Entries() (*model.Entry, *model.Entry, error)

Entries returns previous and next entries.

func (*EntryPaginationBuilder) WithCategoryID

func (e *EntryPaginationBuilder) WithCategoryID(categoryID int64)

WithCategoryID adds category_id to the condition.

func (*EntryPaginationBuilder) WithFeedID

func (e *EntryPaginationBuilder) WithFeedID(feedID int64)

WithFeedID adds feed_id to the condition.

func (*EntryPaginationBuilder) WithSearchQuery

func (e *EntryPaginationBuilder) WithSearchQuery(query string)

WithSearchQuery adds full-text search query to the condition.

func (*EntryPaginationBuilder) WithStarred

func (e *EntryPaginationBuilder) WithStarred()

WithStarred adds starred to the condition.

func (*EntryPaginationBuilder) WithStatus

func (e *EntryPaginationBuilder) WithStatus(status string)

WithStatus adds status to the condition.

type EntryQueryBuilder

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

EntryQueryBuilder builds a SQL query to fetch entries.

func NewEntryQueryBuilder

func NewEntryQueryBuilder(store *Storage, userID int64) *EntryQueryBuilder

NewEntryQueryBuilder returns a new EntryQueryBuilder.

func (*EntryQueryBuilder) AfterDate

func (e *EntryQueryBuilder) AfterDate(date time.Time) *EntryQueryBuilder

AfterDate adds a condition > published_at

func (*EntryQueryBuilder) AfterEntryID

func (e *EntryQueryBuilder) AfterEntryID(entryID int64) *EntryQueryBuilder

AfterEntryID adds a condition > entryID.

func (*EntryQueryBuilder) BeforeDate

func (e *EntryQueryBuilder) BeforeDate(date time.Time) *EntryQueryBuilder

BeforeDate adds a condition < published_at

func (*EntryQueryBuilder) BeforeEntryID

func (e *EntryQueryBuilder) BeforeEntryID(entryID int64) *EntryQueryBuilder

BeforeEntryID adds a condition < entryID.

func (*EntryQueryBuilder) CountEntries

func (e *EntryQueryBuilder) CountEntries() (count int, err error)

CountEntries count the number of entries that match the condition.

func (*EntryQueryBuilder) GetEntries

func (e *EntryQueryBuilder) GetEntries() (model.Entries, error)

GetEntries returns a list of entries that match the condition.

func (*EntryQueryBuilder) GetEntry

func (e *EntryQueryBuilder) GetEntry() (*model.Entry, error)

GetEntry returns a single entry that match the condition.

func (*EntryQueryBuilder) GetEntryIDs

func (e *EntryQueryBuilder) GetEntryIDs() ([]int64, error)

GetEntryIDs returns a list of entry IDs that match the condition.

func (*EntryQueryBuilder) WithCategoryID

func (e *EntryQueryBuilder) WithCategoryID(categoryID int64) *EntryQueryBuilder

WithCategoryID set the categoryID.

func (*EntryQueryBuilder) WithDirection

func (e *EntryQueryBuilder) WithDirection(direction string) *EntryQueryBuilder

WithDirection set the sorting direction.

func (*EntryQueryBuilder) WithEntryID

func (e *EntryQueryBuilder) WithEntryID(entryID int64) *EntryQueryBuilder

WithEntryID set the entryID.

func (*EntryQueryBuilder) WithEntryIDs

func (e *EntryQueryBuilder) WithEntryIDs(entryIDs []int64) *EntryQueryBuilder

WithEntryIDs adds a condition to fetch only the given entry IDs.

func (*EntryQueryBuilder) WithFeedID

func (e *EntryQueryBuilder) WithFeedID(feedID int64) *EntryQueryBuilder

WithFeedID set the feedID.

func (*EntryQueryBuilder) WithLimit

func (e *EntryQueryBuilder) WithLimit(limit int) *EntryQueryBuilder

WithLimit set the limit.

func (*EntryQueryBuilder) WithOffset

func (e *EntryQueryBuilder) WithOffset(offset int) *EntryQueryBuilder

WithOffset set the offset.

func (*EntryQueryBuilder) WithOrder

func (e *EntryQueryBuilder) WithOrder(order string) *EntryQueryBuilder

WithOrder set the sorting order.

func (*EntryQueryBuilder) WithSearchQuery

func (e *EntryQueryBuilder) WithSearchQuery(query string) *EntryQueryBuilder

WithSearchQuery adds full-text search query to the condition.

func (*EntryQueryBuilder) WithStarred

func (e *EntryQueryBuilder) WithStarred() *EntryQueryBuilder

WithStarred adds starred filter.

func (*EntryQueryBuilder) WithStatus

func (e *EntryQueryBuilder) WithStatus(status string) *EntryQueryBuilder

WithStatus set the entry status.

func (*EntryQueryBuilder) WithoutStatus

func (e *EntryQueryBuilder) WithoutStatus(status string) *EntryQueryBuilder

WithoutStatus set the entry status that should not be returned.

type Storage

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

Storage handles all operations related to the database.

func NewStorage

func NewStorage(databaseURL string, maxOpenConns int) *Storage

NewStorage returns a new Storage.

func (*Storage) AnotherCategoryExists

func (s *Storage) AnotherCategoryExists(userID, categoryID int64, title string) bool

AnotherCategoryExists checks if another category exists with the same title.

func (*Storage) AnotherUserExists

func (s *Storage) AnotherUserExists(userID int64, username string) bool

AnotherUserExists checks if another user exists with the given username.

func (*Storage) ArchiveEntries

func (s *Storage) ArchiveEntries() error

ArchiveEntries changes the status of read items to "removed" after 60 days.

func (*Storage) Categories

func (s *Storage) Categories(userID int64) (model.Categories, error)

Categories returns all categories that belongs to the given user.

func (*Storage) CategoriesWithFeedCount

func (s *Storage) CategoriesWithFeedCount(userID int64) (model.Categories, error)

CategoriesWithFeedCount returns all categories with the number of feeds.

func (*Storage) Category

func (s *Storage) Category(userID, categoryID int64) (*model.Category, error)

Category returns a category from the database.

func (*Storage) CategoryByTitle

func (s *Storage) CategoryByTitle(userID int64, title string) (*model.Category, error)

CategoryByTitle finds a category by the title.

func (*Storage) CategoryExists

func (s *Storage) CategoryExists(userID, categoryID int64) bool

CategoryExists checks if the given category exists into the database.

func (*Storage) CheckPassword

func (s *Storage) CheckPassword(username, password string) error

CheckPassword validate the hashed password.

func (*Storage) CleanOldSessions

func (s *Storage) CleanOldSessions() int64

CleanOldSessions removes sessions older than 30 days.

func (*Storage) CleanOldUserSessions

func (s *Storage) CleanOldUserSessions() int64

CleanOldUserSessions removes user sessions older than 30 days.

func (*Storage) Close

func (s *Storage) Close()

Close closes all database connections.

func (*Storage) CountFeeds

func (s *Storage) CountFeeds(userID int64) int

CountFeeds returns the number of feeds that belongs to the given user.

func (*Storage) CountUnreadEntries

func (s *Storage) CountUnreadEntries(userID int64) int

CountUnreadEntries returns the number of unread entries.

func (*Storage) CreateCategory

func (s *Storage) CreateCategory(category *model.Category) error

CreateCategory creates a new category.

func (*Storage) CreateEnclosure

func (s *Storage) CreateEnclosure(enclosure *model.Enclosure) error

CreateEnclosure creates a new attachment.

func (*Storage) CreateFeed

func (s *Storage) CreateFeed(feed *model.Feed) error

CreateFeed creates a new feed.

func (*Storage) CreateFeedIcon

func (s *Storage) CreateFeedIcon(feed *model.Feed, icon *model.Icon) error

CreateFeedIcon creates an icon and associate the icon to the given feed.

func (*Storage) CreateIcon

func (s *Storage) CreateIcon(icon *model.Icon) error

CreateIcon creates a new icon.

func (*Storage) CreateIntegration

func (s *Storage) CreateIntegration(userID int64) error

CreateIntegration creates initial user integration settings.

func (*Storage) CreateSession

func (s *Storage) CreateSession() (*model.Session, error)

CreateSession creates a new session.

func (*Storage) CreateUser

func (s *Storage) CreateUser(user *model.User) (err error)

CreateUser creates a new user.

func (*Storage) CreateUserSession

func (s *Storage) CreateUserSession(username, userAgent, ip string) (sessionID string, userID int64, err error)

CreateUserSession creates a new sessions.

func (*Storage) EntryURLExists

func (s *Storage) EntryURLExists(userID int64, entryURL string) bool

EntryURLExists returns true if an entry with this URL already exists.

func (*Storage) FeedByID

func (s *Storage) FeedByID(userID, feedID int64) (*model.Feed, error)

FeedByID returns a feed by the ID.

func (*Storage) FeedExists

func (s *Storage) FeedExists(userID, feedID int64) bool

FeedExists checks if the given feed exists.

func (*Storage) FeedURLExists

func (s *Storage) FeedURLExists(userID int64, feedURL string) bool

FeedURLExists checks if feed URL already exists.

func (*Storage) Feeds

func (s *Storage) Feeds(userID int64) (model.Feeds, error)

Feeds returns all feeds of the given user.

func (*Storage) FirstCategory

func (s *Storage) FirstCategory(userID int64) (*model.Category, error)

FirstCategory returns the first category for the given user.

func (*Storage) FlushAllSessions

func (s *Storage) FlushAllSessions() (err error)

FlushAllSessions removes all sessions from the database.

func (*Storage) FlushHistory

func (s *Storage) FlushHistory(userID int64) error

FlushHistory set all entries with the status "read" to "removed".

func (*Storage) GetEnclosures

func (s *Storage) GetEnclosures(entryID int64) (model.EnclosureList, error)

GetEnclosures returns all attachments for the given entry.

func (*Storage) HasDuplicateFeverUsername

func (s *Storage) HasDuplicateFeverUsername(userID int64, feverUsername string) bool

HasDuplicateFeverUsername checks if another user have the same fever username.

func (*Storage) HasIcon

func (s *Storage) HasIcon(feedID int64) bool

HasIcon checks if the given feed has an icon.

func (*Storage) HasPassword

func (s *Storage) HasPassword(userID int64) (bool, error)

HasPassword returns true if the given user has a password defined.

func (*Storage) HasSaveEntry

func (s *Storage) HasSaveEntry(userID int64) (result bool)

HasSaveEntry returns true if the given user can save articles to third-parties.

func (*Storage) IconByFeedID

func (s *Storage) IconByFeedID(userID, feedID int64) (*model.Icon, error)

IconByFeedID returns a feed icon.

func (*Storage) IconByHash

func (s *Storage) IconByHash(icon *model.Icon) error

IconByHash returns an icon by the hash (checksum).

func (*Storage) IconByID

func (s *Storage) IconByID(iconID int64) (*model.Icon, error)

IconByID returns an icon by the ID.

func (*Storage) Icons

func (s *Storage) Icons(userID int64) (model.Icons, error)

Icons returns all icons tht belongs to a user.

func (*Storage) Integration

func (s *Storage) Integration(userID int64) (*model.Integration, error)

Integration returns user integration settings.

func (*Storage) IsEnclosureExists

func (s *Storage) IsEnclosureExists(enclosure *model.Enclosure) bool

IsEnclosureExists checks if an attachment exists.

func (*Storage) MarkAllAsRead

func (s *Storage) MarkAllAsRead(userID int64) error

MarkAllAsRead set all entries with the status "unread" to "read".

func (*Storage) Migrate

func (s *Storage) Migrate()

Migrate run database migrations.

func (*Storage) NewBatch

func (s *Storage) NewBatch(batchSize int) (jobs model.JobList, err error)

NewBatch returns a serie of jobs.

func (*Storage) NewEntryQueryBuilder

func (s *Storage) NewEntryQueryBuilder(userID int64) *EntryQueryBuilder

NewEntryQueryBuilder returns a new EntryQueryBuilder

func (*Storage) NewUserBatch

func (s *Storage) NewUserBatch(userID int64, batchSize int) (jobs model.JobList, err error)

NewUserBatch returns a serie of jobs but only for a given user.

func (*Storage) RemoveCategory

func (s *Storage) RemoveCategory(userID, categoryID int64) error

RemoveCategory deletes a category.

func (*Storage) RemoveExtraField

func (s *Storage) RemoveExtraField(userID int64, field string) error

RemoveExtraField deletes an extra field for the given user.

func (*Storage) RemoveFeed

func (s *Storage) RemoveFeed(userID, feedID int64) error

RemoveFeed removes a feed.

func (*Storage) RemoveUser

func (s *Storage) RemoveUser(userID int64) error

RemoveUser deletes a user.

func (*Storage) RemoveUserSessionByID

func (s *Storage) RemoveUserSessionByID(userID, sessionID int64) error

RemoveUserSessionByID remove a session by using the ID.

func (*Storage) RemoveUserSessionByToken

func (s *Storage) RemoveUserSessionByToken(userID int64, token string) error

RemoveUserSessionByToken remove a session by using the token.

func (*Storage) ResetFeedErrors

func (s *Storage) ResetFeedErrors() error

ResetFeedErrors removes all feed errors.

func (*Storage) Session

func (s *Storage) Session(id string) (*model.Session, error)

Session returns the given session.

func (*Storage) SetEntriesStatus

func (s *Storage) SetEntriesStatus(userID int64, entryIDs []int64, status string) error

SetEntriesStatus update the status of the given list of entries.

func (*Storage) SetLastLogin

func (s *Storage) SetLastLogin(userID int64) error

SetLastLogin updates the last login date of a user.

func (*Storage) Timezones

func (s *Storage) Timezones() (map[string]string, error)

Timezones returns all timezones supported by the database.

func (*Storage) ToggleBookmark

func (s *Storage) ToggleBookmark(userID int64, entryID int64) error

ToggleBookmark toggles entry bookmark value.

func (*Storage) UpdateCategory

func (s *Storage) UpdateCategory(category *model.Category) error

UpdateCategory updates an existing category.

func (*Storage) UpdateEnclosures

func (s *Storage) UpdateEnclosures(enclosures model.EnclosureList) error

UpdateEnclosures add missing attachments while updating a feed.

func (*Storage) UpdateEntries

func (s *Storage) UpdateEntries(userID, feedID int64, entries model.Entries, updateExistingEntries bool) (err error)

UpdateEntries updates a list of entries while refreshing a feed.

func (*Storage) UpdateEntryContent

func (s *Storage) UpdateEntryContent(entry *model.Entry) error

UpdateEntryContent updates entry content.

func (*Storage) UpdateExtraField

func (s *Storage) UpdateExtraField(userID int64, field, value string) error

UpdateExtraField updates an extra field of the given user.

func (*Storage) UpdateFeed

func (s *Storage) UpdateFeed(feed *model.Feed) (err error)

UpdateFeed updates an existing feed.

func (*Storage) UpdateIntegration

func (s *Storage) UpdateIntegration(integration *model.Integration) error

UpdateIntegration saves user integration settings.

func (*Storage) UpdateSessionField

func (s *Storage) UpdateSessionField(sessionID, field string, value interface{}) error

UpdateSessionField updates only one session field.

func (*Storage) UpdateUser

func (s *Storage) UpdateUser(user *model.User) error

UpdateUser updates a user.

func (*Storage) UserByExtraField

func (s *Storage) UserByExtraField(field, value string) (*model.User, error)

UserByExtraField finds a user by an extra field value.

func (*Storage) UserByFeverToken

func (s *Storage) UserByFeverToken(token string) (*model.User, error)

UserByFeverToken returns a user by using the Fever API token.

func (*Storage) UserByID

func (s *Storage) UserByID(userID int64) (*model.User, error)

UserByID finds a user by the ID.

func (*Storage) UserByUsername

func (s *Storage) UserByUsername(username string) (*model.User, error)

UserByUsername finds a user by the username.

func (*Storage) UserExists

func (s *Storage) UserExists(username string) bool

UserExists checks if a user exists by using the given username.

func (*Storage) UserLanguage

func (s *Storage) UserLanguage(userID int64) (language string, err error)

UserLanguage returns the language of the given user.

func (*Storage) UserSessionByToken

func (s *Storage) UserSessionByToken(token string) (*model.UserSession, error)

UserSessionByToken finds a session by the token.

func (*Storage) UserSessions

func (s *Storage) UserSessions(userID int64) (model.UserSessions, error)

UserSessions returns the list of sessions for the given user.

func (*Storage) Users

func (s *Storage) Users() (model.Users, error)

Users returns all users.

Jump to

Keyboard shortcuts

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