Database
Database 即底层类型 MbModelTool 的单例,用于访问 MarginNote 的笔记与文档数据。通过 Database.sharedInstance() 获取。修改数据后建议使用 UndoManager 的 undoGrouping(title, topicid, fn) 包裹,并调用 Application.sharedInstance().refreshAfterDBChanged(topicid) 刷新界面。
类成员 (Class members)
Section titled “类成员 (Class members)”sharedInstance
Section titled “sharedInstance”获取全局唯一的数据库工具实例。
static sharedInstance(): MbModelToolReturn Value:
MbModelTool: 数据库工具单例。
实例成员 (Instance members)
Section titled “实例成员 (Instance members)”getNoteById
Section titled “getNoteById”根据笔记 ID 获取笔记。
getNoteById(noteId: string): MbBookNote | undefinedParameters:
| Name | Type | Description |
|---|---|---|
noteId | string | 笔记唯一 ID。 |
Return Value:
MbBookNote | undefined: 对应的笔记对象,若不存在则返回 undefined。
getNotebookById
Section titled “getNotebookById”根据笔记本 ID 获取笔记本。
getNotebookById(topicId: string): MbTopic | undefinedParameters:
| Name | Type | Description |
|---|---|---|
topicId | string | 笔记本 ID。 |
Return Value:
MbTopic | undefined: 对应的笔记本对象。
getDocumentById
Section titled “getDocumentById”根据文档 MD5 获取文档。
getDocumentById(docMd5: string): MbBook | undefinedParameters:
| Name | Type | Description |
|---|---|---|
docMd5 | string | 文档 MD5。 |
Return Value:
MbBook | undefined: 对应的文档对象。
getMediaByHash
Section titled “getMediaByHash”根据媒体哈希获取二进制数据。
getMediaByHash(hash: string): NSData | undefinedParameters:
| Name | Type | Description |
|---|---|---|
hash | string | 媒体哈希字符串。 |
Return Value:
NSData | undefined: 媒体数据。
getFlashcardByNoteId
Section titled “getFlashcardByNoteId”按 Evernote 笔记 ID 与笔记本获取闪卡(笔记)。
getFlashcardByNoteId(noteId: string, topicId: string): MbBookNote | undefinedParameters:
| Name | Type | Description |
|---|---|---|
noteId | string | 原始笔记 ID (Evernote ID)。 |
topicId | string | 笔记本 ID。 |
Return Value:
MbBookNote | undefined: 对应的闪卡笔记。
getFlashcardsByNoteId
Section titled “getFlashcardsByNoteId”按 Evernote 笔记 ID 获取所有关联闪卡。
getFlashcardsByNoteId(noteId: string): NSArrayParameters:
| Name | Type | Description |
|---|---|---|
noteId | string | 原始笔记 ID。 |
Return Value:
NSArray: 包含MbBookNote的数组。
hasFlashcardByNoteId
Section titled “hasFlashcardByNoteId”是否存在该 Evernote 笔记的闪卡。
hasFlashcardByNoteId(noteId: string): booleanParameters:
| Name | Type | Description |
|---|---|---|
noteId | string | 原始笔记 ID。 |
Return Value:
boolean: 是否存在。
allNotebooks
Section titled “allNotebooks”获取所有笔记本。
allNotebooks(): NSArrayReturn Value:
NSArray: 包含所有MbTopic的数组。
allDocuments
Section titled “allDocuments”获取所有文档。
allDocuments(): NSArrayReturn Value:
NSArray: 包含所有MbBook的数组。
savedb
Section titled “savedb”手动保存数据库到磁盘。慎用,通常由系统自动管理。
savedb(): voidsetNotebookSyncDirty
Section titled “setNotebookSyncDirty”将笔记本标记为同步脏(需要同步)。
setNotebookSyncDirty(topicid: string): voidParameters:
| Name | Type | Description |
|---|---|---|
topicid | string | 笔记本 ID。 |
saveHistoryArchiveKey
Section titled “saveHistoryArchiveKey”保存历史归档。
saveHistoryArchiveKey(topicid: string, key: string): NSArrayParameters:
| Name | Type | Description |
|---|---|---|
topicid | string | 笔记本 ID。 |
key | string | 归档键名。 |
Return Value:
NSArray: 归档数据。
loadHistoryArchiveKey
Section titled “loadHistoryArchiveKey”加载历史归档。
loadHistoryArchiveKey(topicid: string, key: string): NSArrayParameters:
| Name | Type | Description |
|---|---|---|
topicid | string | 笔记本 ID。 |
key | string | 归档键名。 |
Return Value:
NSArray: 归档数据。
deleteBookNote
Section titled “deleteBookNote”删除单条笔记(不删子节点)。
deleteBookNote(noteId: string): voidParameters:
| Name | Type | Description |
|---|---|---|
noteId | string | 笔记 ID。 |
deleteBookNoteTree
Section titled “deleteBookNoteTree”删除笔记及其所有后代。
deleteBookNoteTree(noteId: string): voidParameters:
| Name | Type | Description |
|---|---|---|
noteId | string | 笔记 ID。 |
cloneNotesToTopic
Section titled “cloneNotesToTopic”将笔记克隆到指定笔记本。
cloneNotesToTopic(notes: NSArray, topicid: string): NSArrayParameters:
| Name | Type | Description |
|---|---|---|
notes | NSArray | MbBookNote 数组。 |
topicid | string | 目标笔记本 ID。 |
Return Value:
NSArray: 克隆后的新笔记数组。
cloneNotesToFlashcardsToTopic
Section titled “cloneNotesToFlashcardsToTopic”将笔记克隆为闪卡到指定笔记本。
cloneNotesToFlashcardsToTopic(notes: NSArray, topicid: string): NSArrayParameters:
| Name | Type | Description |
|---|---|---|
notes | NSArray | MbBookNote 数组。 |
topicid | string | 目标笔记本 ID。 |
Return Value:
NSArray: 克隆后的新笔记数组。
exportNotebookStorePath
Section titled “exportNotebookStorePath”导出笔记本。
exportNotebookStorePath(topicid: string, storePath: string): booleanParameters:
| Name | Type | Description |
|---|---|---|
topicid | string | 笔记本 ID。 |
storePath | string | 导出路径。 |
Return Value:
boolean: 是否成功。
importNotebookFromStorePathMerge
Section titled “importNotebookFromStorePathMerge”从路径导入笔记本。
importNotebookFromStorePathMerge(storePath: string, merge: boolean): anycreateNoteWithTitleTopicid
Section titled “createNoteWithTitleTopicid”在指定笔记本创建新笔记。
createNoteWithTitleTopicid(title: string, topicid: string): MbBookNotegetSketchNoteForMindMapFocusNoteId
Section titled “getSketchNoteForMindMapFocusNoteId”获取脑图草稿笔记(Sketch)。
getSketchNoteForMindMapFocusNoteId(topicid: string, focusNoteId: string): MbBookNotegetSketchNoteForDocumentMd5Page
Section titled “getSketchNoteForDocumentMd5Page”获取指定文档页的草稿笔记(Sketch)。
getSketchNoteForDocumentMd5Page(topicid: string, md5: string, page: number): MbBookNotegetSketchNotesForDocumentMd5Page
Section titled “getSketchNotesForDocumentMd5Page”获取指定文档页的草稿笔记列表(Sketch)。
getSketchNotesForDocumentMd5Page(topicid: string, md5: string, page: number): NSArraygetSketchNotesForMindMap
Section titled “getSketchNotesForMindMap”获取脑图草稿笔记列表(Sketch)。
getSketchNotesForMindMap(topicid: string): NSArray兼容性工具(类方法)
Section titled “兼容性工具(类方法)”transDictionaryToJSCompatible / transArrayToJSCompatible
Section titled “transDictionaryToJSCompatible / transArrayToJSCompatible”将原生容器转换为更易于 JS 使用的结构(行为以运行时实现为准)。
static transDictionaryToJSCompatible(dic: NSDictionary): NSDictionarystatic transArrayToJSCompatible(arr: NSArray): NSArrayParameters:
| Name | Type | Description |
|---|---|---|
storePath | string | 导入文件路径。 |
merge | boolean | 是否合并。 |
Return Value:
any: 导入结果(通常为导入的笔记本对象或状态)。