2018-01-28 14:55:43 +08:00
|
|
|
package database
|
|
|
|
|
|
|
|
import (
|
2018-01-29 16:00:37 +08:00
|
|
|
"database/sql"
|
2018-03-03 17:50:54 +08:00
|
|
|
|
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-02-20 17:48:02 +08:00
|
|
|
CreateBookmark(bookmark model.Bookmark) (int64, error)
|
2018-02-03 21:20:10 +08:00
|
|
|
|
|
|
|
// GetBookmarks fetch list of bookmarks based on submitted indices.
|
2018-02-22 21:45:43 +08:00
|
|
|
GetBookmarks(withContent bool, indices ...string) ([]model.Bookmark, error)
|
2018-02-03 21:20:10 +08:00
|
|
|
|
2018-05-18 17:18:38 +08:00
|
|
|
// GetTags fetch list of tags and their frequency
|
2018-03-06 16:06:20 +08:00
|
|
|
GetTags() ([]model.Tag, error)
|
|
|
|
|
2018-05-18 17:18:38 +08:00
|
|
|
//GetNewID get new id for specified table
|
|
|
|
GetNewID(table string) (int64, error)
|
|
|
|
|
2018-02-03 21:20:10 +08:00
|
|
|
// DeleteBookmarks removes all record with matching indices from database.
|
2018-03-05 12:02:36 +08:00
|
|
|
DeleteBookmarks(indices ...string) error
|
2018-02-03 21:20:10 +08:00
|
|
|
|
|
|
|
// SearchBookmarks search bookmarks by the keyword or tags.
|
2018-02-23 18:07:18 +08:00
|
|
|
SearchBookmarks(orderLatest bool, keyword string, tags ...string) ([]model.Bookmark, error)
|
2018-02-03 21:20:10 +08:00
|
|
|
|
|
|
|
// UpdateBookmarks updates the saved bookmark in database.
|
2018-04-28 22:02:36 +08:00
|
|
|
UpdateBookmarks(bookmarks ...model.Bookmark) ([]model.Bookmark, error)
|
2018-02-20 17:48:02 +08:00
|
|
|
|
|
|
|
// CreateAccount creates new account in database
|
|
|
|
CreateAccount(username, password string) error
|
|
|
|
|
2018-04-28 22:02:36 +08:00
|
|
|
// GetAccount fetch account with matching username
|
|
|
|
GetAccount(username string) (model.Account, error)
|
|
|
|
|
|
|
|
// GetAccounts fetch list of accounts with matching keyword
|
|
|
|
GetAccounts(keyword string) ([]model.Account, error)
|
2018-02-20 17:48:02 +08:00
|
|
|
|
|
|
|
// DeleteAccounts removes all record with matching usernames
|
|
|
|
DeleteAccounts(usernames ...string) error
|
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)
|
|
|
|
}
|
|
|
|
}
|