db

package
v0.0.31 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddBook

func AddBook(tx Transaction, url string, name string, description null.NullString, parentID null.NullString) (string, error)

AddBook inserts a book into the bookmarks database.

func AddFolder

func AddFolder(tx Transaction, name string, parentID null.NullString) (string, error)

AddFolder inserts a folder into the bookmarks database.

func AddTags

func AddTags(tx Transaction, tags []string) error

AddTags inserts tags into the bookmarks database.

func BookFolderExists

func BookFolderExists(tx Transaction, ID string, isFolder bool) (bool, error)

BookFolderExists returns true if the target book or folder exists.

func CleanOrphanedTags

func CleanOrphanedTags(tx Transaction, tags []string) error

CleanOrphanedTags removes any tags that aren't applied to a bookmark.

func ExecWithTransaction

func ExecWithTransaction(inputPath null.NullString, configPath string, execFn ExecTxFn) (err error)

execWithTransaction creates a scope for functions that operate on a transaction which doesn't return results. Handles connecting to the DB, creating the transaction, committing/rolling back, and closing the connection. Will also handle creating the DB if it doesn't exist and applying missing migrations to it.

func GetBooks

func GetBooks(tx Transaction, args GetBooksArgs) ([]armaria.Book, error)

GetBooks lists bookmarks/folders in the bookmarks DB.

func GetParentAndChildren

func GetParentAndChildren(tx Transaction, ID string) ([]armaria.Book, error)

GetParentAndChildren gets a parent and all of its children.

func GetTags

func GetTags(tx Transaction, args GetTagsArgs) ([]string, error)

GetTags lists tags in the bookmarks DB.

func LinkTags

func LinkTags(tx Transaction, bookmarkID string, tags []string) error

LinkTags adds tags to bookmark.

func QueryWithDB

func QueryWithDB[T any](inputPath null.NullString, configPath string, queryFn QueryTxFn[T]) (T, error)

QueryWithDB creates a scope for for functions that operate on a database connection which return results. Handles connecting to the DB and closing the connection. Will also handle creating the DB if it doesn't exist and applying missing migrations to it.

func QueryWithTransaction

func QueryWithTransaction[T any](inputPath null.NullString, configPath string, queryFn QueryTxFn[T]) (val T, err error)

queryWithTransaction creates a scope for functions that operate on a transaction which returns results. Handles connecting to the DB, creating the transaction, committing/rolling back, and closing the connection. Will also handle creating the DB if it doesn't exist and applying missing migrations to it.

func RemoveBook

func RemoveBook(tx Transaction, ID string) error

RemoveBook deletes a bookmark from the bookmarks DB.

func RemoveFolder

func RemoveFolder(tx Transaction, ID string) error

RemoveFolder deletes a folder from the bookmarks DB.

func UnlinkTags

func UnlinkTags(tx Transaction, ID string, tags []string) error

UnlinkTags removes tags from a bookmark.

func UpdateBook

func UpdateBook(tx Transaction, ID string, args UpdateBookArgs) error

UpdateBook updates a book in the bookmarks database.

func UpdateFolder

func UpdateFolder(tx Transaction, ID string, args UpdateFolderArgs) error

UpdateFolder updates a folder in the bookmarks database.

Types

type ExecTxFn

type ExecTxFn func(Transaction) error

ExecTxFn is a function that operates on a transaction which doesn't return results.

type GetBooksArgs

type GetBooksArgs struct {
	IDFilter       string
	IncludeBooks   bool
	IncludeFolders bool
	ParentID       null.NullString
	Query          null.NullString
	Tags           []string
	After          null.NullString
	Order          armaria.Order
	Direction      armaria.Direction
	First          null.NullInt64
}

GetBooksArgs are the args for getBooksDB.

type GetTagsArgs

type GetTagsArgs struct {
	IDFilter   null.NullString
	TagsFilter []string
	Query      null.NullString
	After      null.NullString
	Direction  armaria.Direction
	First      null.NullInt64
}

GetTagsArgs are the args for getTagsDB.

type QueryTxFn

type QueryTxFn[T any] func(Transaction) (T, error)

QueryTxFn is a function that operates on a transaction which returns results.

type Transaction

type Transaction interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

Transaction represents a database/sql connection.

type UpdateBookArgs

type UpdateBookArgs struct {
	Name        null.NullString
	URL         null.NullString
	Description null.NullString
	ParentID    null.NullString
}

UpdateBookArgs are the args for updateBookDB.

type UpdateFolderArgs

type UpdateFolderArgs struct {
	Name     null.NullString
	ParentID null.NullString
}

UpdateFolderArgs are the args for updateFolderDB.

Jump to

Keyboard shortcuts

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