# Accessing the local database

Source: https://developers.inkdrop.app/guides/access-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](https://pouchdb.com/) 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](https://developers.inkdrop.app/guides/flux-architecture) and components to refresh their contents. The illustration below shows this flow of data:

![Data flow](https://developers.inkdrop.app/images/accessing-the-local-database_data-flow.png)

## Accessing the data from plugins

`env.localDB` — available on the [Environment](https://developers.inkdrop.app/modules/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](https://developers.inkdrop.app/data-access/notes), [notebooks](https://developers.inkdrop.app/data-access/books), [tags](https://developers.inkdrop.app/data-access/tags) and [files](https://developers.inkdrop.app/data-access/files), plus [utilities](https://developers.inkdrop.app/data-access/utils) and [change events](https://developers.inkdrop.app/data-access/events).

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

```js
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](https://developers.inkdrop.app/data-access/notes): Learn about the note model and how to create, retrieve, update, delete, and list notes.
- [Notebooks](https://developers.inkdrop.app/data-access/books): Learn about the notebook model and how to organize your notes with notebooks.
- [Tags](https://developers.inkdrop.app/data-access/tags): Learn about the tag model and how to categorize your notes with tags.
- [Files](https://developers.inkdrop.app/data-access/files): Files in Inkdrop are primarily used as image attachments that can be inserted into notes.
- [Utilities](https://developers.inkdrop.app/data-access/utils): Provides convenient methods for managing documents in the local database.
- [Local HTTP server](https://developers.inkdrop.app/data-access/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

> **Note:**
>
> Moved to the [Integrate with External Programs](https://developers.inkdrop.app/guides/integrate-with-external-programs) guide.
