2018-01-28 14:55:43 +08:00
|
|
|
package database
|
|
|
|
|
|
|
|
import (
|
2018-01-29 16:00:37 +08:00
|
|
|
"database/sql"
|
2018-01-28 14:55:43 +08:00
|
|
|
"github.com/RadhiFadlillah/shiori/model"
|
|
|
|
)
|
|
|
|
|
2018-02-03 21:20:10 +08:00
|
|
|
// Database is interface for manipulating data in database.
|
2018-01-28 14:55:43 +08:00
|
|
|
type Database interface {
|
2018-02-03 21:20:10 +08:00
|
|
|
// SaveBookmark saves new bookmark to database.
|
2018-01-30 17:16:25 +08:00
|
|
|
SaveBookmark(bookmark model.Bookmark) (int64, error)
|
2018-02-03 21:20:10 +08:00
|
|
|
|
|
|
|
// GetBookmarks fetch list of bookmarks based on submitted indices.
|
2018-02-11 22:00:56 +08:00
|
|
|
GetBookmarks(options GetBookmarksOptions, indices ...string) ([]model.Bookmark, error)
|
2018-02-03 21:20:10 +08:00
|
|
|
|
|
|
|
// DeleteBookmarks removes all record with matching indices from database.
|
2018-01-29 08:40:29 +08:00
|
|
|
DeleteBookmarks(indices ...string) ([]int, []int, error)
|
2018-02-03 21:20:10 +08:00
|
|
|
|
|
|
|
// SearchBookmarks search bookmarks by the keyword or tags.
|
2018-01-29 21:45:27 +08:00
|
|
|
SearchBookmarks(keyword string, tags ...string) ([]model.Bookmark, error)
|
2018-02-03 21:20:10 +08:00
|
|
|
|
|
|
|
// UpdateBookmarks updates the saved bookmark in database.
|
2018-02-03 16:02:28 +08:00
|
|
|
UpdateBookmarks(bookmarks []model.Bookmark) error
|
2018-01-28 14:55:43 +08:00
|
|
|
}
|
|
|
|
|
2018-02-11 22:00:56 +08:00
|
|
|
type GetBookmarksOptions struct {
|
|
|
|
WithContents bool
|
|
|
|
OrderLatest bool
|
|
|
|
}
|
|
|
|
|
2018-01-28 14:55:43 +08:00
|
|
|
func checkError(err error) {
|
2018-01-29 16:00:37 +08:00
|
|
|
if err != nil && err != sql.ErrNoRows {
|
2018-01-28 14:55:43 +08:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|