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

There is a class called InkdropDatabase which wraps PouchDB and provides a bunch of useful methods that help you access the local database for managing notes, notebooks, tags and images.

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

const db = inkdrop.main.dataStore.getLocalDB()

// 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)

Data Access

Notes

Learn about the note model and the note class, which provide the core functionality for handling notes.

Notebooks

Notebooks are how notes are organized in Inkdrop and are commonly used to separate notes by category, project, or purpose.

Tags

Tags let you add keywords to notes, making them easier to find and browse when you've got a lot of them.

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 (Advanced)

Local REST API endpoint

The Inkdrop client app can open a simple HTTP server so that you can access the data from an external program easily, which gives you a flexible ability to import/export your notes.

You can configure the HTTP server settings by editing config.json in the user data directory.

Quit Inkdrop, then edit it like so:

{
  "*": {
    "core": {
      "server": {
        "enabled": true,
        "port": 19840,
        "bindAddress": "127.0.0.1",
        "auth": { "username": "foo", "password": "bar" }
      }
    }
  }
}

Now, launch the app.

Configurations

  • core.server.enabled - Specify true to enable the HTTP server. Default is false.
  • core.server.port - Defines the port number to listen. Default is 19840.
  • core.server.bindAddress - Defines the IP address to listen. Default is 127.0.0.1.
  • core.server.auth.{username,password} - Defines Basic auth credentials.

API reference

See the local HTTP server reference for more details.

There is a global variables named inkdrop which allows you to access the internal objects of Inkdrop. It has main property, which is a reference to the inkdrop instance in the main process. To access the local PouchDB instance in the main process:

async function getDatabaseInfo() {
  const db = inkdrop.main.dataStore.localPouch
  const info = await db.info()
  console.log(info.db_name)
}

In this code, localPouch is the instance of PouchDB. Be careful, you could break your database by accessing it with PouchDB since its API does not protect you from breaking it. Use it only if the data access API does not provide what you would do.

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!