data

package
v0.0.0-...-9307e03 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	Note            *NoteData
	NoteAsset       *NoteAssetData
	NoteExt         *NoteExtData
	ProcedureRecord *ProcedureRecordData
	Tag             *TagData

	NoteEventBus *event.NoteEventBus
	// contains filtered or unexported fields
}

Data 数据层入口 协调数据库和缓存操作,对上层(biz)屏蔽底层数据存取细节

func MustNew

func MustNew(c *config.Config, cache *redis.Redis, publisher *infrakafka.Publisher) *Data

MustNew 创建Data实例

func (*Data) Close

func (d *Data) Close()

func (*Data) DB

func (d *Data) DB() *xsql.DB

type GetOption

type GetOption struct {
	UseCache bool // 是否使用缓存获取数据
	SetCache bool // 是否在缓存未命中时回填缓存
}

GetOption 数据获取选项

func ApplyOptions

func ApplyOptions(opts ...GetOptionFunc) *GetOption

ApplyOptions 应用选项

func DefaultGetOption

func DefaultGetOption() *GetOption

DefaultGetOption 默认选项:使用缓存并回填

type GetOptionFunc

type GetOptionFunc func(*GetOption)

GetOptionFunc 选项函数

func WithCacheOnly

func WithCacheOnly() GetOptionFunc

WithCacheOnly 仅使用缓存,不回填

func WithSetCache

func WithSetCache(set bool) GetOptionFunc

WithSetCache 设置是否回填缓存

func WithUseCache

func WithUseCache(use bool) GetOptionFunc

WithUseCache 设置是否使用缓存

func WithoutCache

func WithoutCache() GetOptionFunc

WithoutCache 不使用缓存

type NoteAssetData

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

NoteAssetData 笔记资源数据层

func NewNoteAssetData

func NewNoteAssetData(repo *notedao.NoteAssetRepo) *NoteAssetData

func (*NoteAssetData) BatchInsert

func (d *NoteAssetData) BatchInsert(ctx context.Context, assets []*notedao.AssetPO) error

批量插入资源

func (*NoteAssetData) BatchUpdateAssetMeta

func (d *NoteAssetData) BatchUpdateAssetMeta(ctx context.Context, noteId int64, metas map[string][]byte) error

批量更新资源元数据

func (*NoteAssetData) DeleteByNoteId

func (d *NoteAssetData) DeleteByNoteId(ctx context.Context, noteId int64) error

删除笔记的所有资源

func (*NoteAssetData) DeleteByNoteIdExcept

func (d *NoteAssetData) DeleteByNoteIdExcept(ctx context.Context, noteId int64, assetKeys []string) error

删除笔记的资源(排除指定的key)

func (*NoteAssetData) FindByNoteIds

func (d *NoteAssetData) FindByNoteIds(ctx context.Context, noteIds []int64) ([]*notedao.AssetPO, error)

根据笔记ID批量获取资源

func (*NoteAssetData) FindImageNoteAssets

func (d *NoteAssetData) FindImageNoteAssets(ctx context.Context, noteId int64) ([]*notedao.AssetPO, error)

获取笔记的图片资源

func (*NoteAssetData) FindOne

func (d *NoteAssetData) FindOne(ctx context.Context, id int64) (*notedao.AssetPO, error)

获取单个资源

func (*NoteAssetData) FindVideoNoteAssets

func (d *NoteAssetData) FindVideoNoteAssets(ctx context.Context, noteId int64) ([]*notedao.AssetPO, error)

func (*NoteAssetData) Insert

func (d *NoteAssetData) Insert(ctx context.Context, asset *notedao.AssetPO) error

插入资源

type NoteCondition

type NoteCondition = notedao.NoteRepoCondition

NoteCondition 笔记查询条件(重新导出给 Biz 层使用)

func WithNoteOwnerEqual

func WithNoteOwnerEqual(uid int64) NoteCondition

WithNoteOwnerEqual 指定笔记所有者

func WithNotePrivacyEqual

func WithNotePrivacyEqual(privacy model.Privacy) NoteCondition

WithNotePrivacyEqual 指定笔记隐私类型

func WithNoteStateEqual

func WithNoteStateEqual(state model.NoteState) NoteCondition

WithNoteStateEqual 指定笔记状态

func WithNoteStateIn

func WithNoteStateIn(states ...model.NoteState) NoteCondition

func WithNoteStateNotIn

func WithNoteStateNotIn(states ...model.NoteState) NoteCondition

WithNoteStateNotIn 排除指定状态

func WithNoteTypeEqual

func WithNoteTypeEqual(noteType model.NoteType) NoteCondition

WithNoteTypeEqual 指定笔记类型

type NoteData

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

NoteData 笔记数据层 - 协调数据库和缓存操作

func NewNoteData

func NewNoteData(repo *notedao.NoteRepo, cache *notedao.NoteCache) *NoteData

func (*NoteData) BatchGet

func (d *NoteData) BatchGet(ctx context.Context, ids []int64, opts ...GetOptionFunc) (map[int64]*notedao.NotePO, error)

BatchGet 批量获取笔记,支持缓存选项

func (*NoteData) ConvertNotes

func (d *NoteData) ConvertNotes(notes []*notedao.NotePO) []*model.Note

ConvertNotes 将dao层的NotePO转换为model层的Note

func (*NoteData) Count

func (d *NoteData) Count(ctx context.Context, conds ...NoteCondition) (int64, error)

Count 统计笔记数量(支持 conditions)

func (*NoteData) Delete

func (d *NoteData) Delete(ctx context.Context, noteId int64) error

Delete 删除笔记,同时删除相关缓存

func (*NoteData) DeleteNote

func (d *NoteData) DeleteNote(ctx context.Context, po *notedao.NotePO) error

func (*NoteData) FindOne

func (d *NoteData) FindOne(ctx context.Context, id int64, opts ...GetOptionFunc) (*notedao.NotePO, error)

FindOne 获取单个笔记,支持缓存选项

func (*NoteData) FindOneForUpdate

func (d *NoteData) FindOneForUpdate(ctx context.Context, id int64) (*notedao.NotePO, error)

FindOneForUpdate 获取单个笔记用于更新(带行锁,不使用缓存)

func (*NoteData) GetCountWithStateByOwner

func (d *NoteData) GetCountWithStateByOwner(ctx context.Context, uid int64, states ...model.NoteState) (int64, error)

func (*NoteData) GetNoteType

func (d *NoteData) GetNoteType(ctx context.Context, id int64) (model.NoteType, error)

GetNoteType 获取笔记类型

func (*NoteData) GetPostedCountByOwner

func (d *NoteData) GetPostedCountByOwner(ctx context.Context, uid int64, opts ...GetOptionFunc) (int64, error)

GetPostedCountByOwner 获取用户发布的笔记数量,支持缓存选项

func (*NoteData) GetPublicAll

func (d *NoteData) GetPublicAll(ctx context.Context) ([]*notedao.NotePO, error)

GetPublicAll 获取所有公开笔记

func (*NoteData) GetPublicByCursor

func (d *NoteData) GetPublicByCursor(ctx context.Context, id int64, count int) ([]*notedao.NotePO, error)

GetPublicByCursor 按游标获取公开笔记

func (*NoteData) GetPublicCount

func (d *NoteData) GetPublicCount(ctx context.Context) (int64, error)

GetPublicCount 获取公开笔记数量

func (*NoteData) GetPublicLastId

func (d *NoteData) GetPublicLastId(ctx context.Context) (int64, error)

GetPublicLastId 获取最后一个公开笔记ID

func (*NoteData) GetPublicPostedCountByOwner

func (d *NoteData) GetPublicPostedCountByOwner(ctx context.Context, uid int64, opts ...GetOptionFunc) (int64, error)

GetPublicPostedCountByOwner 获取用户公开发布的笔记数量,支持缓存选项

func (*NoteData) GetRecentPublicPosted

func (d *NoteData) GetRecentPublicPosted(ctx context.Context, uid int64, count int32) ([]*notedao.NotePO, error)

GetRecentPublicPosted 获取用户最近发布的公开笔记

func (*NoteData) Insert

func (d *NoteData) Insert(ctx context.Context, note *notedao.NotePO) (int64, error)

Insert 插入笔记

func (*NoteData) List

func (d *NoteData) List(ctx context.Context, conds ...NoteCondition) ([]*notedao.NotePO, error)

List 查询笔记列表(支持 conditions)

func (*NoteData) ListByCursor

func (d *NoteData) ListByCursor(ctx context.Context, cursor int64, limit int32, conds ...NoteCondition) ([]*notedao.NotePO, error)

ListByCursor 游标分页查询笔记(支持 conditions)

func (*NoteData) ListByPage

func (d *NoteData) ListByPage(ctx context.Context, page, count int32, conds ...NoteCondition) ([]*notedao.NotePO, error)

ListByPage 页码分页查询笔记(支持 conditions)

func (*NoteData) Update

func (d *NoteData) Update(ctx context.Context, note *notedao.NotePO) error

Update 更新笔记,同时删除相关缓存

func (*NoteData) UpdateState

func (d *NoteData) UpdateState(
	ctx context.Context,
	noteId int64,
	state model.NoteState,
) error

UpdateState 更新笔记状态,同时删除缓存

func (*NoteData) UpgradeState

func (d *NoteData) UpgradeState(
	ctx context.Context,
	noteId int64,
	state model.NoteState,
) error

带条件检查的笔记状态更新 同时删除缓存

如果当前状态小于等于目标状态,则更新状态,否则不更新

type NoteExtData

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

NoteExtData 笔记扩展信息数据层

func NewNoteExtData

func NewNoteExtData(repo *notedao.NoteExtRepo) *NoteExtData

func (*NoteExtData) BatchGetById

func (d *NoteExtData) BatchGetById(ctx context.Context, noteIds []int64) ([]*notedao.ExtPO, error)

BatchGetById 批量获取扩展信息

func (*NoteExtData) Delete

func (d *NoteExtData) Delete(ctx context.Context, noteId int64) error

Delete 删除扩展信息

func (*NoteExtData) GetById

func (d *NoteExtData) GetById(ctx context.Context, noteId int64) (*notedao.ExtPO, error)

GetById 根据笔记ID获取扩展信息

func (*NoteExtData) Upsert

func (d *NoteExtData) Upsert(ctx context.Context, ext *notedao.ExtPO) error

Upsert 插入或更新扩展信息

type ProcedureRecordData

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

ProcedureRecordData 流程记录数据层

func NewProcedureRecordData

func NewProcedureRecordData(repo *notedao.ProcedureRecordRepo) *ProcedureRecordData

func (*ProcedureRecordData) Delete

func (d *ProcedureRecordData) Delete(
	ctx context.Context,
	noteId int64,
	protype model.ProcedureType,
) error

Delete 删除流程记录

func (*ProcedureRecordData) Get

Get 获取流程记录

func (*ProcedureRecordData) GetEarliestNextCheckTimeRecord

func (d *ProcedureRecordData) GetEarliestNextCheckTimeRecord(
	ctx context.Context,
	status model.ProcedureStatus,
) (*notedao.ProcedureRecordPO, error)

GetEarliestNextCheckTimeRecord 获取最早需要检查的流程记录

func (*ProcedureRecordData) GetForUpdate

func (d *ProcedureRecordData) GetForUpdate(
	ctx context.Context,
	noteId int64,
	protype model.ProcedureType,
) (*notedao.ProcedureRecordPO, error)

func (*ProcedureRecordData) ListNextCheckTimeByRange

func (d *ProcedureRecordData) ListNextCheckTimeByRange(
	ctx context.Context,
	status model.ProcedureStatus,
	start int64,
	end int64,
	offsetId int64,
	limit int,
	shardIndex int,
	shardTotal int,
) ([]*notedao.ProcedureRecordPO, error)

ListNextCheckTimeByRange 获取指定时间范围内需要检查的流程记录

func (*ProcedureRecordData) UpdateRetry

func (d *ProcedureRecordData) UpdateRetry(
	ctx context.Context,
	noteId int64,
	protype model.ProcedureType,
	nextCheckTime int64,
) error

UpdateRetry 更新流程记录重试次数

func (*ProcedureRecordData) UpdateRetryMarkFailure

func (d *ProcedureRecordData) UpdateRetryMarkFailure(
	ctx context.Context,
	noteId int64,
	protype model.ProcedureType,
	nextCheckTime int64,
) error

UpdateRetryMarkFailure 更新流程记录重试次数并标记失败

func (*ProcedureRecordData) UpdateStatus

func (d *ProcedureRecordData) UpdateStatus(
	ctx context.Context,
	noteId int64,
	protype model.ProcedureType,
	status model.ProcedureStatus,
) error

UpdateStatus 更新流程记录状态

func (*ProcedureRecordData) UpdateTaskId

func (d *ProcedureRecordData) UpdateTaskId(
	ctx context.Context,
	noteId int64,
	protype model.ProcedureType,
	taskId string,
) error

UpdateTaskId 更新流程记录的任务ID

func (*ProcedureRecordData) UpdateTaskIdRetryNextCheckTime

func (d *ProcedureRecordData) UpdateTaskIdRetryNextCheckTime(
	ctx context.Context,
	record *notedao.ProcedureRecordPO,
) error

UpdateRecord 更新流程记录

func (*ProcedureRecordData) Upsert

Upsert 插入流程记录

type TagData

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

TagData 标签数据层 - 协调数据库和缓存操作

func NewTagData

func NewTagData(repo *tagdao.TagRepo, cache *tagdao.TagCache) *TagData

func (*TagData) BatchGetById

func (d *TagData) BatchGetById(ctx context.Context, ids []int64, opts ...GetOptionFunc) ([]*tagdao.Tag, error)

BatchGetById 批量根据ID获取标签,支持缓存选项

func (*TagData) Create

func (d *TagData) Create(ctx context.Context, tag *tagdao.Tag) (int64, error)

Create 创建标签

func (*TagData) FindById

func (d *TagData) FindById(ctx context.Context, id int64, opts ...GetOptionFunc) (*tagdao.Tag, error)

FindById 根据ID获取标签,支持缓存选项

func (*TagData) FindByName

func (d *TagData) FindByName(ctx context.Context, name string, opts ...GetOptionFunc) (*tagdao.Tag, error)

FindByName 根据名称获取标签,支持缓存选项

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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