Documentation ¶
Index ¶
- type DB
- type GetAccountsOptions
- type GetBookmarksOptions
- type MySQLDatabase
- func (db *MySQLDatabase) CreateNewID(table string) (int, error)
- func (db *MySQLDatabase) DeleteAccounts(usernames ...string) (err error)
- func (db *MySQLDatabase) DeleteBookmarks(ids ...int) (err error)
- func (db *MySQLDatabase) GetAccount(username string) (model.Account, bool)
- func (db *MySQLDatabase) GetAccounts(opts GetAccountsOptions) ([]model.Account, error)
- func (db *MySQLDatabase) GetBookmark(id int, url string) (model.Bookmark, bool)
- func (db *MySQLDatabase) GetBookmarks(opts GetBookmarksOptions) ([]model.Bookmark, error)
- func (db *MySQLDatabase) GetBookmarksCount(opts GetBookmarksOptions) (int, error)
- func (db *MySQLDatabase) GetTags() ([]model.Tag, error)
- func (db *MySQLDatabase) RenameTag(id int, newName string) error
- func (db *MySQLDatabase) SaveAccount(account model.Account) (err error)
- func (db *MySQLDatabase) SaveBookmarks(bookmarks ...model.Bookmark) (result []model.Bookmark, err error)
- type OrderMethod
- type PGDatabase
- func (db *PGDatabase) CreateNewID(table string) (int, error)
- func (db *PGDatabase) DeleteAccounts(usernames ...string) (err error)
- func (db *PGDatabase) DeleteBookmarks(ids ...int) (err error)
- func (db *PGDatabase) GetAccount(username string) (model.Account, bool)
- func (db *PGDatabase) GetAccounts(opts GetAccountsOptions) ([]model.Account, error)
- func (db *PGDatabase) GetBookmark(id int, url string) (model.Bookmark, bool)
- func (db *PGDatabase) GetBookmarks(opts GetBookmarksOptions) ([]model.Bookmark, error)
- func (db *PGDatabase) GetBookmarksCount(opts GetBookmarksOptions) (int, error)
- func (db *PGDatabase) GetTags() ([]model.Tag, error)
- func (db *PGDatabase) RenameTag(id int, newName string) error
- func (db *PGDatabase) SaveAccount(account model.Account) (err error)
- func (db *PGDatabase) SaveBookmarks(bookmarks ...model.Bookmark) (result []model.Bookmark, err error)
- type SQLiteDatabase
- func (db *SQLiteDatabase) CreateNewID(table string) (int, error)
- func (db *SQLiteDatabase) DeleteAccounts(usernames ...string) (err error)
- func (db *SQLiteDatabase) DeleteBookmarks(ids ...int) (err error)
- func (db *SQLiteDatabase) GetAccount(username string) (model.Account, bool)
- func (db *SQLiteDatabase) GetAccounts(opts GetAccountsOptions) ([]model.Account, error)
- func (db *SQLiteDatabase) GetBookmark(id int, url string) (model.Bookmark, bool)
- func (db *SQLiteDatabase) GetBookmarks(opts GetBookmarksOptions) ([]model.Bookmark, error)
- func (db *SQLiteDatabase) GetBookmarksCount(opts GetBookmarksOptions) (int, error)
- func (db *SQLiteDatabase) GetTags() ([]model.Tag, error)
- func (db *SQLiteDatabase) RenameTag(id int, newName string) error
- func (db *SQLiteDatabase) SaveAccount(account model.Account) (err error)
- func (db *SQLiteDatabase) SaveBookmarks(bookmarks ...model.Bookmark) (result []model.Bookmark, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
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) // GetBookmarksCount get count of bookmarks in database. GetBookmarksCount(opts GetBookmarksOptions) (int, 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) // SaveAccount saves new account in database SaveAccount(model.Account) error // GetAccounts fetch list of account (without its password) with matching keyword. GetAccounts(opts GetAccountsOptions) ([]model.Account, error) // GetAccount fetch account with matching username. GetAccount(username string) (model.Account, bool) // DeleteAccounts removes all record with matching usernames DeleteAccounts(usernames ...string) error // GetTags fetch list of tags and its frequency from database. GetTags() ([]model.Tag, error) // RenameTag change the name of a tag. RenameTag(id int, newName string) error // CreateNewID creates new id for specified table. CreateNewID(table string) (int, error) }
DB is interface for accessing and manipulating data in database.
type GetAccountsOptions ¶
GetAccountsOptions is options for fetching accounts from database.
type GetBookmarksOptions ¶
type GetBookmarksOptions struct { IDs []int Tags []string ExcludedTags []string Keyword string WithContent bool OrderMethod OrderMethod Limit int Offset int }
GetBookmarksOptions is options for fetching bookmarks from database.
type MySQLDatabase ¶
MySQLDatabase is implementation of Database interface for connecting to MySQL or MariaDB database.
func OpenMySQLDatabase ¶
func OpenMySQLDatabase(connString string) (mysqlDB *MySQLDatabase, err error)
OpenMySQLDatabase creates and opens connection to a MySQL Database.
func (*MySQLDatabase) CreateNewID ¶
func (db *MySQLDatabase) CreateNewID(table string) (int, error)
CreateNewID creates new ID for specified table
func (*MySQLDatabase) DeleteAccounts ¶
func (db *MySQLDatabase) DeleteAccounts(usernames ...string) (err error)
DeleteAccounts removes all record with matching usernames.
func (*MySQLDatabase) DeleteBookmarks ¶
func (db *MySQLDatabase) DeleteBookmarks(ids ...int) (err error)
DeleteBookmarks removes all record with matching ids from database.
func (*MySQLDatabase) GetAccount ¶
func (db *MySQLDatabase) GetAccount(username string) (model.Account, bool)
GetAccount fetch account with matching username. Returns the account and boolean whether it's exist or not.
func (*MySQLDatabase) GetAccounts ¶
func (db *MySQLDatabase) GetAccounts(opts GetAccountsOptions) ([]model.Account, error)
GetAccounts fetch list of account (without its password) based on submitted options.
func (*MySQLDatabase) GetBookmark ¶
GetBookmark fetchs bookmark based on its ID or URL. Returns the bookmark and boolean whether it's exist or not.
func (*MySQLDatabase) GetBookmarks ¶
func (db *MySQLDatabase) GetBookmarks(opts GetBookmarksOptions) ([]model.Bookmark, error)
GetBookmarks fetch list of bookmarks based on submitted options.
func (*MySQLDatabase) GetBookmarksCount ¶
func (db *MySQLDatabase) GetBookmarksCount(opts GetBookmarksOptions) (int, error)
GetBookmarksCount fetch count of bookmarks based on submitted options.
func (*MySQLDatabase) GetTags ¶
func (db *MySQLDatabase) GetTags() ([]model.Tag, error)
GetTags fetch list of tags and their frequency.
func (*MySQLDatabase) RenameTag ¶
func (db *MySQLDatabase) RenameTag(id int, newName string) error
RenameTag change the name of a tag.
func (*MySQLDatabase) SaveAccount ¶
func (db *MySQLDatabase) SaveAccount(account model.Account) (err error)
SaveAccount saves new account to database. Returns error if any happened.
func (*MySQLDatabase) SaveBookmarks ¶
func (db *MySQLDatabase) SaveBookmarks(bookmarks ...model.Bookmark) (result []model.Bookmark, err error)
SaveBookmarks saves new or updated bookmarks to database. Returns the saved ID and error message if any happened.
type OrderMethod ¶
type OrderMethod int
OrderMethod is the order method for getting bookmarks
const ( // DefaultOrder is oldest to newest. DefaultOrder OrderMethod = iota // ByLastAdded is from newest addition to the oldest. ByLastAdded // ByLastModified is from latest modified to the oldest. ByLastModified )
type PGDatabase ¶
PGDatabase is implementation of Database interface for connecting to PostgreSQL database.
func OpenPGDatabase ¶
func OpenPGDatabase(connString string) (pgDB *PGDatabase, err error)
OpenPGDatabase creates and opens connection to a PostgreSQL Database.
func (*PGDatabase) CreateNewID ¶
func (db *PGDatabase) CreateNewID(table string) (int, error)
CreateNewID creates new ID for specified table
func (*PGDatabase) DeleteAccounts ¶
func (db *PGDatabase) DeleteAccounts(usernames ...string) (err error)
DeleteAccounts removes all record with matching usernames.
func (*PGDatabase) DeleteBookmarks ¶
func (db *PGDatabase) DeleteBookmarks(ids ...int) (err error)
DeleteBookmarks removes all record with matching ids from database.
func (*PGDatabase) GetAccount ¶
func (db *PGDatabase) GetAccount(username string) (model.Account, bool)
GetAccount fetch account with matching username. Returns the account and boolean whether it's exist or not.
func (*PGDatabase) GetAccounts ¶
func (db *PGDatabase) GetAccounts(opts GetAccountsOptions) ([]model.Account, error)
GetAccounts fetch list of account (without its password) based on submitted options.
func (*PGDatabase) GetBookmark ¶
GetBookmark fetchs bookmark based on its ID or URL. Returns the bookmark and boolean whether it's exist or not.
func (*PGDatabase) GetBookmarks ¶
func (db *PGDatabase) GetBookmarks(opts GetBookmarksOptions) ([]model.Bookmark, error)
GetBookmarks fetch list of bookmarks based on submitted options.
func (*PGDatabase) GetBookmarksCount ¶
func (db *PGDatabase) GetBookmarksCount(opts GetBookmarksOptions) (int, error)
GetBookmarksCount fetch count of bookmarks based on submitted options.
func (*PGDatabase) GetTags ¶
func (db *PGDatabase) GetTags() ([]model.Tag, error)
GetTags fetch list of tags and their frequency.
func (*PGDatabase) RenameTag ¶
func (db *PGDatabase) RenameTag(id int, newName string) error
RenameTag change the name of a tag.
func (*PGDatabase) SaveAccount ¶
func (db *PGDatabase) SaveAccount(account model.Account) (err error)
SaveAccount saves new account to database. Returns error if any happened.
func (*PGDatabase) SaveBookmarks ¶
func (db *PGDatabase) SaveBookmarks(bookmarks ...model.Bookmark) (result []model.Bookmark, err error)
SaveBookmarks saves new or updated bookmarks to database. Returns the saved ID and error message if any happened.
type SQLiteDatabase ¶
SQLiteDatabase is implementation of Database interface for connecting to SQLite3 database.
func OpenSQLiteDatabase ¶
func OpenSQLiteDatabase(databasePath string) (sqliteDB *SQLiteDatabase, err error)
OpenSQLiteDatabase creates and open connection to new SQLite3 database.
func (*SQLiteDatabase) CreateNewID ¶
func (db *SQLiteDatabase) CreateNewID(table string) (int, error)
CreateNewID creates new ID for specified table
func (*SQLiteDatabase) DeleteAccounts ¶
func (db *SQLiteDatabase) DeleteAccounts(usernames ...string) (err error)
DeleteAccounts removes all record with matching usernames.
func (*SQLiteDatabase) DeleteBookmarks ¶
func (db *SQLiteDatabase) DeleteBookmarks(ids ...int) (err error)
DeleteBookmarks removes all record with matching ids from database.
func (*SQLiteDatabase) GetAccount ¶
func (db *SQLiteDatabase) GetAccount(username string) (model.Account, bool)
GetAccount fetch account with matching username. Returns the account and boolean whether it's exist or not.
func (*SQLiteDatabase) GetAccounts ¶
func (db *SQLiteDatabase) GetAccounts(opts GetAccountsOptions) ([]model.Account, error)
GetAccounts fetch list of account (without its password) based on submitted options.
func (*SQLiteDatabase) GetBookmark ¶
GetBookmark fetchs bookmark based on its ID or URL. Returns the bookmark and boolean whether it's exist or not.
func (*SQLiteDatabase) GetBookmarks ¶
func (db *SQLiteDatabase) GetBookmarks(opts GetBookmarksOptions) ([]model.Bookmark, error)
GetBookmarks fetch list of bookmarks based on submitted options.
func (*SQLiteDatabase) GetBookmarksCount ¶
func (db *SQLiteDatabase) GetBookmarksCount(opts GetBookmarksOptions) (int, error)
GetBookmarksCount fetch count of bookmarks based on submitted options.
func (*SQLiteDatabase) GetTags ¶
func (db *SQLiteDatabase) GetTags() ([]model.Tag, error)
GetTags fetch list of tags and their frequency.
func (*SQLiteDatabase) RenameTag ¶
func (db *SQLiteDatabase) RenameTag(id int, newName string) error
RenameTag change the name of a tag.
func (*SQLiteDatabase) SaveAccount ¶
func (db *SQLiteDatabase) SaveAccount(account model.Account) (err error)
SaveAccount saves new account to database. Returns error if any happened.
func (*SQLiteDatabase) SaveBookmarks ¶
func (db *SQLiteDatabase) SaveBookmarks(bookmarks ...model.Bookmark) (result []model.Bookmark, err error)
SaveBookmarks saves new or updated bookmarks to database. Returns the saved ID and error message if any happened.