sql

package
v0.0.0-...-c901a60 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 59 Imported by: 2 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	AssetContentsFTSCaseInsensitiveInsert = "INSERT INTO asset_contents_fts_case_insensitive (id, name, ext, path, size, updated, content) VALUES %s"
	AssetContentsPlaceholder              = "(?, ?, ?, ?, ?, ?, ?)"
)
View Source
const (
	HistoriesFTSCaseInsensitiveInsert = "INSERT INTO histories_fts_case_insensitive (id, type, op, title, content, path, created) VALUES %s"
	HistoriesPlaceholder              = "(?, ?, ?, ?, ?, ?, ?)"
)
View Source
const (
	BlocksInsert      = "" /* 182-byte string literal not displayed */
	BlocksPlaceholder = "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

	// blocks_fts 采用 external content 模式(content='blocks'),写入时必须显式提供 rowid,
	// 该 rowid 取自 blocks 表的隐式 rowid,否则 FTS rowid 与 blocks rowid 脱钩会导致
	// snippet/highlight 回表取错行、按 rowid 删除静默失效。首列即为 rowid。
	BlocksFTSInsert      = "" /* 193-byte string literal not displayed */
	BlocksFTSPlaceholder = "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

	SpansInsert      = "INSERT INTO spans (id, block_id, root_id, box, path, content, markdown, type, ial) VALUES %s"
	SpansPlaceholder = "(?, ?, ?, ?, ?, ?, ?, ?, ?)"

	AssetsPlaceholder             = "(?, ?, ?, ?, ?, ?, ?, ?, ?)"
	AttributesPlaceholder         = "(?, ?, ?, ?, ?, ?, ?, ?)"
	RefsPlaceholder               = "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
	FileAnnotationRefsPlaceholder = "(?, ?, ?, ?, ?, ?, ?, ?, ?)"
)
View Source
const AttributeViewRefType = "av"
View Source
const BlockSearchMetadataPredicate = "(name != '' OR alias != '' OR memo != '' OR tag != '')"

字段拼接匹配需要补查元数据非空的块,部分索引使普通正文块不参与这一步扫描。

Variables

View Source
var (

	// IsEncryptedBoxFn 由 model 层注入,用于判断 boxID 是否为加密笔记本。
	// sql 包不直接 import model(循环依赖),路由函数据此 fail-closed:
	// 加密笔记本未解锁时绝不回退全局库,避免加密笔记本索引污染全局明文库。
	IsEncryptedBoxFn func(boxID string) bool

	// IsBoxUnlockedFn 由 model 层注入,用于在读取明文缓存前确认加密笔记本仍处于解锁状态。
	IsBoxUnlockedFn func(boxID string) bool
)
View Source
var (

	// HPathRefreshLock 在重建索引前阻止路径任务写回;锁顺序为路径任务锁、数据库初始化锁、索引队列锁。
	HPathRefreshLock sync.Mutex
	// ResetHPathRefreshQueue 由模型层注入,在持有 HPathRefreshLock 时同步清理普通索引的路径恢复记录。
	ResetHPathRefreshQueue func() error
)
View Source
var (
	IndexIgnoreCached bool
)

Functions

func BatchGetBlockAttrs

func BatchGetBlockAttrs(ids []string) (ret map[string]map[string]string)

func BatchGetBlockAttrsWitTrees

func BatchGetBlockAttrsWitTrees(ids []string, trees map[string]*parse.Tree) (ret map[string]map[string]string)

func BatchRemoveAssetsQueue

func BatchRemoveAssetsQueue(hashes []string)

func BatchRemoveTreeQueue

func BatchRemoveTreeQueue(rootIDs []string)

func CacheRef

func CacheRef(tree *parse.Tree, refNode *ast.Node)

func CalculateEmbedBlockContent

func CalculateEmbedBlockContent(block *Block) (content string, supported bool)

CalculateEmbedBlockContent 计算只读 SQL 嵌入的搜索内容;空脚本和 JavaScript 嵌入由前端更新。

func CheckAssetContentReadonlyStatement

func CheckAssetContentReadonlyStatement(stmt string) error

CheckAssetContentReadonlyStatement 在资源文件内容数据库连接上检查 SQL 是否只读。

func CheckHistoryReadonlyStatement

func CheckHistoryReadonlyStatement(stmt string) error

CheckHistoryReadonlyStatement 在历史数据库连接上检查 SQL 为「单条 + 只读」。 历史查询语句只引用 history.db 中的表,必须在该连接上 prepare 才能通过校验。 见 https://github.com/siyuan-note/siyuan/security/advisories/GHSA-4hjx-84f6-gr7c

func CheckReadonlyBlockQueryStatement

func CheckReadonlyBlockQueryStatement(stmt, boxID string) error

CheckReadonlyBlockQueryStatement 校验原始块查询语句为「单条 + 只读」,boxID 为空或普通笔记本时 在全局库上校验,加密笔记本在其独立加密库上校验。

嵌入块脚本、模板查询和导出路径的 SQL 都来自文档内容,属于不可信输入,执行前必须经过本校验。 见 https://github.com/siyuan-note/siyuan/security/advisories/GHSA-67p9-hm94-xwf3

func CheckReadonlyStatement

func CheckReadonlyStatement(stmt string) error

CheckReadonlyStatement 对整段 SQL 做 prepare(不执行),用 sqlite3_stmt_readonly 判断首条语句是否只读。 见 https://sqlite.org/c3ref/stmt_readonly.html

注意:若字符串里在语法上还有第二条及以后的语句,本函数只针对「首条」对应的 stmt 做判断, 不会拒绝多语句。与 CheckSingleStatement 组合即可得到「单条 + 只读」策略。 仅允许 SELECT 和 WITH 查询,避免 SQLite 将 ATTACH、DETACH 和事务控制语句标记为只读后放行。

func CheckReadonlyStatementInBox

func CheckReadonlyStatementInBox(stmt, boxID string) error

CheckReadonlyStatementInBox 在指定笔记本对应的数据库连接上检查 SQL 是否只读。

func CheckSingleStatement

func CheckSingleStatement(stmt string) error

func ClearCache

func ClearCache()

func ClearQueue

func ClearQueue()

func CloseDatabase

func CloseDatabase()

func CloseEncryptedDB

func CloseEncryptedDB(boxID string)

CloseEncryptedDB 仅关闭加密笔记本的 db 连接(不删文件)。UnlockBox 创建失败回滚时调用。 关闭/锁定加密笔记本请用 RemoveEncryptedDBFile(关连接 + 删文件)。

func DefRefs

func DefRefs(condition string, limit int) (ret []map[*Block]*Block)

func DeleteAssetContentsByPathQueue

func DeleteAssetContentsByPathQueue(path string)

func DeleteBoxQueue

func DeleteBoxQueue(boxID string)

func DeleteBoxRefsQueue

func DeleteBoxRefsQueue(boxID string)

func DeleteOutdatedHistories

func DeleteOutdatedHistories(before int64)

func DeleteRefsTreeQueue

func DeleteRefsTreeQueue(tree *parse.Tree)

func Exec

func Exec(stmt string, args ...any) error

func ExistRefByDefIDs

func ExistRefByDefIDs(defIDs, defRootIDs, excludeBlockIDs, excludeRootIDs []string) (ret bool, err error)

ExistRefByDefIDs 检查全局库及所有已打开加密库中来自删除集合外部的引用。

func ExistRefByDefIDsInBox

func ExistRefByDefIDsInBox(defIDs, defRootIDs, excludeBlockIDs, excludeRootIDs []string, boxID string) (ret bool, err error)

ExistRefByDefIDsInBox 检查指定笔记本索引中是否存在来自删除集合外部的引用。

func FillAttributeViewNilValue

func FillAttributeViewNilValue(value *av.Value, typ av.KeyType)

func FillAttributeViewTemplateValuesForKeysWithContext

func FillAttributeViewTemplateValuesForKeysWithContext(attrView *av.AttributeView, view *av.View, collection av.Collection,
	keys map[string]bool, renderContext *AttributeViewRenderContext)

FillAttributeViewTemplateValuesForKeysWithContext 只求值指定字段,保留其他字段已计算的显示结果。 keys 为 nil 时求值全部模板,非 nil 的空集合不执行模板。

func FillAttributeViewTemplateValuesWithContext

func FillAttributeViewTemplateValuesWithContext(attrView *av.AttributeView, view *av.View, collection av.Collection,
	renderContext *AttributeViewRenderContext)

FillAttributeViewTemplateValuesWithContext 计算集合中当前条目的模板字段值和显示模板结果。

func FilterNonEmptyRefCheckIDs

func FilterNonEmptyRefCheckIDs(ids []string) (ret []string)

FilterNonEmptyRefCheckIDs 去空格、去空串并去重,保留首次出现的顺序。 供引用校验的多个入参列表共用,避免调用方各自实现一份。

func FilterVirtualRefKeywordsByAccess

func FilterVirtualRefKeywordsByAccess(keywords []string, boxID string, accessible func(string, string) bool) (ret []string)

FilterVirtualRefKeywordsByAccess 批量校验文档中的候选关键字,避免逐个扫描引用与块索引。

func FlushAssetContentQueue

func FlushAssetContentQueue() error

func FlushAssetContentTxJob

func FlushAssetContentTxJob()

func FlushHistoryQueue

func FlushHistoryQueue()

func FlushHistoryTxJob

func FlushHistoryTxJob()

func FlushQueue

func FlushQueue()

func FlushTxJob

func FlushTxJob()

func GetBlockAttrs

func GetBlockAttrs(id string) (ret map[string]string)

func GetContainerText

func GetContainerText(container *ast.Node) string

func GetDuplicatedRootIDs

func GetDuplicatedRootIDs(blocksTable string) (ret []string)

func GetEncryptedBoxIDs

func GetEncryptedBoxIDs() (ret []string)

GetEncryptedBoxIDs 返回所有已打开的加密 content db 对应的 boxID。

func GetEncryptedDB

func GetEncryptedDB(boxID string) *sql.DB

GetEncryptedDB 返回加密笔记本的 db 句柄;未打开返回 nil。

func GetFurtherCollections

func GetFurtherCollections(attrView *av.AttributeView,
	cachedAttrViews map[string]*av.AttributeView) map[string]*av.RollupRenderContext

func GetFurtherCollectionsWithContext

func GetFurtherCollectionsWithContext(attrView *av.AttributeView, cachedAttrViews map[string]*av.AttributeView,
	renderContext *AttributeViewRenderContext) map[string]*av.RollupRenderContext

GetFurtherCollectionsWithContext 使用指定的渲染上下文获取后续集合。

func GetRefDuplicatedDefRootIDs

func GetRefDuplicatedDefRootIDs() (ret []string)

func GetRefText

func GetRefText(defBlockID string) (ret string)

func GetRootUpdated

func GetRootUpdated() (ret map[string]string, err error)

func GetTemplateKeyRelevantKeys

func GetTemplateKeyRelevantKeys(attrView *av.AttributeView, templateKey *av.Key) (ret []*av.Key)

func GetTemplateKeysByResolutionOrder

func GetTemplateKeysByResolutionOrder(attrView *av.AttributeView) (ret []*av.Key, resolved bool)

func HasDocumentRefsOutsideRootsInBox

func HasDocumentRefsOutsideRootsInBox(rootID string, owned map[string]bool, boxID string) (bool, error)

HasDocumentRefsOutsideRootsInBox 为新建后失败的保守清理保留任何外部引用;查询错误不能当作无引用。

func IndexAssetContentsQueue

func IndexAssetContentsQueue(assetContents []*AssetContent)

func IndexHistoriesQueue

func IndexHistoriesQueue(histories []*History)

func IndexNodeQueue

func IndexNodeQueue(id string)

func IndexQueueIdle

func IndexQueueIdle() bool

IndexQueueIdle 在索引执行锁内检查队列,避免把已取出但尚未提交的操作误判为空闲。

func IndexRecoveryPending

func IndexRecoveryPending() bool

IndexRecoveryPending 供同步应用准入检查,涵盖正在处理和等待处理的历史记录。

func IndexTreeQueue

func IndexTreeQueue(tree *parse.Tree)

func InitAssetContentDatabase

func InitAssetContentDatabase(forceRebuild bool) error

func InitDatabase

func InitDatabase(forceRebuild bool)

func InitHistoryDatabase

func InitHistoryDatabase(forceRebuild bool)

func IsReusableTemplateKey

func IsReusableTemplateKey(attrView *av.AttributeView, key *av.Key) bool

IsReusableTemplateKey 仅接纳封闭的字段访问和字符串格式化,不依赖时间、SQL 或外部状态。

func MoveTreeQueue

func MoveTreeQueue(tree *parse.Tree)

func NodeStaticContent

func NodeStaticContent(node *ast.Node, excludeTypes []string, includeTextMarkATitleURL, includeAssetPath, fullAttrView bool) string

func NodeStaticContentWithoutOCRAssets

func NodeStaticContentWithoutOCRAssets(node *ast.Node, excludeTypes []string, includeTextMarkATitleURL, includeAssetPath, fullAttrView bool) string

NodeStaticContentWithoutOCRAssets 与 NodeStaticContent 相同,但不读取资源的 OCR 文本。

func OpenEncryptedDB

func OpenEncryptedDB(boxID string, dek []byte) (err error)

OpenEncryptedDB 打开加密笔记本的独立 SQLCipher db 并注册到 encryptedDBs。 dek 是该 box 的 32 字节数据密钥;先用 HKDF 派生 content 子密钥(用途分离),DSN 用 raw key 格式 x'<hex>'。 首次打开会建表(幂等 IF NOT EXISTS)。UnlockBox 时调用。

func Query

func Query(stmt string, limit int) (ret []map[string]any, err error)

func QueryAssetContentNoLimit

func QueryAssetContentNoLimit(stmt string) (ret []map[string]any, err error)

func QueryAssetContentNoLimitArgs

func QueryAssetContentNoLimitArgs(stmt string, args ...any) (ret []map[string]any, err error)

QueryAssetContentNoLimitArgs 使用绑定参数查询资源文件内容数据库。

func QueryAttributeViewRefDefIDsByBlockIDsInBox

func QueryAttributeViewRefDefIDsByBlockIDsInBox(blockIDs []string, boxID string) (ret []string)

QueryAttributeViewRefDefIDsByBlockIDsInBox 按数据库载体块查询属性视图引用的定义块 ID。

func QueryBacklinkRefDefsInBox

func QueryBacklinkRefDefsInBox(blockIDs []string, boxID string) (ret map[string][]string, err error)

QueryBacklinkRefDefsInBox 批量读取条目内容块的引用关系,保留数据库隔离边界。

func QueryBlockAliasesInBox

func QueryBlockAliasesInBox(rootID, boxID string) (ret []string)

QueryBlockAliasesInBox 按 rootID 在指定 box 的 db 里查块别名(按逗号拆分去重)。

func QueryBlockDefIDsByRefTextInBox

func QueryBlockDefIDsByRefTextInBox(refText, boxID string, accessible func(string, string) bool) (ret []string)

func QueryBlockNamesByRootIDInBox

func QueryBlockNamesByRootIDInBox(rootID, boxID string) (ret []string)

QueryBlockNamesByRootIDInBox 按 rootID 在指定 box 的 db 里查块命名。

func QueryBookmarkLabels

func QueryBookmarkLabels() (ret []string)

func QueryBoundBlockAVIDs

func QueryBoundBlockAVIDs(blockIDs, rootIDs []string) (ret map[string][]string, err error)

QueryBoundBlockAVIDs 查询全局库及所有已打开加密库中删除集合内的数据库绑定块。

func QueryBoundBlockAVIDsInBox

func QueryBoundBlockAVIDsInBox(blockIDs, rootIDs []string, boxID string) (ret map[string][]string, err error)

QueryBoundBlockAVIDsInBox 查询删除集合中绑定块所属的属性视图。

func QueryChildDefIDsByRootDefID

func QueryChildDefIDsByRootDefID(rootDefID string) (ret []string)

func QueryChildDefIDsByRootDefIDInBox

func QueryChildDefIDsByRootDefIDInBox(rootDefID, boxID string) (ret []string)

QueryChildDefIDsByRootDefIDInBox 按定义文档根 ID 查询存在引用的子定义块,按 boxID 路由。

func QueryChildRefDefIDsByRootDefIDInBox

func QueryChildRefDefIDsByRootDefIDInBox(rootDefID, boxID string) (ret map[string][]string)

QueryChildRefDefIDsByRootDefIDInBox 按 rootDefID 查子引用定义,按 boxID 路由。

func QueryDailyNoteRootIDsInBox

func QueryDailyNoteRootIDsInBox(boxID, name, date string) (ids []string, err error)

QueryDailyNoteRootIDsInBox 按日记属性查询文档,限定笔记本并保留数据库错误。

func QueryDocTreeRefCounts

func QueryDocTreeRefCounts(ids, boxes []string, visible func(string, string) bool) (map[string]int, error)

QueryDocTreeRefCounts 只查询所需根文档;ids 为 nil 时用于引用数排序的首次构建。 boxes 由调用方已持有的笔记本租约确定,空字符串表示普通数据库。

func QueryExactDocTitleIDInBox

func QueryExactDocTitleIDInBox(title, id, rootID, boxID string) (ret string, err error)

QueryExactDocTitleIDInBox 按完整文档标题查询,先精确匹配,再匹配 Unicode 大小写,保留数据库错误。

func QueryHistory

func QueryHistory(stmt string) (ret []map[string]any, err error)

func QueryImageSpanMarkdowns

func QueryImageSpanMarkdowns() (ret []string, err error)

QueryImageSpanMarkdowns 读取全局索引中的图片引用,保留同一段落内各图片的元数据归属。

func QueryNoLimit

func QueryNoLimit(stmt string) (ret []map[string]any, err error)

func QueryNoLimitArgs

func QueryNoLimitArgs(stmt string, args ...any) (ret []map[string]any, err error)

QueryNoLimitArgs 与 QueryNoLimit 一致,但支持参数化查询(stmt 中用 ? 占位,args 顺序填入)。 用于 embedding 索引器按 fail_count/last_tried 调度时的带参 SELECT。

func QueryNoLimitArgsInBox

func QueryNoLimitArgsInBox(stmt, boxID string, args ...any) (ret []map[string]any, err error)

QueryNoLimitArgsInBox 与 QueryNoLimitInBox 一致,但支持参数化查询。

func QueryNoLimitArgsInBoxContext

func QueryNoLimitArgsInBoxContext(ctx context.Context, stmt, boxID string, args ...any) (ret []map[string]any, err error)

QueryNoLimitArgsInBoxContext 在请求取消时中断参数化查询,并保留笔记本数据库路由。

func QueryNoLimitInBox

func QueryNoLimitInBox(stmt, boxID string) (ret []map[string]any, err error)

QueryNoLimitInBox 在指定 box 的 db 里执行无 limit 的原始查询(返回 map 行)。

func QueryNoLimitInBoxContext

func QueryNoLimitInBoxContext(ctx context.Context, stmt, boxID string) (ret []map[string]any, err error)

func QueryRefCountInBox

func QueryRefCountInBox(defIDs []string, boxID string) (ret map[string]int)

QueryRefCountInBox 按 defBlockIDs 在指定 box 的 db 里查引用计数。

func QueryRefCountInBoxContext

func QueryRefCountInBoxContext(ctx context.Context, defIDs []string, boxID string) (ret map[string]int)

QueryRefCountInBoxContext 在搜索取消后停止引用计数,沿用原有的笔记本隔离。

func QueryRefIDsByAnnotationID

func QueryRefIDsByAnnotationID(annotationID string) (refIDs []string)

func QueryRefIDsByAnnotationIDInBox

func QueryRefIDsByAnnotationIDInBox(annotationID, boxID string) (refIDs []string)

func QueryRefIDsByDefID

func QueryRefIDsByDefID(defID string, containChildren bool) (refIDs []string)

func QueryRefIDsByDefIDInBox

func QueryRefIDsByDefIDInBox(defID string, containChildren bool, boxID string) (refIDs []string)

QueryRefIDsByDefIDInBox 按 defID 查引用 ID 列表,按 boxID 路由。

func QueryRefRootBlocksByDefRootIDs

func QueryRefRootBlocksByDefRootIDs(defRootIDs []string) (ret map[string][]*Block)

func QueryRootBlockRefCount

func QueryRootBlockRefCount() (ret map[string]int)

func QueryRootChildrenRefCountInBox

func QueryRootChildrenRefCountInBox(defRootID, boxID string) (ret map[string]int)

QueryRootChildrenRefCountInBox 按 defRootID 在指定 box 的 db 里查询根文档下各块的引用计数。

func QueryTagCounts

func QueryTagCounts() (map[string]int, error)

func QueryVirtualRefKeywords

func QueryVirtualRefKeywords(name, alias, anchor, doc bool, searchIgnoreLines, refSearchIgnoreLines []string, boxIDs ...string) (ret []string)

func ReadTagAssociations

func ReadTagAssociations(withDates bool, consume func(label, attrs, box, path string, count int)) error

func RebuildFTSIndex

func RebuildFTSIndex() (err error)

func RefreshDefinitionRefsQueue

func RefreshDefinitionRefsQueue(boxID string, ids []string)

RefreshDefinitionRefsQueue follows the committed source/target indexing operations. Recovery needs only stable IDs, never the reference source files.

func RefreshHPathsBatch

func RefreshHPathsBatch(doc *treenode.BlockTree, blockAfter, treeAfter int64, limit int) (nextBlock, nextTree int64, done, busy bool, err error)

RefreshHPathsBatch 只在普通索引空闲时执行一个批次,不占用普通任务队列等待下一批。

func RemapTemplateFieldIDs

func RemapTemplateFieldIDs(source string, ids map[string]string) string

RemapTemplateFieldIDs 仅替换可静态识别的字段身份查找,不替换普通文字或变量声明。 使用独立解析树的字节位置编辑原文;无效模板及动态构造的字段身份保持原样。

func RemoveAllEncryptedDBFiles

func RemoveAllEncryptedDBFiles()

RemoveAllEncryptedDBFiles 关闭所有已打开的加密 content db 连接并删除其文件(含 WAL/SHM)。 进程退出(CloseDatabase)时调用,避免重启后残留旧索引数据导致下次解锁叠加重复行。

func RemoveEncryptedDBFile

func RemoveEncryptedDBFile(boxID string)

RemoveEncryptedDBFile 关闭连接并删除加密 db 文件(含 WAL/SHM)。删除笔记本、关闭加密笔记本时调用。

func RemoveTreePathQueue

func RemoveTreePathQueue(treeBox, treePathPrefix string)

func RemoveTreeQueue

func RemoveTreeQueue(boxID, rootID string)

func RenameDocQueue

func RenameDocQueue(tree *parse.Tree)

RenameDocQueue 及时更新文档标题,内容块的路径副本由独立后台任务补齐。

func RenderAttributeViewTable

func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query string, depth *int, cachedAttrViews map[string]*av.AttributeView, ignoreRows bool) (ret *av.Table)

func RenderGroupView

func RenderGroupView(attrView *av.AttributeView, view, groupView *av.View, query string) (ret av.Viewable)

func RenderGroupViewWithSource

func RenderGroupViewWithSource(attrView *av.AttributeView, view, groupView *av.View, query string,
	source *GroupViewRenderSource, ignoreRows bool) (ret av.Viewable)

RenderGroupViewWithSource 优先从父视图条目索引组装分组;布局或查询不匹配时沿用独立渲染。

func RenderGroupViewWithSourceContext

func RenderGroupViewWithSourceContext(attrView *av.AttributeView, view, groupView *av.View, query string,
	source *GroupViewRenderSource, ignoreRows bool, context *AttributeViewRenderContext) (ret av.Viewable)

RenderGroupViewWithSourceContext 使用指定的渲染上下文渲染分组视图。

func RenderView

func RenderView(attrView *av.AttributeView, view *av.View, query string, ignoreRows bool) (ret av.Viewable)

func RenderViewGroupItems

func RenderViewGroupItems(attrView *av.AttributeView, view *av.View) []av.Item

func RenderViewItem

func RenderViewItem(attrView *av.AttributeView, view *av.View, itemID string) av.Viewable

RenderViewItem 为属性面板计算单条记录,关联汇总仅物化该记录依赖的条目。

func RenderViewItemWithContext

func RenderViewItemWithContext(attrView *av.AttributeView, view *av.View, itemID string, context *AttributeViewRenderContext) av.Viewable

单条元数据读取可显式禁止派生值持久化,且保留数据库已固定的依赖读取边界。

func RenderViewWithContext

func RenderViewWithContext(attrView *av.AttributeView, view *av.View, query string, ignoreRows bool,
	renderContext *AttributeViewRenderContext) (ret av.Viewable)

RenderViewWithContext 使用指定的渲染上下文渲染属性视图。

func RenderViewWithDeferredTemplatesContext

func RenderViewWithDeferredTemplatesContext(attrView *av.AttributeView, view *av.View, query string, ignoreRows bool,
	renderContext *AttributeViewRenderContext) (ret av.Viewable)

RenderViewWithDeferredTemplatesContext 生成尚未计算模板字段的普通视图。

func SQLTemplateFuncs

func SQLTemplateFuncs(templateFuncMap *template.FuncMap, boxIDs ...string)

func SetCaseSensitive

func SetCaseSensitive(b bool)

func SetHanSensitive

func SetHanSensitive(b bool)

func SetIndexAssetPath

func SetIndexAssetPath(b bool)

func StaticTemplateKeyDependencies

func StaticTemplateKeyDependencies(attrView *av.AttributeView, key *av.Key) ([]*av.Key, bool)

StaticTemplateKeyDependencies 复用字段依赖解析,仅为可静态识别的表达式返回完整依赖。 分支、命名模板、变量别名或动态访问保留完整求值路径,避免将遗漏依赖当成显示字段。

func TreeHasRefs

func TreeHasRefs(tree *parse.Tree) bool

TreeHasRefs uses the same extraction as normal indexing, including rich inline titles, attribute views and embedded references.

func UpdateBlockContentQueue

func UpdateBlockContentQueue(block *Block)

func UpdateRefsTreeQueue

func UpdateRefsTreeQueue(tree *parse.Tree)

func UpsertTreeQueue

func UpsertTreeQueue(tree *parse.Tree)

func UpsertTreeQueueWithChanges

func UpsertTreeQueueWithChanges(tree *parse.Tree, changes *TreeIndexChanges)

UpsertTreeQueueWithChanges 合并同一文档的影响集合;未知影响范围或有序操作边界保留完整更新。

func Vacuum

func Vacuum()

func WaitFlushTx

func WaitFlushTx()

Types

type Asset

type Asset struct {
	ID      string
	BlockID string
	RootID  string
	Box     string
	DocPath string
	Path    string
	Name    string
	Title   string
	Hash    string
}

func QueryAssetByHash

func QueryAssetByHash(hash string) (ret *Asset)

func QueryOCRAssetDocuments

func QueryOCRAssetDocuments(paths map[string]bool, refreshAll bool) ([]Asset, error)

type AssetContent

type AssetContent struct {
	ID      string
	Name    string
	Ext     string
	Path    string
	Size    int64
	Updated int64
	Content string
}

func SelectAssetContentsRawStmt

func SelectAssetContentsRawStmt(stmt string, page, limit int) (ret []*AssetContent)

func SelectAssetContentsRawStmtNoParse

func SelectAssetContentsRawStmtNoParse(stmt string, limit int) (ret []*AssetContent)

func SelectAssetContentsRawStmtNoParseArgs

func SelectAssetContentsRawStmtNoParseArgs(stmt string, args []any, limit int) (ret []*AssetContent)

SelectAssetContentsRawStmtNoParseArgs 使用绑定参数查询资源文件内容,并保留调用方构造的 SQL。

type Attribute

type Attribute struct {
	ID      string
	Name    string
	Value   string
	Type    string
	BlockID string
	RootID  string
	Box     string
	Path    string
}

type AttributeViewRenderContext

type AttributeViewRenderContext struct {
	HTTPPreview             *HTTPTemplatePreview
	TemplateHTTP            *templatehttp.Execution
	TemplateHTTPSourceScope func(owner, avID, keyID, slot, content string) string

	ReadOnly                  bool   // 预览只允许修正内存副本,不保存缺失字段等订正结果。
	HistoricalAttributeViewID string // 已认证历史源的条目及块属性取自源数据,不使用实时块索引裁剪。
	// contains filtered or unexported fields
}

AttributeViewRenderContext 收集一次属性视图渲染期间产生的模板错误。

func NewAttributeViewRenderContext

func NewAttributeViewRenderContext() *AttributeViewRenderContext

NewAttributeViewRenderContext 创建属性视图渲染上下文。

func (*AttributeViewRenderContext) HTTPTemplateError

func (context *AttributeViewRenderContext) HTTPTemplateError() error

HTTPTemplateError 仅将取消、锁定和执行预算终止提升为整个渲染失败。

func (*AttributeViewRenderContext) HasTemplateErrors

func (context *AttributeViewRenderContext) HasTemplateErrors() bool

HasTemplateErrors 判断本次求值是否产生模板错误,错误结果不参与跨请求复用。

func (*AttributeViewRenderContext) PushTemplateErrors

func (context *AttributeViewRenderContext) PushTemplateErrors()

type Block

type Block struct {
	ID       string
	ParentID string
	RootID   string
	Hash     string
	Box      string
	Path     string
	HPath    string
	Name     string
	Alias    string
	Memo     string
	Tag      string
	Content  string
	FContent string
	Markdown string
	Length   int
	Type     string
	SubType  string
	IAL      string
	Sort     int
	Created  string
	Updated  string
}

func BuildBlockFromNode

func BuildBlockFromNode(n *ast.Node, tree *parse.Tree) (block *Block)

func GetAllChildBlocks

func GetAllChildBlocks(rootIDs []string, condition string, limit int) (ret []*Block)

func GetAllRootBlocks

func GetAllRootBlocks() (ret []*Block)

func GetBlock

func GetBlock(id string) (ret *Block)

func GetBlockInBox

func GetBlockInBox(id, boxID string) (ret *Block)

GetBlockInBox 按 id 在指定 box 的 db 里查 block。boxID 为空则查全局 db。

func GetBlocks

func GetBlocks(ids []string) (ret []*Block)

func GetBlocksInBox

func GetBlocksInBox(ids []string, boxID string) (ret []*Block)

GetBlocksInBox 按 ids 在指定 box 的 db 里批量查 block。

func GetBlocksInBoxContext

func GetBlocksInBoxContext(ctx context.Context, ids []string, boxID string) (ret []*Block)

GetBlocksInBoxContext 保留缓存、分批查询和输入顺序,并在请求取消后停止读取。

func GetChildBlocks

func GetChildBlocks(parentID, condition string, limit int) (ret []*Block)

func GetChildBlocksInBox

func GetChildBlocksInBox(parentID, condition string, limit int, boxID string) (ret []*Block)

GetChildBlocksInBox 按 parentID 在指定 box 的 db 里查所有子块。

func QueryBookmarkBlocks

func QueryBookmarkBlocks() (ret []*Block)

func QueryDefRootBlocksByRefRootID

func QueryDefRootBlocksByRefRootID(refRootID string) (ret []*Block)

func QueryEmptyContentEmbedBlocks

func QueryEmptyContentEmbedBlocks() (ret []*Block)

func QueryEmptyContentEmbedBlocksInBox

func QueryEmptyContentEmbedBlocksInBox(boxID string) (ret []*Block)

func QueryRootBlockByCondition

func QueryRootBlockByCondition(condition, exactKeyword string, limit int, args ...any) (ret []*Block)

func QueryRootBlockByConditionInBox

func QueryRootBlockByConditionInBox(condition, exactKeyword string, limit int, boxID string, args ...any) (ret []*Block)

func SelectBlocksRawStmt

func SelectBlocksRawStmt(stmt string, page, limit int) (ret []*Block)

func SelectBlocksRawStmtArgs

func SelectBlocksRawStmtArgs(stmt string, args []any, limit int) (ret []*Block)

SelectBlocksRawStmtArgs 与 selectBlocksRawStmt 行为一致,但通过绑定参数执行, 绕开 sqlparser 解析(vitess 会把 "?" 改写为 ":vN" 导致占位失效),用于含用户可控参数的搜索语句。

func SelectBlocksRawStmtArgsInBox

func SelectBlocksRawStmtArgsInBox(stmt string, args []any, limit int, boxID string) (ret []*Block)

SelectBlocksRawStmtArgsInBox 在指定 box 的 db 里执行参数化原始 SQL 查询 blocks。 与 SelectBlocksRawStmtArgs 对应,绕开 sqlparser 对 "?" 占位的改写。

func SelectBlocksRawStmtArgsInBoxContext

func SelectBlocksRawStmtArgsInBoxContext(ctx context.Context, stmt string, args []any, limit int, boxID string) (ret []*Block, err error)

SelectBlocksRawStmtArgsInBoxContext 取消参数化块查询,不将取消后的部分行作为完整结果返回。

func SelectBlocksRawStmtBoundedInBoxContext

func SelectBlocksRawStmtBoundedInBoxContext(ctx context.Context, stmt string, limit int, boxID string) (ret []*Block, truncated bool, err error)

SelectBlocksRawStmtBoundedInBoxContext 执行原始块查询,并无条件限制返回行数。

func SelectBlocksRawStmtInBox

func SelectBlocksRawStmtInBox(stmt string, page, limit int, boxID string) (ret []*Block)

SelectBlocksRawStmtInBox 在指定 box 的 db 里执行原始 SQL 查询 blocks。

func SelectBlocksRawStmtInBoxContext

func SelectBlocksRawStmtInBoxContext(ctx context.Context, stmt string, page, limit int, boxID string) (ret []*Block, err error)

func SelectBlocksRawStmtNoParse

func SelectBlocksRawStmtNoParse(stmt string, limit int) (ret []*Block)

func SelectBlocksRawStmtNoParseInBox

func SelectBlocksRawStmtNoParseInBox(stmt string, limit int, boxID string) (ret []*Block)

SelectBlocksRawStmtNoParseInBox 与 SelectBlocksRawStmtNoParse 一致,但按 boxID 路由。

func SelectBlocksRegexArgsInBoxContext

func SelectBlocksRegexArgsInBoxContext(ctx context.Context, stmt string, exp *regexp.Regexp, name, alias, memo, ial bool, page, pageSize int, boxID string, args ...any) (ret []*Block, err error)

SelectBlocksRegexArgsInBoxContext 同时中断数据库扫描和逐块正则高亮。

func SelectBlocksRegexInBox

func SelectBlocksRegexInBox(stmt string, exp *regexp.Regexp, name, alias, memo, ial bool, page, pageSize int, boxID string) (ret []*Block)

SelectBlocksRegexInBox 在指定 box 的 db 里执行正则匹配查询 blocks(无占位参数版)。

func SelectFTSBlocksWithCountContext

func SelectFTSBlocksWithCountContext(ctx context.Context, statement, countStatement string, args []any) (blocks []*Block, matches, docs int, err error)

SelectFTSBlocksWithCountContext 在同一普通库读取快照内取得分页行及精确计数。 仅供固定 FTS 查询使用;加密库、自定义 SQL 和动态忽略条件使用各自的既有路径。

func ToBlocks

func ToBlocks(result []map[string]any) (ret []*Block)

func (*Block) IsContainerBlock

func (block *Block) IsContainerBlock() bool

type BookmarkLabelBlock

type BookmarkLabelBlock struct {
	Label string
	Box   string
	Path  string
}

func QueryBookmarkLabelBlocks

func QueryBookmarkLabelBlocks() (ret []*BookmarkLabelBlock)

type FileAnnotationRef

type FileAnnotationRef struct {
	ID           string
	FilePath     string
	AnnotationID string
	BlockID      string
	RootID       string
	Box          string
	Path         string
	Content      string
	Type         string
}

type GroupViewRenderSource

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

GroupViewRenderSource 保存分组渲染可复用的条目索引。 索引中的条目已经完成字段值生成和查询过滤,各分组仍会独立执行视图过滤、排序、统计和分页。

func NewGroupViewRenderSource

func NewGroupViewRenderSource(viewable av.Viewable, query string) (ret *GroupViewRenderSource)

NewGroupViewRenderSource 在父视图分页前建立可供所有同布局分组复用的条目索引。

func (*GroupViewRenderSource) GetItems

func (source *GroupViewRenderSource) GetItems() (ret []av.Item)

GetItems 返回父视图分页前的完整有序条目列表。

type HTTPTemplatePreview

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

func (*HTTPTemplatePreview) Pending

func (preview *HTTPTemplatePreview) Pending() []string

func (*HTTPTemplatePreview) Prepare

func (preview *HTTPTemplatePreview) Prepare(database *av.AttributeView) bool

Prepare 同库模板共享求值顺序,首屏一并延后,避免下游模板读取未完成的联网结果。

type History

type History struct {
	ID      string
	Type    int
	Op      string
	Title   string
	Content string
	Created string
	Path    string
}

func SelectHistoriesRawStmt

func SelectHistoriesRawStmt(stmt string) (ret []*History)

type QueryLimitInfo

type QueryLimitInfo struct {
	Limit     int  `json:"limit"`
	Truncated bool `json:"truncated"`
}

QueryLimitInfo 描述查询行数限制;Limit 为零表示使用 SQL 自身的限制。

func QueryWithLimitInfo

func QueryWithLimitInfo(stmt string, limit int) (rows []map[string]any, info QueryLimitInfo, err error)

QueryWithLimitInfo 在同一次查询中多读取一行,判断默认限制是否截断了结果。

func QueryWithRowLimitInfo

func QueryWithRowLimitInfo(stmt string, limit int) (rows []map[string]any, info QueryLimitInfo, err error)

QueryWithRowLimitInfo 在 SQL 自身限制之外封顶返回行数,并多读取一行判断是否截断。 直接执行原始语句,保留注释、递归查询和解析器不支持的 SQLite 语法。

type Ref

type Ref struct {
	ID               string
	DefBlockID       string
	DefBlockParentID string
	DefBlockRootID   string
	DefBlockPath     string
	BlockID          string
	RootID           string
	Box              string
	Path             string
	Content          string
	Markdown         string
	Type             string
}

func GetRefsCacheByDefID

func GetRefsCacheByDefID(defID string) (ret []*Ref)

func GetRefsCacheByDefIDInBox

func GetRefsCacheByDefIDInBox(defID, boxID string) (ret []*Ref)

func QueryRefsByDefID

func QueryRefsByDefID(defBlockID string, containChildren bool) (ret []*Ref)

func QueryRefsByDefIDInBox

func QueryRefsByDefIDInBox(defBlockID string, containChildren bool, boxID string) (ret []*Ref)

QueryRefsByDefIDInBox 按 defBlockID 在指定 box 的 db 里查引用列表。 containChildren 为 true 时递归查询定义块及其所有子块,与 QueryRefsByDefID 保持一致。

func QueryRefsByDefIDRefIDInBox

func QueryRefsByDefIDRefIDInBox(defBlockID, refBlockID, boxID string) (ret []*Ref)

QueryRefsByDefIDRefIDInBox 按 defBlockID+refBlockID 在指定 box 的 db 里查引用。

func QueryRefsByDefIDsInBox

func QueryRefsByDefIDsInBox(defBlockIDs []string, boxID string) (ret []*Ref)

QueryRefsByDefIDsInBox 按一组定义块 ID 查询引用,按 boxID 路由。

func QueryRefsRecentInBox

func QueryRefsRecentInBox(onlyDoc bool, typeFilter string, ignoreLines, recentDefBlockIDs []string, boxID string) (ret []*Ref)

QueryRefsRecentInBox 按 boxID 路由查最近引用,用于加密笔记本内的块引搜索。

type Span

type Span struct {
	ID       string
	BlockID  string
	RootID   string
	Box      string
	Path     string
	Content  string
	Markdown string
	Type     string
	IAL      string
}

func QueryTagSpans

func QueryTagSpans(p string) (ret []*Span)

func QueryTagSpansByKeyword

func QueryTagSpansByKeyword(keyword string, limit int) (ret []*Span)

func QueryTagSpansByLabel

func QueryTagSpansByLabel(label string) (ret []*Span)

func SelectSpansRawStmt

func SelectSpansRawStmt(stmt string, limit int) (ret []*Span)

func SelectSpansRawStmtInBox

func SelectSpansRawStmtInBox(stmt string, limit int, boxID string) (ret []*Span)

type Stat

type Stat struct {
	Key string `json:"key"`
	Val string `json:"value"`
}

type TreeIndexChanges

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

TreeIndexChanges 是完整事务影响集合的进程内提示;nil 表示必须重新生成全部主块投影。 集合须包含变更、删除和替换子树的块以及受影响容器,入队时复制且不写入恢复队列。

func NewTreeIndexChanges

func NewTreeIndexChanges(blockIDs []string) *TreeIndexChanges

Jump to

Keyboard shortcuts

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