logseq-schema
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLogseq Schema
Logseq 模式
Overview
概述
Use this skill to ground Datascript queries in Logseq's schema: core block/page/file attributes, built-in properties, built-in classes, and schema entities with :db/ident. Load for authoritative sources and query patterns, and
for scenario-based query examples.
references/logseq-datascript-schema.mdreferences/logseq-datascript-query-examples.md使用此技能可让Datascript查询基于Logseq的模式:核心块/页面/文件属性、内置属性、内置类,以及带有:db/ident的模式实体。加载获取权威来源和查询模式,加载获取基于场景的查询示例。
references/logseq-datascript-schema.mdreferences/logseq-datascript-query-examples.mdGlossary
术语表
- : Internal numeric entity id (use with CLI flags like
db/id).--id - : Stable UUID for a block entity; prefer when you need a persistent reference.
:block/uuid - : Lowercased page name, used for page lookup and joins.
:block/name - : Block or page title stored in the DB graph (use in queries when content text is needed).
:block/title - : Ref-many attribute linking blocks to tag/page entities.
:block/tags - : Namespace for user-defined properties stored directly on block entities.
:user.property/<name> - : Namespace for built-in properties stored directly on block entities.
:logseq.property/*
- : 内部数字实体ID(配合
db/id等CLI标志使用)。--id - : 块实体的稳定UUID;当需要持久化引用时优先使用。
:block/uuid - : 小写的页面名称,用于页面查找和关联。
:block/name - : 存储在数据库图谱中的块或页面标题(当需要内容文本时在查询中使用)。
:block/title - : 多引用属性,用于关联块与标签/页面实体。
:block/tags - : 直接存储在块实体上的用户自定义属性命名空间。
:user.property/<name> - : 直接存储在块实体上的内置属性命名空间。
:logseq.property/*
Important Notes
重要说明
- Never use following block attrs in or
query, these attrs are file-graph only, never used in db-graphs:pull,:block/format,:block/level,:block/level-spaces,:block/pre-block?,:block/properties-order,:block/properties-text-values,:block/invalid-properties,:block/macros,:block/file,:block.temp/ast-body,:block.temp/ast-blocks,:block/marker,:block/content,:block/priority,:block/scheduled,:block/deadline,:block/properties.:block/left - User properties are stored as attributes on the block/page entity.
:user.property/<name> - Pull selectors do NOT support namespace wildcards like or
:user.property/*. Only:logseq.property/*(all attributes) or explicit attributes are allowed in*.pull - To fetch user properties, either:
- Query datoms and filter attributes by namespace (e.g., ), then merge into the entity map, or
user.property - Discover explicit user property idents (via ) and include them explicitly in the pull selector.
:db/ident
- Query datoms and filter attributes by namespace (e.g.,
- Property values are often entities/refs (not always scalars). When rendering values, check for ,
:block/title, or:block/nameon the value entity before falling back to stringifying.:logseq.property/value - Many properties are (values may be sets/vectors). Treat them as collections in queries and formatting.
:db.cardinality/many
- 切勿在或
query中使用以下块属性,这些属性仅属于文件图谱,从不用于数据库图谱:pull,:block/format,:block/level,:block/level-spaces,:block/pre-block?,:block/properties-order,:block/properties-text-values,:block/invalid-properties,:block/macros,:block/file,:block.temp/ast-body,:block.temp/ast-blocks,:block/marker,:block/content,:block/priority,:block/scheduled,:block/deadline,:block/properties。:block/left - 用户属性以属性的形式存储在块/页面实体上。
:user.property/<name> - 拉取选择器不支持命名空间通配符,如或
:user.property/*。在:logseq.property/*中仅允许使用pull(所有属性)或明确的属性。* - 要获取用户属性,可选择以下两种方式:
- 查询数据原子并按命名空间过滤属性(例如),然后合并到实体映射中;
user.property - 发现明确的用户属性标识符(通过)并将其明确包含在拉取选择器中。
:db/ident
- 查询数据原子并按命名空间过滤属性(例如
- 属性值通常是实体/引用(并非总是标量)。渲染值时,先检查值实体上的、
:block/title或:block/name,再回退到字符串化处理。:logseq.property/value - 许多属性是(值可能是集合/向量)。在查询和格式化时将其视为集合处理。
:db.cardinality/many
Datascript Query Mistakes To Avoid
需避免的Datascript查询错误
- In
query/:where/pull, attributes cannot use namespace wildcards (e.g.,find,:logseq.property/*); you must use full attr:user.property/*values (e.g.,:db/ident,:logseq.property/status). In:user.property/background, onlypull(all attributes) is special.* - Avoid nesting function calls inside predicates in (some Datascript engines reject or mis-handle it). Bind the function result first, then compare.
:where
Example of safe namespace filtering:
clojure
[:find [?a ...]
:where
[?e :db/ident ?a]
[(namespace ?a) ?ns]
[(= ?ns "user.property")]]- 在的
query/:where/pull中,属性不能使用命名空间通配符(例如find、:logseq.property/*);必须使用完整的属性:user.property/*值(例如:db/ident、:logseq.property/status)。在:user.property/background中,只有pull(所有属性)是特殊用法。* - 避免在的谓词中嵌套函数调用(部分Datascript引擎会拒绝或错误处理)。先绑定函数结果,再进行比较。
:where
安全的命名空间过滤示例:
clojure
[:find [?a ...]
:where
[?e :db/ident ?a]
[(namespace ?a) ?ns]
[(= ?ns "user.property")]]Workflow
工作流程
1) Locate schema facts
1) 查找模式信息
- Open .
references/logseq-datascript-schema.md - Review the core attribute list and helper sets for ref/cardinality details.
- Review built-in properties and classes to understand available attributes and required fields.
- 打开。
references/logseq-datascript-schema.md - 查看核心属性列表和辅助集合,了解引用/基数的详细信息。
- 查看内置属性和类,了解可用属性和必填字段。
2) Write or validate queries
2) 编写或验证查询
- Prefer attributes for block/page queries; use properties/classes only when needed.
:block/* - If unsure about available entities, run the CLI query listed in the references file.
:db/ident - For user properties, query against directly; for built-ins, use
:user.property/<name>.:logseq.property/<name>
- 在块/页面查询中优先使用属性;仅在需要时使用属性/类。
:block/* - 如果不确定可用的实体,运行参考文件中列出的CLI查询。
:db/ident - 对于用户属性,直接查询;对于内置属性,使用
:user.property/<name>。:logseq.property/<name>
3) Keep queries consistent with schema
3) 保持查询与模式一致
- Respect ref vs scalar attributes and when joining.
:db.cardinality/many - Use property/class definitions to confirm public/queryable status before exposing a query to users.
- 关联时要区分引用属性和标量属性,以及。
:db.cardinality/many - 在向用户公开查询之前,使用属性/类定义确认其公开/可查询状态。
Resources
资源
references/
references/
logseq-datascript-schema.mdlogseq-datascript-query-examples.md
logseq-datascript-schema.mdlogseq-datascript-query-examples.md
Quick Examples
快速示例
Pull user properties for a block
拉取块的用户属性
clojure
;; Discover idents, then pull explicitly.
[:db/id :block/title :user.property/background :user.property/notes]clojure
;; 发现标识符,然后明确拉取。
[:db/id :block/title :user.property/background :user.property/notes]Query blocks with a user property
查询带有用户属性的块
clojure
[:find ?b ?v
:where
[?b :user.property/background ?v]]clojure
[:find ?b ?v
:where
[?b :user.property/background ?v]]Render a property value
渲染属性值
Order of preference when value is a map/entity:
:block/title:block/name:logseq.property/value
当值为映射/实体时,优先顺序:
:block/title:block/name:logseq.property/value