This note explains how properties work in Logseq when using a DB graph (database mode), how that differs from a file graph (Markdown/Org), and how to use the plugin SDK APIs defined in libs/src/LSPlugin.ts.
Scope: This is written for plugin developers. It focuses on
logseq.Editor.*property APIs and tag/class modeling.
---):PROPERTIES:)key:: value)Editor.insertBlock/updateBlock have opts.properties, but note this warning in the typings:
IBatchBlock.properties is not supported for DB graph.DB mode treats properties as first-class DB entities.
Think of it as a 2-layer model:
1) Property definitions (schema)
rating, authors, zotero_key) exists as an entity.2) Property values (data)
key:: value text).In DB graphs, prefer the dedicated APIs:
Editor.getProperty / upsertProperty / removePropertyEditor.upsertBlockProperty / removeBlockProperty / getBlockPropertiesLSPlugin.ts)PropertySchemaexport type PropertySchema = {
type: 'default' | 'number' | 'node' | 'date' | 'checkbox' | 'url' | string,
cardinality: 'many' | 'one',
hide: boolean
public: boolean
}
Practical meaning:
type
default, number, date, checkbox, url, node.cardinality
'one': a single value'many': multiple values (typically passed as an array)hide
public
BlockEntity: blocks, but also used for some “special blocks” such as property entities.PageEntity: pages, tags (classes), property pages (type: 'property'), etc.BlockIdentity: a block uuid string OR { uuid }.Before doing DB-only work, check graph type:
const isDbGraph = await logseq.App.checkCurrentIsDbGraph()
if (!isDbGraph) {
await logseq.UI.showMsg('This feature requires a DB graph.', 'warning')
return
}
// Also check app-level capability:
const { supportDb } = await logseq.App.getInfo()
const propEntity = await logseq.Editor.getProperty('zotero_key')
// -> BlockEntity | null
Use upsertProperty to ensure the property exists and has the schema you expect.
await logseq.Editor.upsertProperty(
'zotero_key',
{
type: 'default',
cardinality: 'one',
hide: false,
public: true,
},
{ name: 'Zotero Key' }
)
Notes:
key is your stable identifier (recommend snake_case).opts.name can be used as a display name for users.await logseq.Editor.removeProperty('zotero_key')
const block = await logseq.Editor.getCurrentBlock()
if (!block) return
await logseq.Editor.upsertBlockProperty(block.uuid, 'zotero_key', 'ABCD1234')
cardinality: 'many')For many, pass an array. Use { reset: true } when you want to overwrite vs merge.
await logseq.Editor.upsertBlockProperty(
block.uuid,
'authors',
['Ada Lovelace', 'Alan Turing'],
{ reset: true }
)
await logseq.Editor.removeBlockProperty(block.uuid, 'zotero_key')
const props = await logseq.Editor.getBlockProperties(block.uuid)
// -> Record<string, any> | null
const pageProps = await logseq.Editor.getPageProperties('My Page')
BlockEntity | null)getBlockProperty is useful when you want the DB entity wrapper for a key.
const v = await logseq.Editor.getBlockProperty(block.uuid, 'zotero_key')
In DB graphs, tags can behave like classes.
Relevant APIs:
Editor.createTag(tagName, opts)Editor.addTagProperty(tagId, propertyIdOrName) / removeTagPropertyEditor.addTagExtends(tagId, parentTagIdOrName) / removeTagExtendsEditor.addBlockTag(blockId, tagId) / removeBlockTagThis is the most developer-friendly way to ship a “schema bundle”:
const tag = await logseq.Editor.createTag('ZoteroItem', {
tagProperties: [
{
name: 'zotero_key',
schema: { type: 'default', cardinality: 'one', public: true, hide: false },
},
{
name: 'authors',
schema: { type: 'node', cardinality: 'many', public: true, hide: false },
},
{
name: 'published_at',
schema: { type: 'date', cardinality: 'one', public: true, hide: false },
},
],
})
if (tag) {
const block = await logseq.Editor.getCurrentBlock()
if (block) await logseq.Editor.addBlockTag(block.uuid, tag.uuid)
}
Why this pattern is popular:
ZoteroItem) with fields.const tag = await logseq.Editor.getTag('ZoteroItem')
if (tag) {
await logseq.Editor.addTagProperty(tag.uuid, 'zotero_key')
await logseq.Editor.addTagProperty(tag.uuid, 'authors')
}
await logseq.Editor.addTagExtends('ZoteroItem', 'Reference')
key:: value strings as your “source of truth” in DB mode.upsertProperty + upsertBlockProperty.snake_case, ASCII) for key.upsertProperty(key, schema, { name }) to show a nice label.cardinality: 'many' and always write arrays.{ reset: true } when you want to overwrite.App.checkCurrentIsDbGraph().If you’re building a small internal “DB properties SDK” for your plugin, a minimal shape looks like:
export async function ensureDbGraph() {
if (!(await logseq.App.checkCurrentIsDbGraph())) {
throw new Error('DB graph required')
}
}
export async function ensureProperty(
key: string,
schema: Partial<import('../src/LSPlugin').PropertySchema>,
name?: string
) {
return logseq.Editor.upsertProperty(key, schema, name ? { name } : undefined)
}
export async function setProp(
block: string,
key: string,
value: any,
reset = false
) {
return logseq.Editor.upsertBlockProperty(block, key, value, reset ? { reset: true } : undefined)
}
LSPlugin.ts)Property schema (DB only)
Editor.getProperty(key)Editor.upsertProperty(key, schema?, opts?)Editor.removeProperty(key)Block/page values
Editor.upsertBlockProperty(block, key, value, { reset? })Editor.removeBlockProperty(block, key)Editor.getBlockProperty(block, key)Editor.getBlockProperties(block)Editor.getPageProperties(page)Tags / Classes
Editor.createTag(tagName, { tagProperties? })Editor.getTag(nameOrIdent) / Editor.getAllTags()Editor.addTagProperty(tagId, propertyIdOrName) / removeTagPropertyEditor.addTagExtends(tagId, parentTagIdOrName) / removeTagExtendsEditor.addBlockTag(blockId, tagId) / removeBlockTag