database

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB interface {
	// Migrate runs migrations for this database
	Migrate() error

	// SaveBookmarks saves bookmarks data to database.
	SaveBookmarks(ctx context.Context, create bool, bookmarks ...model.BookmarkDTO) ([]model.BookmarkDTO, error)

	// GetBookmarks fetch list of bookmarks based on submitted options.
	GetBookmarks(ctx context.Context, opts GetBookmarksOptions) ([]model.BookmarkDTO, error)

	// GetBookmarksCount get count of bookmarks in database.
	GetBookmarksCount(ctx context.Context, opts GetBookmarksOptions) (int, error)

	// DeleteBookmarks removes all record with matching ids from database.
	DeleteBookmarks(ctx context.Context, ids ...int) error

	// GetBookmark fetches bookmark based on its ID or URL.
	GetBookmark(ctx context.Context, id int, url string) (model.BookmarkDTO, bool, error)

	// SaveAccount saves new account in database
	SaveAccount(ctx context.Context, a model.Account) error

	// SaveAccountSettings saves settings for specific user in database
	SaveAccountSettings(ctx context.Context, a model.Account) error

	// GetAccounts fetch list of account (without its password) with matching keyword.
	GetAccounts(ctx context.Context, opts GetAccountsOptions) ([]model.Account, error)

	// GetAccount fetch account with matching username.
	GetAccount(ctx context.Context, username string) (model.Account, bool, error)

	// DeleteAccounts removes all record with matching usernames
	DeleteAccounts(ctx context.Context, usernames ...string) error

	// CreateTags creates new tags in database.
	CreateTags(ctx context.Context, tags ...model.Tag) error

	// GetTags fetch list of tags and its frequency from database.
	GetTags(ctx context.Context) ([]model.Tag, error)

	// RenameTag change the name of a tag.
	RenameTag(ctx context.Context, id int, newName string) error
}

DB is interface for accessing and manipulating data in database.

func Connect added in v1.6.0

func Connect(ctx context.Context, dbURL string) (DB, error)

Connect connects to database based on submitted database URL.

type GetAccountsOptions

type GetAccountsOptions struct {
	Keyword string
	Owner   bool
}

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

type MySQLDatabase struct {
	// contains filtered or unexported fields
}

MySQLDatabase is implementation of Database interface for connecting to MySQL or MariaDB database.

func OpenMySQLDatabase

func OpenMySQLDatabase(ctx context.Context, connString string) (mysqlDB *MySQLDatabase, err error)

OpenMySQLDatabase creates and opens connection to a MySQL Database.

func (*MySQLDatabase) CreateTags added in v1.6.0

func (db *MySQLDatabase) CreateTags(ctx context.Context, tags ...model.Tag) error

CreateTags creates new tags from submitted objects.

func (*MySQLDatabase) DeleteAccounts

func (db *MySQLDatabase) DeleteAccounts(ctx context.Context, usernames ...string) error

DeleteAccounts removes all record with matching usernames.

func (*MySQLDatabase) DeleteBookmarks

func (db *MySQLDatabase) DeleteBookmarks(ctx context.Context, ids ...int) (err error)

DeleteBookmarks removes all record with matching ids from database.

func (*MySQLDatabase) GetAccount

func (db *MySQLDatabase) GetAccount(ctx context.Context, username string) (model.Account, bool, error)

GetAccount fetch account with matching username. Returns the account and boolean whether it's exist or not.

func (*MySQLDatabase) GetAccounts

func (db *MySQLDatabase) GetAccounts(ctx context.Context, opts GetAccountsOptions) ([]model.Account, error)

GetAccounts fetch list of account (without its password) based on submitted options.

func (*MySQLDatabase) GetBookmark

func (db *MySQLDatabase) GetBookmark(ctx context.Context, id int, url string) (model.BookmarkDTO, bool, error)

GetBookmark fetches 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(ctx context.Context, opts GetBookmarksOptions) ([]model.BookmarkDTO, error)

GetBookmarks fetch list of bookmarks based on submitted options.

func (*MySQLDatabase) GetBookmarksCount

func (db *MySQLDatabase) GetBookmarksCount(ctx context.Context, opts GetBookmarksOptions) (int, error)

GetBookmarksCount fetch count of bookmarks based on submitted options.

func (*MySQLDatabase) GetTags

func (db *MySQLDatabase) GetTags(ctx context.Context) ([]model.Tag, error)

GetTags fetch list of tags and their frequency.

func (*MySQLDatabase) Migrate added in v1.5.3

func (db *MySQLDatabase) Migrate() error

Migrate runs migrations for this database engine

func (*MySQLDatabase) RenameTag

func (db *MySQLDatabase) RenameTag(ctx context.Context, id int, newName string) error

RenameTag change the name of a tag.

func (*MySQLDatabase) SaveAccount

func (db *MySQLDatabase) SaveAccount(ctx context.Context, account model.Account) (err error)

SaveAccount saves new account to database. Returns error if any happened.

func (*MySQLDatabase) SaveAccountSettings added in v1.6.0

func (db *MySQLDatabase) SaveAccountSettings(ctx context.Context, account model.Account) (err error)

SaveAccountSettings update settings for specific account in database. Returns error if any happened

func (*MySQLDatabase) SaveBookmarks

func (db *MySQLDatabase) SaveBookmarks(ctx context.Context, create bool, bookmarks ...model.BookmarkDTO) ([]model.BookmarkDTO, 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 added in v1.5.1

type PGDatabase struct {
	// contains filtered or unexported fields
}

PGDatabase is implementation of Database interface for connecting to PostgreSQL database.

func OpenPGDatabase added in v1.5.1

func OpenPGDatabase(ctx context.Context, connString string) (pgDB *PGDatabase, err error)

OpenPGDatabase creates and opens connection to a PostgreSQL Database.

func (*PGDatabase) CreateTags added in v1.6.0

func (db *PGDatabase) CreateTags(ctx context.Context, tags ...model.Tag) error

CreateTags creates new tags from submitted objects.

func (*PGDatabase) DeleteAccounts added in v1.5.1

func (db *PGDatabase) DeleteAccounts(ctx context.Context, usernames ...string) (err error)

DeleteAccounts removes all record with matching usernames.

func (*PGDatabase) DeleteBookmarks added in v1.5.1

func (db *PGDatabase) DeleteBookmarks(ctx context.Context, ids ...int) (err error)

DeleteBookmarks removes all record with matching ids from database.

func (*PGDatabase) GetAccount added in v1.5.1

func (db *PGDatabase) GetAccount(ctx context.Context, username string) (model.Account, bool, error)

GetAccount fetch account with matching username. Returns the account and boolean whether it's exist or not.

func (*PGDatabase) GetAccounts added in v1.5.1

func (db *PGDatabase) GetAccounts(ctx context.Context, opts GetAccountsOptions) ([]model.Account, error)

GetAccounts fetch list of account (without its password) based on submitted options.

func (*PGDatabase) GetBookmark added in v1.5.1

func (db *PGDatabase) GetBookmark(ctx context.Context, id int, url string) (model.BookmarkDTO, bool, error)

GetBookmark fetches bookmark based on its ID or URL. Returns the bookmark and boolean whether it's exist or not.

func (*PGDatabase) GetBookmarks added in v1.5.1

func (db *PGDatabase) GetBookmarks(ctx context.Context, opts GetBookmarksOptions) ([]model.BookmarkDTO, error)

GetBookmarks fetch list of bookmarks based on submitted options.

func (*PGDatabase) GetBookmarksCount added in v1.5.1

func (db *PGDatabase) GetBookmarksCount(ctx context.Context, opts GetBookmarksOptions) (int, error)

GetBookmarksCount fetch count of bookmarks based on submitted options.

func (*PGDatabase) GetTags added in v1.5.1

func (db *PGDatabase) GetTags(ctx context.Context) ([]model.Tag, error)

GetTags fetch list of tags and their frequency.

func (*PGDatabase) Migrate added in v1.5.3

func (db *PGDatabase) Migrate() error

Migrate runs migrations for this database engine

func (*PGDatabase) RenameTag added in v1.5.1

func (db *PGDatabase) RenameTag(ctx context.Context, id int, newName string) error

RenameTag change the name of a tag.

func (*PGDatabase) SaveAccount added in v1.5.1

func (db *PGDatabase) SaveAccount(ctx context.Context, account model.Account) (err error)

SaveAccount saves new account to database. Returns error if any happened.

func (*PGDatabase) SaveAccountSettings added in v1.6.0

func (db *PGDatabase) SaveAccountSettings(ctx context.Context, account model.Account) (err error)

SaveAccountSettings update settings for specific account in database. Returns error if any happened

func (*PGDatabase) SaveBookmarks added in v1.5.1

func (db *PGDatabase) SaveBookmarks(ctx context.Context, create bool, bookmarks ...model.BookmarkDTO) (result []model.BookmarkDTO, err error)

SaveBookmarks saves new or updated bookmarks to database. Returns the saved ID and error message if any happened.

type SQLiteDatabase

type SQLiteDatabase struct {
	// contains filtered or unexported fields
}

SQLiteDatabase is implementation of Database interface for connecting to SQLite3 database.

func OpenSQLiteDatabase

func OpenSQLiteDatabase(ctx context.Context, databasePath string) (sqliteDB *SQLiteDatabase, err error)

OpenSQLiteDatabase creates and open connection to new SQLite3 database.

func (*SQLiteDatabase) CreateTags added in v1.6.0

func (db *SQLiteDatabase) CreateTags(ctx context.Context, tags ...model.Tag) error

CreateTags creates new tags from submitted objects.

func (*SQLiteDatabase) DeleteAccounts

func (db *SQLiteDatabase) DeleteAccounts(ctx context.Context, usernames ...string) error

DeleteAccounts removes all record with matching usernames.

func (*SQLiteDatabase) DeleteBookmarks

func (db *SQLiteDatabase) DeleteBookmarks(ctx context.Context, ids ...int) error

DeleteBookmarks removes all record with matching ids from database.

func (*SQLiteDatabase) GetAccount

func (db *SQLiteDatabase) GetAccount(ctx context.Context, username string) (model.Account, bool, error)

GetAccount fetch account with matching username. Returns the account and boolean whether it's exist or not.

func (*SQLiteDatabase) GetAccounts

func (db *SQLiteDatabase) GetAccounts(ctx context.Context, opts GetAccountsOptions) ([]model.Account, error)

GetAccounts fetch list of account (without its password) based on submitted options.

func (*SQLiteDatabase) GetBookmark

func (db *SQLiteDatabase) GetBookmark(ctx context.Context, id int, url string) (model.BookmarkDTO, bool, error)

GetBookmark fetches 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(ctx context.Context, opts GetBookmarksOptions) ([]model.BookmarkDTO, error)

GetBookmarks fetch list of bookmarks based on submitted options.

func (*SQLiteDatabase) GetBookmarksCount

func (db *SQLiteDatabase) GetBookmarksCount(ctx context.Context, opts GetBookmarksOptions) (int, error)

GetBookmarksCount fetch count of bookmarks based on submitted options.

func (*SQLiteDatabase) GetTags

func (db *SQLiteDatabase) GetTags(ctx context.Context) ([]model.Tag, error)

GetTags fetch list of tags and their frequency.

func (*SQLiteDatabase) Migrate added in v1.5.3

func (db *SQLiteDatabase) Migrate() error

Migrate runs migrations for this database engine

func (*SQLiteDatabase) RenameTag

func (db *SQLiteDatabase) RenameTag(ctx context.Context, id int, newName string) error

RenameTag change the name of a tag.

func (*SQLiteDatabase) SaveAccount

func (db *SQLiteDatabase) SaveAccount(ctx context.Context, account model.Account) error

SaveAccount saves new account to database. Returns error if any happened.

func (*SQLiteDatabase) SaveAccountSettings added in v1.6.0

func (db *SQLiteDatabase) SaveAccountSettings(ctx context.Context, account model.Account) error

SaveAccountSettings update settings for specific account in database. Returns error if any happened.

func (*SQLiteDatabase) SaveBookmarks

func (db *SQLiteDatabase) SaveBookmarks(ctx context.Context, create bool, bookmarks ...model.BookmarkDTO) ([]model.BookmarkDTO, error)

SaveBookmarks saves new or updated bookmarks to database. Returns the saved ID and error message if any happened.

Jump to

Keyboard shortcuts

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