database

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	// InsertBookmark inserts new bookmark to database.
	InsertBookmark(bookmark *model.Bookmark) error

	// GetBookmarks fetch list of bookmarks based on submitted ids.
	GetBookmarks(withContent bool, ids ...int) ([]model.Bookmark, error)

	// GetTags fetch list of tags and their frequency
	GetTags() ([]model.Tag, error)

	// DeleteBookmarks removes all record with matching ids from database.
	DeleteBookmarks(ids ...int) error

	// SearchBookmarks search bookmarks by the keyword or tags.
	SearchBookmarks(orderLatest bool, keyword string, tags ...string) ([]model.Bookmark, error)

	// UpdateBookmarks updates the saved bookmark in database.
	UpdateBookmarks(bookmarks ...model.Bookmark) ([]model.Bookmark, error)

	// CreateAccount creates new account in database
	CreateAccount(username, password string) error

	// 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)

	// DeleteAccounts removes all record with matching usernames
	DeleteAccounts(usernames ...string) error

	// GetBookmarkID fetchs bookmark ID based by its url
	GetBookmarkID(url string) int
}

Database is interface for manipulating data in database.

type XormDatabase

type XormDatabase struct {
	*xorm.Engine
	// contains filtered or unexported fields
}

XormDatabase is implementation of Database interface for connecting to database.

func OpenXormDatabase

func OpenXormDatabase(options *XormOptions) (*XormDatabase, error)

OpenXormDatabase creates and open connection to new database.

func (*XormDatabase) CreateAccount

func (db *XormDatabase) CreateAccount(username, password string) error

CreateAccount saves new account to database. Returns new ID and error if any happened.

func (*XormDatabase) DeleteAccounts

func (db *XormDatabase) DeleteAccounts(usernames ...string) error

DeleteAccounts removes all record with matching usernames

func (*XormDatabase) DeleteBookmarks

func (db *XormDatabase) DeleteBookmarks(ids ...int) error

DeleteBookmarks removes all record with matching ids from database.

func (*XormDatabase) GetAccount

func (db *XormDatabase) GetAccount(username string) (model.Account, error)

GetAccount fetch account with matching username

func (*XormDatabase) GetAccounts

func (db *XormDatabase) GetAccounts(keyword string) ([]model.Account, error)

GetAccounts fetch list of accounts with matching keyword

func (*XormDatabase) GetBookmarkID

func (db *XormDatabase) GetBookmarkID(url string) int

GetBookmarkID fetchs bookmark ID based by its url

func (*XormDatabase) GetBookmarks

func (db *XormDatabase) GetBookmarks(withContent bool, ids ...int) ([]model.Bookmark, error)

GetBookmarks fetch list of bookmarks based on submitted ids.

func (*XormDatabase) GetTags

func (db *XormDatabase) GetTags() ([]model.Tag, error)

GetTags fetch list of tags and their frequency

func (*XormDatabase) InsertBookmark

func (db *XormDatabase) InsertBookmark(bookmark *model.Bookmark) error

InsertBookmark inserts new bookmark to database. Returns new ID and error if any happened.

func (*XormDatabase) SearchBookmarks

func (db *XormDatabase) SearchBookmarks(orderLatest bool, keyword string, tags ...string) ([]model.Bookmark, error)

SearchBookmarks search bookmarks by the keyword or tags.

func (*XormDatabase) UpdateBookmarks

func (db *XormDatabase) UpdateBookmarks(bookmarks ...model.Bookmark) (result []model.Bookmark, err error)

UpdateBookmarks updates the saved bookmark in database.

type XormOptions added in v0.8.0

type XormOptions struct {
	DbDsn   string
	DbType  string
	ShowSQL bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL