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