dao

package
v0.0.0-...-b5db161 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserByIDKey            = "user#id=%d"
	UserByNameEmailKey     = "user#name=%s;email=%s"
	UserIDByEmailKey       = "user_id#email=%s"
	SiteByIDKey            = "site#id=%d"
	SiteByNameKey          = "site#name=%s"
	PageByIDKey            = "page#id=%d"
	PageByKeySiteNameKey   = "page#key=%s;site_name=%s"
	CommentByIDKey         = "comment#id=%d"
	CommentChildIDsByIDKey = "comment_child_ids#id=%d"
	NotifyByUserCommentKey = "notify#user_id=%d;comment_id=%d"
)

Variables

This section is empty.

Functions

func FindCreateAction

func FindCreateAction[T EntityHasIsEmpty](
	key string,
	findAction func() (T, error),
	createAction func() (T, error),
) (T, error)

FindCreateAction (Thread Safe)

Use singleflight.Group to prevent duplicate creation if multiple goroutines access at the same time.

func GetTitleByURL

func GetTitleByURL(url string) (string, error)

Types

type Dao

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

func NewDao

func NewDao(db *gorm.DB) *Dao

Create new dao instance

This function will auto migrate database tables

func (*Dao) CacheAction

func (dao *Dao) CacheAction(fn func(cache *DaoCache))

func (*Dao) CacheFlushAll

func (dao *Dao) CacheFlushAll()

清空缓存

func (*Dao) CacheWarmUp

func (dao *Dao) CacheWarmUp()

缓存预热

func (*Dao) CommentToArtran

func (dao *Dao) CommentToArtran(c *entity.Comment) entity.Artran

func (*Dao) CookAllComments

func (dao *Dao) CookAllComments(comments []*entity.Comment) []entity.CookedComment

func (*Dao) CookAllNotifies

func (dao *Dao) CookAllNotifies(notifies []entity.Notify) []entity.CookedNotify

func (*Dao) CookAllPages

func (dao *Dao) CookAllPages(pages []entity.Page) []entity.CookedPage

func (*Dao) CookComment

func (dao *Dao) CookComment(c *entity.Comment) entity.CookedComment

func (*Dao) CookCommentForEmail

func (dao *Dao) CookCommentForEmail(c *entity.Comment) entity.CookedCommentForEmail

func (*Dao) CookNotify

func (dao *Dao) CookNotify(n *entity.Notify) entity.CookedNotify

func (*Dao) CookPage

func (dao *Dao) CookPage(p *entity.Page) entity.CookedPage

func (*Dao) CookSite

func (dao *Dao) CookSite(s *entity.Site) entity.CookedSite

func (*Dao) CookUser

func (dao *Dao) CookUser(u *entity.User) entity.CookedUser

func (*Dao) CreateAuthIdentity

func (dao *Dao) CreateAuthIdentity(identity *entity.AuthIdentity) error

func (*Dao) CreateComment

func (dao *Dao) CreateComment(comment *entity.Comment) error

func (*Dao) CreatePage

func (dao *Dao) CreatePage(page *entity.Page) error

func (*Dao) CreateSite

func (dao *Dao) CreateSite(site *entity.Site) error

func (*Dao) CreateUser

func (dao *Dao) CreateUser(user *entity.User) error

func (*Dao) DB

func (dao *Dao) DB() *gorm.DB

func (*Dao) DelAuthIdentity

func (dao *Dao) DelAuthIdentity(authIdentity *entity.AuthIdentity) error

func (*Dao) DelComment

func (dao *Dao) DelComment(comment *entity.Comment) error

func (*Dao) DelCommentChildren

func (dao *Dao) DelCommentChildren(parentID uint) error

删除所有子评论

func (*Dao) DelPage

func (dao *Dao) DelPage(page *entity.Page) error

func (*Dao) DelSite

func (dao *Dao) DelSite(site *entity.Site) error

func (*Dao) DelUser

func (dao *Dao) DelUser(user *entity.User) error

func (*Dao) DropConstraintsIfExist

func (dao *Dao) DropConstraintsIfExist()

Remove all constraints

func (*Dao) FetchCommentForNotify

func (dao *Dao) FetchCommentForNotify(n *entity.Notify) entity.Comment

func (*Dao) FetchPageForComment

func (dao *Dao) FetchPageForComment(c *entity.Comment) entity.Page

func (*Dao) FetchPageFromURL

func (dao *Dao) FetchPageFromURL(p *entity.Page) error

func (*Dao) FetchSiteForComment

func (dao *Dao) FetchSiteForComment(c *entity.Comment) entity.Site

func (*Dao) FetchSiteForPage

func (dao *Dao) FetchSiteForPage(p *entity.Page) entity.Site

func (*Dao) FetchUserForComment

func (dao *Dao) FetchUserForComment(c *entity.Comment) entity.User

func (*Dao) FetchUserForNotify

func (dao *Dao) FetchUserForNotify(n *entity.Notify) entity.User

获取接收通知的用户

func (*Dao) FindAllSites

func (dao *Dao) FindAllSites() []entity.Site

func (*Dao) FindAllSitesCooked

func (dao *Dao) FindAllSitesCooked() []entity.CookedSite

func (*Dao) FindAuthIdentityByRemoteUID

func (dao *Dao) FindAuthIdentityByRemoteUID(provider string, remoteUID string) entity.AuthIdentity

func (*Dao) FindAuthIdentityByToken

func (dao *Dao) FindAuthIdentityByToken(provider string, token string) entity.AuthIdentity

func (*Dao) FindAuthIdentityByUserID

func (dao *Dao) FindAuthIdentityByUserID(provider string, userID uint) entity.AuthIdentity

func (*Dao) FindComment

func (dao *Dao) FindComment(id uint, checkers ...func(*entity.Comment) bool) entity.Comment

func (*Dao) FindCommentChildren

func (dao *Dao) FindCommentChildren(parentID uint, checkers ...func(*entity.Comment) bool) []entity.Comment

func (*Dao) FindCommentChildrenShallow

func (dao *Dao) FindCommentChildrenShallow(parentID uint, checkers ...func(*entity.Comment) bool) []entity.Comment

(Cached:parent-comments)

func (*Dao) FindCommentRootID

func (dao *Dao) FindCommentRootID(rid uint) uint

func (*Dao) FindCreateNotify

func (dao *Dao) FindCreateNotify(userID uint, commentID uint) entity.Notify

func (*Dao) FindCreatePage

func (dao *Dao) FindCreatePage(pageKey string, pageTitle string, siteName string) entity.Page

func (*Dao) FindCreateSite

func (dao *Dao) FindCreateSite(siteName string) entity.Site

func (*Dao) FindCreateUser

func (dao *Dao) FindCreateUser(name string, email string, link string) (entity.User, error)

func (*Dao) FindNotify

func (dao *Dao) FindNotify(userID uint, commentID uint) entity.Notify

#region Notify

func (*Dao) FindNotifyForComment

func (dao *Dao) FindNotifyForComment(commentID uint, key string) entity.Notify

func (*Dao) FindNotifyParentComment

func (dao *Dao) FindNotifyParentComment(n *entity.Notify) entity.Comment

func (*Dao) FindPage

func (dao *Dao) FindPage(key string, siteName string) entity.Page

func (*Dao) FindPageByID

func (dao *Dao) FindPageByID(id uint) entity.Page

func (*Dao) FindSite

func (dao *Dao) FindSite(name string) entity.Site

func (*Dao) FindSiteByID

func (dao *Dao) FindSiteByID(id uint) entity.Site

func (*Dao) FindUnreadNotifies

func (dao *Dao) FindUnreadNotifies(userID uint) []entity.Notify

func (*Dao) FindUser

func (dao *Dao) FindUser(name string, email string) entity.User

查找用户 (精确查找 name & email)

func (*Dao) FindUserByID

func (dao *Dao) FindUserByID(id uint) entity.User

查找用户 (通过 ID)

func (*Dao) FindUserIdsByEmail

func (dao *Dao) FindUserIdsByEmail(email string) []uint

查找用户 ID (仅根据 email)

func (*Dao) FindUsersByEmail

func (dao *Dao) FindUsersByEmail(email string) []entity.User

查找用户 (仅根据 email)

func (*Dao) GetAllAdminIDs

func (dao *Dao) GetAllAdminIDs() []uint

func (*Dao) GetAllAdmins

func (dao *Dao) GetAllAdmins() []entity.User

#region 管理员账号检测

func (*Dao) GetLinkToReplyByComment

func (dao *Dao) GetLinkToReplyByComment(c *entity.Comment, notifyKey ...string) string

获取评论回复链接

func (*Dao) GetPageAccessibleURL

func (dao *Dao) GetPageAccessibleURL(p *entity.Page, s ...*entity.Site) string

获取可访问链接

func (*Dao) GetReadLinkByNotify

func (dao *Dao) GetReadLinkByNotify(n *entity.Notify) string

func (*Dao) GetUserAllCommentIDs

func (dao *Dao) GetUserAllCommentIDs(userID uint) []uint

func (*Dao) GetVoteNum

func (dao *Dao) GetVoteNum(targetID uint, voteType string) int

#region Vote

func (*Dao) GetVoteNumUpDown

func (dao *Dao) GetVoteNumUpDown(targetID uint, voteTo string) (int, int)

func (*Dao) IsAdminUser

func (dao *Dao) IsAdminUser(userID uint) bool

func (*Dao) IsAdminUserByNameEmail

func (dao *Dao) IsAdminUserByNameEmail(name string, email string) bool

func (*Dao) MergePages

func (dao *Dao) MergePages()

func (*Dao) MigrateModels

func (dao *Dao) MigrateModels()

func (*Dao) MigrateRootID

func (dao *Dao) MigrateRootID()

func (*Dao) NewNotify

func (dao *Dao) NewNotify(userID uint, commentID uint) entity.Notify

func (*Dao) NewPage

func (dao *Dao) NewPage(key string, pageTitle string, siteName string) entity.Page

func (*Dao) NewSite

func (dao *Dao) NewSite(name string, urls string) entity.Site

func (*Dao) NewUser

func (dao *Dao) NewUser(name string, email string, link string) (entity.User, error)

func (*Dao) NewVote

func (dao *Dao) NewVote(targetID uint, voteType entity.VoteType, userID uint, ua string, ip string) (entity.Vote, error)

func (*Dao) NotifySetEmailed

func (dao *Dao) NotifySetEmailed(n *entity.Notify) error

func (*Dao) NotifySetInitial

func (dao *Dao) NotifySetInitial(n *entity.Notify) error

func (*Dao) NotifySetRead

func (dao *Dao) NotifySetRead(n *entity.Notify) error

func (*Dao) QueryDBWithCache

func (dao *Dao) QueryDBWithCache(name string, dest any, queryDB func()) error

func (*Dao) SetCache

func (dao *Dao) SetCache(cache *DaoCache)

func (*Dao) UpdateAuthIdentity

func (dao *Dao) UpdateAuthIdentity(authIdentity *entity.AuthIdentity) error

func (*Dao) UpdateComment

func (dao *Dao) UpdateComment(comment *entity.Comment) error

更新评论

func (*Dao) UpdatePage

func (dao *Dao) UpdatePage(page *entity.Page) error

func (*Dao) UpdateSite

func (dao *Dao) UpdateSite(site *entity.Site) error

func (*Dao) UpdateUser

func (dao *Dao) UpdateUser(user *entity.User) error

func (*Dao) UserNotifyMarkAllAsRead

func (dao *Dao) UserNotifyMarkAllAsRead(userID uint) error

func (*Dao) UserToCookedForAdmin

func (dao *Dao) UserToCookedForAdmin(u *entity.User) entity.CookedUserForAdmin

func (*Dao) VoteSync

func (dao *Dao) VoteSync()

type DaoCache

type DaoCache struct {
	*cache.Cache
}

func NewCacheAdaptor

func NewCacheAdaptor(cache *cache.Cache) *DaoCache

func (*DaoCache) ChildCommentCacheDel

func (c *DaoCache) ChildCommentCacheDel(comment *entity.Comment)

func (*DaoCache) ChildCommentCacheSave

func (c *DaoCache) ChildCommentCacheSave(comment *entity.Comment) error

缓存 父ID=>子ID 评论数据

func (*DaoCache) CommentCacheDel

func (c *DaoCache) CommentCacheDel(comment *entity.Comment)

func (*DaoCache) CommentCacheSave

func (c *DaoCache) CommentCacheSave(comment *entity.Comment) (err error)

func (*DaoCache) PageCacheDel

func (c *DaoCache) PageCacheDel(page *entity.Page)

func (*DaoCache) PageCacheSave

func (c *DaoCache) PageCacheSave(page *entity.Page) error

func (*DaoCache) SiteCacheDel

func (c *DaoCache) SiteCacheDel(site *entity.Site)

func (*DaoCache) SiteCacheSave

func (c *DaoCache) SiteCacheSave(site *entity.Site) error

func (*DaoCache) UserCacheDel

func (c *DaoCache) UserCacheDel(user *entity.User)

func (*DaoCache) UserCacheSave

func (c *DaoCache) UserCacheSave(user *entity.User) error

type EntityHasIsEmpty

type EntityHasIsEmpty interface {
	IsEmpty() bool
}

Jump to

Keyboard shortcuts

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