Skip to content

Database

Database 即底层类型 MbModelTool 的单例,用于访问 MarginNote 的笔记与文档数据。通过 Database.sharedInstance() 获取。修改数据后建议使用 UndoManagerundoGrouping(title, topicid, fn) 包裹,并调用 Application.sharedInstance().refreshAfterDBChanged(topicid) 刷新界面。

获取全局唯一的数据库工具实例。

static sharedInstance(): MbModelTool

Return Value:

  • MbModelTool: 数据库工具单例。

根据笔记 ID 获取笔记。

getNoteById(noteId: string): MbBookNote | undefined

Parameters:

NameTypeDescription
noteIdstring笔记唯一 ID。

Return Value:

  • MbBookNote | undefined: 对应的笔记对象,若不存在则返回 undefined。

根据笔记本 ID 获取笔记本。

getNotebookById(topicId: string): MbTopic | undefined

Parameters:

NameTypeDescription
topicIdstring笔记本 ID。

Return Value:

  • MbTopic | undefined: 对应的笔记本对象。

根据文档 MD5 获取文档。

getDocumentById(docMd5: string): MbBook | undefined

Parameters:

NameTypeDescription
docMd5string文档 MD5。

Return Value:

  • MbBook | undefined: 对应的文档对象。

根据媒体哈希获取二进制数据。

getMediaByHash(hash: string): NSData | undefined

Parameters:

NameTypeDescription
hashstring媒体哈希字符串。

Return Value:

  • NSData | undefined: 媒体数据。

按 Evernote 笔记 ID 与笔记本获取闪卡(笔记)。

getFlashcardByNoteId(noteId: string, topicId: string): MbBookNote | undefined

Parameters:

NameTypeDescription
noteIdstring原始笔记 ID (Evernote ID)。
topicIdstring笔记本 ID。

Return Value:

  • MbBookNote | undefined: 对应的闪卡笔记。

按 Evernote 笔记 ID 获取所有关联闪卡。

getFlashcardsByNoteId(noteId: string): NSArray

Parameters:

NameTypeDescription
noteIdstring原始笔记 ID。

Return Value:

  • NSArray: 包含 MbBookNote 的数组。

是否存在该 Evernote 笔记的闪卡。

hasFlashcardByNoteId(noteId: string): boolean

Parameters:

NameTypeDescription
noteIdstring原始笔记 ID。

Return Value:

  • boolean: 是否存在。

获取所有笔记本。

allNotebooks(): NSArray

Return Value:

  • NSArray: 包含所有 MbTopic 的数组。

获取所有文档。

allDocuments(): NSArray

Return Value:

  • NSArray: 包含所有 MbBook 的数组。

手动保存数据库到磁盘。慎用,通常由系统自动管理。

savedb(): void

将笔记本标记为同步脏(需要同步)。

setNotebookSyncDirty(topicid: string): void

Parameters:

NameTypeDescription
topicidstring笔记本 ID。

保存历史归档。

saveHistoryArchiveKey(topicid: string, key: string): NSArray

Parameters:

NameTypeDescription
topicidstring笔记本 ID。
keystring归档键名。

Return Value:

  • NSArray: 归档数据。

加载历史归档。

loadHistoryArchiveKey(topicid: string, key: string): NSArray

Parameters:

NameTypeDescription
topicidstring笔记本 ID。
keystring归档键名。

Return Value:

  • NSArray: 归档数据。

删除单条笔记(不删子节点)。

deleteBookNote(noteId: string): void

Parameters:

NameTypeDescription
noteIdstring笔记 ID。

删除笔记及其所有后代。

deleteBookNoteTree(noteId: string): void

Parameters:

NameTypeDescription
noteIdstring笔记 ID。

将笔记克隆到指定笔记本。

cloneNotesToTopic(notes: NSArray, topicid: string): NSArray

Parameters:

NameTypeDescription
notesNSArrayMbBookNote 数组。
topicidstring目标笔记本 ID。

Return Value:

  • NSArray: 克隆后的新笔记数组。

将笔记克隆为闪卡到指定笔记本。

cloneNotesToFlashcardsToTopic(notes: NSArray, topicid: string): NSArray

Parameters:

NameTypeDescription
notesNSArrayMbBookNote 数组。
topicidstring目标笔记本 ID。

Return Value:

  • NSArray: 克隆后的新笔记数组。

导出笔记本。

exportNotebookStorePath(topicid: string, storePath: string): boolean

Parameters:

NameTypeDescription
topicidstring笔记本 ID。
storePathstring导出路径。

Return Value:

  • boolean: 是否成功。

从路径导入笔记本。

importNotebookFromStorePathMerge(storePath: string, merge: boolean): any

在指定笔记本创建新笔记。

createNoteWithTitleTopicid(title: string, topicid: string): MbBookNote

获取脑图草稿笔记(Sketch)。

getSketchNoteForMindMapFocusNoteId(topicid: string, focusNoteId: string): MbBookNote

获取指定文档页的草稿笔记(Sketch)。

getSketchNoteForDocumentMd5Page(topicid: string, md5: string, page: number): MbBookNote

获取指定文档页的草稿笔记列表(Sketch)。

getSketchNotesForDocumentMd5Page(topicid: string, md5: string, page: number): NSArray

获取脑图草稿笔记列表(Sketch)。

getSketchNotesForMindMap(topicid: string): NSArray

transDictionaryToJSCompatible / transArrayToJSCompatible

Section titled “transDictionaryToJSCompatible / transArrayToJSCompatible”

将原生容器转换为更易于 JS 使用的结构(行为以运行时实现为准)。

static transDictionaryToJSCompatible(dic: NSDictionary): NSDictionary
static transArrayToJSCompatible(arr: NSArray): NSArray

Parameters:

NameTypeDescription
storePathstring导入文件路径。
mergeboolean是否合并。

Return Value:

  • any: 导入结果(通常为导入的笔记本对象或状态)。
头文件 API 清单

正在加载…

协议:,来源: