Accessing the local database

There are two databases in local and on remote and they sync via HTTP(S). The Inkdrop client app is built on top of a PouchDB for storing data in local and syncing with the remote database. For many parts of the application, the database is the source of truth.

Data is written to the local database first, then synced with the remote database, and changes to the database trigger Actions, Stores and components to refresh their contents. The illustration below shows this flow of data:

Data flow

Accessing the data from plugins

env.localDB — available on the Environment passed to activate(env) — is a proxy to the local database, which lives in the main process. It provides a bunch of useful methods that help you manage notes, notebooks, tags and files, plus utilities and change events.

For example, below code gets data directly from the local database:

const db = env.localDB

// Get a note data by note ID
const note = await db.notes.get('note:F8xUp-23G')

// Get all notebooks
const books = await db.books.all()

// Get notes in a notebook
const notesInBook = await db.notes.findInBook(books[0]._id)

// Search notes with keywords
const result = await db.utils.search('Foobar')
const { docs } = result
console.log('Search result:', docs)

Resources

Notes

Learn about the note model and how to create, retrieve, update, delete, and list notes.

Notebooks

Learn about the notebook model and how to organize your notes with notebooks.

Tags

Learn about the tag model and how to categorize your notes with tags.

Files

Files in Inkdrop are primarily used as image attachments that can be inserted into notes.

Utilities

Provides convenient methods for managing documents in the local database.

Local HTTP server

The Inkdrop client app can open a simple HTTP server so that you can access the data from an external program easily.

Accessing via HTTP

Can you help us improve the docs? 🙏

The source of these docs is here on GitHub. If you see a way these docs can be improved, please fork us!