database

package
v0.0.0-...-3289fe5 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("Database already closed")

ErrClosed is returned when trying to take actions on a closed Database

Functions

This section is empty.

Types

type AddCategoryRequest

type AddCategoryRequest struct {
	Name       string `json:"name"`
	Title      string `json:"title"`
	HiddenNav  bool   `json:"hiddenNav"`
	HiddenMain bool   `json:"hiddenMain"`
}

AddCategoryRequest contains the information needed to create a category

type CurrentState

type CurrentState struct {
	Timestamp   int64               `json:"timestamp"`
	Items       []*structs.Item     `json:"items,omitempty"`
	Feeds       []*structs.Feed     `json:"feeds,omitempty"`
	Categoriess []*structs.Category `json:"categories,omitempty"`
	// Timestamps of the newest items in each feed
	NewestTimestamps map[int64]time.Time `json:"newestTimestamps,omitempty"`
}

CurrentState contains the initial data sent to the client

type Database

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

Database is the database for storing all persistent data for aw-rss

func NewDatabase

func NewDatabase(c config.Config) (dbase *Database, err error)

NewDatabase creates a new database instances around the provided sqlite3 DB

func (*Database) Close

func (d *Database) Close() error

Close closes the database, freeing all resources Requests in flight are allowed to complete but those that haven't started are cancelled

func (*Database) GetCurrentFeeds

func (d *Database) GetCurrentFeeds() ([]*structs.Feed, error)

GetCurrentFeeds returns the set of enabled feeds It's currently only used by the backend on initialization and as a guard against out of band edits.

func (*Database) GetCurrentState

func (d *Database) GetCurrentState() (*CurrentState, error)

GetCurrentState returns the current state of all "valid" entities in the DB

func (*Database) GetDisabledFeeds

func (d *Database) GetDisabledFeeds() ([]*structs.Feed, error)

GetDisabledFeeds returns all disabled feeds from the database for the admin page. There's no support for pagination or filtering as it's assumed the number of feeds will never be prohibitively large.

func (*Database) GetItems

func (d *Database) GetItems(
	req GetItemsRequest) (*GetItemsResponse, error)

GetItems returns the Items needed to fulfill the GetItemsRequest

func (*Database) GetUpdates

func (d *Database) GetUpdates(t time.Time) (*Updates, error)

GetUpdates gets all the updates since `t`

func (*Database) InsertItems

func (d *Database) InsertItems(items []*structs.Item) error

InsertItems inserts new items into the database if they aren't present. The order of the items matters, as item IDs are used to break timestamp ties when sorting on the frontend.

func (*Database) InsertNewCategory

func (d *Database) InsertNewCategory(req AddCategoryRequest) (
	*structs.Category, error)

InsertNewCategory creates and inserts a new category

func (*Database) InsertNewFeed

func (d *Database) InsertNewFeed(url string, userTitle string) (
	*structs.Feed, error)

InsertNewFeed creates and inserts a new feed from the url and user title

func (*Database) MarkItemsReadByFeed

func (d *Database) MarkItemsReadByFeed(feedID int64, maxID int64) (
	[]*structs.Item, error)

MarkItemsReadByFeed marks all items up to maxID as read for the feed

func (*Database) MutateCategory

func (d *Database) MutateCategory(
	id int64,
	fn func(*structs.Category) structs.EntityUpdate) (*structs.Category, error)

MutateCategory applies `fn` to one category in the DB and returns it

func (*Database) MutateFeed

func (d *Database) MutateFeed(
	id int64,
	fn func(*structs.Feed) structs.EntityUpdate) (*structs.Feed, error)

MutateFeed applies `fn` to one feed in the DB and returns it

func (*Database) MutateItem

func (d *Database) MutateItem(
	id int64,
	fn func(*structs.Item) structs.EntityUpdate) (*structs.Item, error)

MutateItem applies `fn` to one item from the DB and returns it

func (*Database) ReorderCategories

func (d *Database) ReorderCategories(ids []int64) (
	[]*structs.Category, error)

ReorderCategories sets the sortPosition on all references categories

type GetItemsRequest

type GetItemsRequest struct {
	// ID of the category, if any
	CategoryID *int64 `json:"categoryId"`
	// IDs of the Feeds, if any
	FeedIDs []int64 `json:"feedIds"`
	// Include feeds specified by FeedIDs in the response
	// Does not work for categories
	IncludeFeeds bool `json:"includeFeeds"`

	// If true fetch all unread items
	Unread bool `json:"unread"`
	// Note that they will be filtered by timestamp, but ordered by ID.
	ReadBeforeCount int `json:"readBeforeCount"`
	// Fetch _at least_ ReadBeforeCount items before this timestamp (exclusive)
	// Guaranteed that all existing read items between ReadBefore and the minimum
	// timestamp in the response are fetched.
	ReadBefore *time.Time `json:"readBefore"`

	// Fetch _all_ read items after this timestamp (inclusive)
	// This is used when backfilling on the frontend, but only in the rare
	// case where a category is open and a feed is added to it or re-enabled.
	ReadAfter *time.Time `json:"readAfter"`
}

GetItemsRequest is a request for items matching some constraints Items from disabled feeds will not be fetched unless they're specified in FeedIDs If both FeedIDs and CategoryID are absent, items from every enabled feed will be fetched

type GetItemsResponse

type GetItemsResponse struct {
	Items []*structs.Item `json:"items"`
	Feeds []*structs.Feed `json:"feeds,omitempty"`
}

GetItemsResponse is used to fulfill the GetItemsRequest

type Updates

type Updates struct {
	Timestamp  int64               `json:"timestamp,omitempty"`
	Items      []*structs.Item     `json:"items,omitempty"`
	Feeds      []*structs.Feed     `json:"feeds,omitempty"`
	Categories []*structs.Category `json:"categories,omitempty"`
	// When the client's state is too old and they should refresh instead
	MustRefresh bool `json:"mustRefresh,omitempty"`
}

Updates contains all the entities that have changed after a given time

Jump to

Keyboard shortcuts

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