shiori/internal/database/database.go
2019-05-23 09:22:47 +07:00

41 lines
1 KiB
Go

package database
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
}
// DB is interface for accessing and manipulating data in database.
type DB interface {
// SaveBookmarks saves bookmarks data to database.
SaveBookmarks(bookmarks ...model.Bookmark) ([]model.Bookmark, error)
// GetBookmarks fetch list of bookmarks based on submitted options.
GetBookmarks(opts GetBookmarksOptions) ([]model.Bookmark, error)
// DeleteBookmarks removes all record with matching ids from database.
DeleteBookmarks(ids ...int) error
// GetBookmark fetchs bookmark based on its ID or URL.
GetBookmark(id int, url string) (model.Bookmark, bool)
// CreateNewID creates new id for specified table.
CreateNewID(table string) (int, error)
}
func checkError(err error) {
if err != nil && err != sql.ErrNoRows {
panic(err)
}
}