storage

package
v0.0.0-...-5af0fa5 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: BSD-2-Clause Imports: 5 Imported by: 3

Documentation

Index

Constants

View Source
const (
	TaggableTypeBookmark TaggableType = "bookmark"

	TagsFetchModeNone    TagsFetchMode = "none"
	TagsFetchModeLeafs   TagsFetchMode = "leafs"
	TagsFetchModeAll     TagsFetchMode = "all"
	TagsFetchModeDefault               = TagsFetchModeLeafs

	TagNamesFetchModeNone    TagNamesFetchMode = "none"
	TagNamesFetchModeFull    TagNamesFetchMode = "full"
	TagNamesFetchModeDefault                   = TagNamesFetchModeFull

	TaggableLeafPolicyKeep TaggableLeafPolicy = "keep_new_leaf"
	TaggableLeafPolicyDel  TaggableLeafPolicy = "del_new_leaf"
)

Variables

View Source
var (
	ErrUserDoesNotExist     = errors.New("user does not exist")
	ErrTagDoesNotExist      = errors.New("tag does not exist")
	ErrTagNameInvalid       = errors.New("")
	ErrBookmarkDoesNotExist = errors.New("bookmark does not exist")
	ErrNotImplemented       = errors.New("not implemented")
)

Functions

func CleanupTagName

func CleanupTagName(s string, allowEmpty bool) (err error, name string)

func ValidateTagName

func ValidateTagName(name string, allowEmpty bool) error

Types

type BookmarkData

type BookmarkData struct {
	// We don't embed TaggableData here since we don't want Type to be here
	ID        int
	OwnerID   int
	CreatedAt uint64
	UpdatedAt uint64
	URL       string
	Title     string
	Comment   string
}

type BookmarkDataWTags

type BookmarkDataWTags struct {
	BookmarkData
	Tags []BookmarkTagPath
}

type BookmarkTagPath

type BookmarkTagPath struct {
	TagItems []BookmarkTagPathItem
}

type BookmarkTagPathItem

type BookmarkTagPathItem struct {
	ID   int
	Name string
}

type GetTagOpts

type GetTagOpts struct {
	GetNames   bool
	GetSubtags bool
}

type GetUserArgs

type GetUserArgs struct {
	ID       *int
	Username *string
}

Either ID or Username should be given.

type Storage

type Storage interface {
	//-- Common
	Connect() error
	ApplyMigrations() error
	Tx(fn func(*sql.Tx) error) error
	TxOpt(ilevel TxILevel, mode TxMode, fn func(*sql.Tx) error) error

	//-- Users
	GetUser(tx *sql.Tx, args *GetUserArgs) (*UserData, error)
	CreateUser(tx *sql.Tx, ud *UserData) (userID int, err error)
	DeleteUser(tx *sql.Tx, userID int) error
	GetUsers(tx *sql.Tx) ([]UserData, error)
	GetAccessToken(
		tx *sql.Tx, userID int, descr string, createIfNotExist bool,
	) (token string, err error)
	GetUserByAccessToken(tx *sql.Tx, token string) (*UserData, error)
	GetUserByGoogleUserID(tx *sql.Tx, googleUserID string) (*UserData, error)
	CreateGoogleUser(tx *sql.Tx, userID int, googleUserID, email string) error

	//-- Tags
	CreateTag(tx *sql.Tx, td *TagData) (tagID int, err error)
	// leafPolicy is used if only td.ParentTagID is not nil, i.e. if the tag
	// should be moved.
	UpdateTag(tx *sql.Tx, td *TagData, leafPolicy TaggableLeafPolicy) (err error)
	DeleteTag(tx *sql.Tx, tagID int, leafPolicy TaggableLeafPolicy) (err error)
	GetTagIDByPath(tx *sql.Tx, ownerID int, tagPath string) (int, error)
	GetTagIDByName(tx *sql.Tx, parentTagID int, tagName string) (int, error)
	GetRootTagID(tx *sql.Tx, ownerID int) (int, error)
	// NOTE: all non-slice pointer fields are guaranteed to be non-nil
	GetTag(tx *sql.Tx, tagID int, opts *GetTagOpts) (*TagData, error)
	GetTags(
		tx *sql.Tx, parentTagID int, opts *GetTagOpts,
	) ([]TagData, error)
	GetTagNames(tx *sql.Tx, tagID int) ([]string, error)

	//-- Taggables (bookmarks)
	CreateTaggable(tx *sql.Tx, tgbd *TaggableData) (tgbID int, err error)
	CreateBookmark(tx *sql.Tx, bd *BookmarkData) (bkmID int, err error)
	UpdateBookmark(tx *sql.Tx, bd *BookmarkData) (err error)
	GetTaggedTaggableIDs(
		tx *sql.Tx, tagIDs []int, ownerID *int, ttypes []TaggableType,
	) (taggableIDs []int, err error)

	// tagsFetchOpts might be nil, or any of the options might be empty strings:
	// in this case, defaults will be used: TagsFetchModeLeafs and
	// TagNamesFetchModeFull.
	GetTaggedBookmarks(
		tx *sql.Tx, tagIDs []int, ownerID *int, tagsFetchOpts *TagsFetchOpts,
	) (bookmarks []BookmarkDataWTags, err error)
	GetBookmarksByURL(
		tx *sql.Tx, url string, ownerID int, tagsFetchOpts *TagsFetchOpts,
	) (bookmarks []BookmarkDataWTags, err error)
	GetBookmarkByID(
		tx *sql.Tx, bookmarkID int, tagsFetchOpts *TagsFetchOpts,
	) (bookmark *BookmarkDataWTags, err error)
	DeleteTaggable(tx *sql.Tx, taggableID int) error

	//-- Taggings
	GetTaggings(
		tx *sql.Tx, taggableID int, tm TaggingMode,
	) (tagIDs []int, err error)
	SetTaggings(
		tx *sql.Tx, taggableID int, tagIDs []int, tm TaggingMode,
	) error

	//-- Maintenance
	CheckIntegrity() error
}

type TagData

type TagData struct {
	ID          int
	OwnerID     int
	ParentTagID *int
	Description *string
	Names       []string
	Subtags     []TagData
}

type TagNamesFetchMode

type TagNamesFetchMode string

type TaggableData

type TaggableData struct {
	ID        int
	OwnerID   int
	Type      TaggableType
	CreatedAt uint64
	UpdatedAt uint64
}

type TaggableLeafPolicy

type TaggableLeafPolicy string

Taggable leaf policy when tags structure changes: either keep the taggings of the new leaf, or delete it

type TaggableType

type TaggableType string

type TaggingMode

type TaggingMode int

TaggingMode is used for GetTaggings(), SetTaggings: specifies whether given argument/returned value should contain all tags (including all supertags), or leafs only.

const (
	TaggingModeAll TaggingMode = iota
	TaggingModeLeafs
)

type TagsFetchMode

type TagsFetchMode string

type TagsFetchOpts

type TagsFetchOpts struct {
	TagsFetchMode     TagsFetchMode
	TagNamesFetchMode TagNamesFetchMode
}

type TxILevel

type TxILevel int
const (
	TxILevelReadCommitted TxILevel = iota
	TxILevelRepeatableRead
	TxILevelSerializable
)

type TxMode

type TxMode int
const (
	TxModeReadWrite TxMode = iota
	TxModeReadOnly
)

type UserData

type UserData struct {
	ID       int
	Username string
	Password string
	Email    string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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