Utils
Provides convenient methods for managing documents in the local database.
Search for notes
Retrieves notes which match given keyword.
Parameters
- Name
keyword
- Type
- string
- Required
- Description
The search keyword. The syntax is described here.
- Name
options
- Type
- object
- Description
Options include sorting, limiting, and skipping notes.
- Name
sort
- Type
- object
- Description
An array indicating the field and order. Example:
[ { updatedAt: 'asc' } ]
,[ { title: 'desc' } ]
. Only one field supported.
- Name
limit
- Type
- number
- Description
Number of notes to fetch. Default is
20
.
- Name
skip
- Type
- number
- Description
Number of notes to skip. Default is
0
.
Returns
Returns a query result with matching notes.
Request
const db = inkdrop.main.dataStore.getLocalDB()
const results = await db.utils.search('foobar', { sort: [ { updatedAt: 'asc' } ], limit: 20 })
Response
{
"query": {
"index": "fts",
"conditions": [
{
"type": "keyword",
"term": "foobar",
"phrase": false,
"exclude": false
}
]
},
"cursor": {
"index": "fts",
"conditions": [
{
"type": "keyword",
"term": "hoge",
"phrase": false,
"exclude": false
}
],
"limit": 20,
"skip": 20
},
"includeDocs": true,
"docs": [
{
"doctype": "markdown",
"updatedAt": 1461564004766,
"createdAt": 1461563995746,
"bookId": "book:32b385767dc2",
"status": "none",
"numOfTasks": 0,
"numOfCheckedTasks": 0,
"title": "title...",
"body": "body...",
"_id": "note:4eeb997c",
"_rev": "8-d18201be3336c70979c6a375b497b3a7"
},
...
]
}
Count notes with a tag
Counts number of notes which are associated with specified tag ID.
Parameters
- Name
tagId
- Type
- string
- Required
- Description
The tag ID.
Returns
Returns the number of notes associated with the specified tag ID.
Request
const db = inkdrop.main.dataStore.getLocalDB()
const count = await db.utils.countNotesWithTag('tag:exampleTagId')
Response
45
Delete a tag
Delete a tag with the specified ID and remove it from associated notes.
Parameters
- Name
tagId
- Type
- string
- Required
- Description
The tag ID to delete.
Returns
A Promise that will reject if the tag cannot be deleted.
Request
const db = inkdrop.main.dataStore.getLocalDB()
await db.utils.deleteTag('tag:tBELDUITs')
Move a note to a notebook
Move a note to a designated notebook.
Parameters
- Name
noteId
- Type
- string
- Required
- Description
The note ID you wish to move.
- Name
moveToBookId
- Type
- string
- Required
- Description
The destination notebook ID where the note will be moved to.
Returns
Returns a Promise. Rejects if there's a failure in moving the note.
Request
const db = inkdrop.main.dataStore.getLocalDB()
await db.utils.moveNoteToBook('note:BKzzd8iGK', 'book:4eeb997c')
Move multiple notes to a notebook
Move a batch of notes to a designated notebook.
Parameters
- Name
noteIds
- Type
- array
- Required
- Description
An array of note IDs you wish to move.
- Name
moveToBookId
- Type
- string
- Required
- Description
The destination notebook ID where the notes will be moved to.
Returns
Returns a Promise. Rejects if there's a failure in moving the notes.
Request
const db = inkdrop.main.dataStore.getLocalDB()
await db.utils.moveNoteToBookBatch(["note:BKzzd8iGK", "note:8eea9f7c"], 'book:4eeb997c')
Duplicate a note
Duplicate a note with the provided note ID. The duplicated note will have newly assigned values for _id
, createdAt
, updatedAt
, and _rev
.
Parameters
- Name
noteId
- Type
- string
- Required
- Description
The ID of the note you wish to duplicate.
Returns
Returns a Promise which will resolve with the duplicated note details.
Request
const db = inkdrop.main.dataStore.getLocalDB()
await db.utils.duplicateNote("note:BKzzd8iGK")
Duplicate multiple notes
Duplicate a batch of notes. Each duplicated note will have newly assigned values for _id
, createdAt
, updatedAt
, and _rev
.
Parameters
- Name
noteIds
- Type
- array
- Required
- Description
An array of note IDs you wish to duplicate.
Returns
Returns a Promise which will resolve with the details of the duplicated notes.
Request
const db = inkdrop.main.dataStore.getLocalDB()
await db.utils.duplicateNoteBatch(["note:BKzzd8iGK", "note:8eea9f7c"])
Trash or delete multiple notes
Move the given notes to trash or if they are already in the trash, delete them permanently.
Parameters
- Name
noteIds
- Type
- array
- Required
- Description
An array of note IDs to either move to trash or delete permanently.
Returns
Returns a Promise. Rejects if it fails to perform any of the operations.
Request
const db = inkdrop.main.dataStore.getLocalDB()
await db.utils.moveNotesToTrashOrDelete(["note:BKzzd8iGK", "note:8eea9f7c"])
Empty Trash
Request
const db = inkdrop.main.dataStore.getLocalDB()
await db.utils.emptyTrash()
Set Tags Batch
Sets given tags to notes with specified IDs.
Parameters
- Name
noteIds
- Type
- array
- Required
- Description
A list of IDs of notes to be set.
- Name
tags
- Type
- array of string
- Required
- Description
A list of tag IDs to set.
Returns
Returns an Array of updated Notes.
Request
const db = inkdrop.main.dataStore.getLocalDB()
await db.utils.setTagsBatch(["note:BKzzd8iGK", "note:8eea9f7c"], ["tag:tBELDUITs"])
Set Status Batch
Sets specified note status to notes with given IDs.
Parameters
- Name
noteIds
- Type
- array
- Required
- Description
A list of IDs of notes to be set.
- Name
status
- Type
- string
- Required
- Description
A note status which can be
'none'
,'active'
,'onHold'
,'completed'
or'dropped'
.
Request
const db = inkdrop.main.dataStore.getLocalDB()
await db.utils.setStatusBatch(["note:BKzzd8iGK", "note:8eea9f7c"], "completed")
Move a notebook
Sets a notebook with specified ID as a child of a notebook.
Parameters
- Name
bookId
- Type
- string
- Required
- Description
A notebook ID to move.
- Name
newParentBookId
- Type
- string or null
- Description
A notebook ID of new parent notebook. Specifying
null
moves the notebook to the root.
Returns
Returns the updated Book.
Request
const db = inkdrop.main.dataStore.getLocalDB()
await db.utils.moveBook("book:tjnPbJakw", "book:Bk5Ivk0T")
Delete a notebook
Deletes a notebook with given ID and moves notes associated with it into trash.
Parameters
- Name
bookId
- Type
- string
- Required
- Description
A notebook ID to delete.
Returns
Returns a Promise.
Request
const db = inkdrop.main.dataStore.getLocalDB()
await db.utils.deleteBook("book:tjnPbJakw")
Get Buffer From File
Loads an image file as Buffer.
Parameters
- Name
fileId
- Type
- string
- Required
- Description
A file ID to load.
Returns
Returns a content of the image file.
Request
const db = inkdrop.main.dataStore.getLocalDB()
await db.utils.getBufferFromFile("file:5c2c2b2c")