2019-05-21 11:31:40 +08:00
|
|
|
package database
|
|
|
|
|
2019-05-22 00:24:11 +08:00
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
|
|
|
|
"github.com/go-shiori/shiori/internal/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetBookmarksOptions is options for fetching bookmarks from database.
|
|
|
|
type GetBookmarksOptions struct {
|
|
|
|
IDs []int
|
|
|
|
Tags []string
|
|
|
|
Keyword string
|
|
|
|
WithContent bool
|
|
|
|
OrderLatest bool
|
2019-05-27 18:01:53 +08:00
|
|
|
Limit int
|
|
|
|
Offset int
|
2019-05-22 00:24:11 +08:00
|
|
|
}
|
|
|
|
|
2019-05-21 11:31:40 +08:00
|
|
|
// DB is interface for accessing and manipulating data in database.
|
|
|
|
type DB interface {
|
2019-05-22 17:13:52 +08:00
|
|
|
// SaveBookmarks saves bookmarks data to database.
|
|
|
|
SaveBookmarks(bookmarks ...model.Bookmark) ([]model.Bookmark, error)
|
2019-05-22 00:24:11 +08:00
|
|
|
|
|
|
|
// GetBookmarks fetch list of bookmarks based on submitted options.
|
|
|
|
GetBookmarks(opts GetBookmarksOptions) ([]model.Bookmark, error)
|
|
|
|
|
2019-05-27 18:01:53 +08:00
|
|
|
// GetBookmarksCount get count of bookmarks in database.
|
|
|
|
GetBookmarksCount(opts GetBookmarksOptions) (int, error)
|
|
|
|
|
2019-05-22 09:13:52 +08:00
|
|
|
// DeleteBookmarks removes all record with matching ids from database.
|
|
|
|
DeleteBookmarks(ids ...int) error
|
|
|
|
|
2019-05-23 10:22:47 +08:00
|
|
|
// GetBookmark fetchs bookmark based on its ID or URL.
|
|
|
|
GetBookmark(id int, url string) (model.Bookmark, bool)
|
|
|
|
|
2019-05-27 18:01:53 +08:00
|
|
|
// GetAccounts fetch list of accounts with matching keyword.
|
|
|
|
GetAccounts(keyword string) ([]model.Account, error)
|
|
|
|
|
|
|
|
// GetAccount fetch account with matching username.
|
|
|
|
GetAccount(username string) (model.Account, bool)
|
|
|
|
|
2019-05-28 18:05:11 +08:00
|
|
|
// GetTags fetch list of tags and its frequency from database.
|
|
|
|
GetTags() ([]model.Tag, error)
|
|
|
|
|
2019-05-22 00:24:11 +08:00
|
|
|
// CreateNewID creates new id for specified table.
|
|
|
|
CreateNewID(table string) (int, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkError(err error) {
|
|
|
|
if err != nil && err != sql.ErrNoRows {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-05-21 11:31:40 +08:00
|
|
|
}
|