Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/issue.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Write the description of the issue here
### Info
- Environment: (Node.js/browser/hybrid app/etc.)
- Platform: (Chrome/FF/Safari/Edge/iOS/Android/etc.)
- Adapter: (idb/indexeddb/memory/leveldb/etc.)
- Adapter: (idb/indexeddb/memory/leveldb/nodesqlite/etc.)
- Server: (CouchDB/Cloudant/PouchDB Server/etc.)

### Reproduce
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,54 @@ jobs:
- name: Second retry
if: steps.retry.outcome == 'failure'
run: git reset --hard && ${{ matrix.cmd }}

nodejs-sqlite-adapter:
needs: lint
strategy:
fail-fast: false
matrix:
node: [22]
adapter: ['nodesqlite']
cmd:
- npm test
- TYPE=find PLUGINS=pouchdb-find npm test
- TYPE=mapreduce npm test
runs-on: ubuntu-latest
services:
couchdb:
image: couchdb:3.1
ports:
- 5984:5984
env:
COUCHDB_USER: admin
COUCHDB_PASSWORD: password
env:
CLIENT: node
SERVER: couchdb-master
COUCH_HOST: http://admin:password@127.0.0.1:5984
SKIP_MIGRATION: 1
ADAPTERS: ${{ matrix.adapter }}
VIEW_ADAPTERS: nodesqlite
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
- name: Wait for CouchDB
run: ./bin/wait-for-couch.sh 20
- name: Setup CouchDB CORS
run: curl 'http://admin:password@127.0.0.1:5984/_node/_local/_config/cors/origins' -X PUT -d '"http://127.0.0.1:8000"'
- uses: ./.github/actions/install-node-package
with:
node-version: ${{ matrix.node }}
- uses: ./.github/actions/build-pouchdb
- id: test
run: ${{ matrix.cmd }}
continue-on-error: true
- name: First retry
id: retry
if: steps.test.outcome == 'failure'
run: ${{ matrix.cmd }}
continue-on-error: true
- name: Second retry
if: steps.retry.outcome == 'failure'
run: ${{ matrix.cmd }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ yarn.lock
release-todo.txt
/perf-test-results/
/dist-bundles/
*.sqlite
6 changes: 3 additions & 3 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ The main test suite can be run using the following command:

PouchDB runs in the browser and on Node.js, and has multiple different storage
backends known as _adapters_. In the browser these are `idb`, `indexeddb` and
`memory` and on Node.js they're `leveldb` and `memory`.
`memory` and on Node.js they're `nodesqlite`, `leveldb` and `memory`.

It also includes an adapter named `http`, which works by delegating operations
to CouchDB (or anything that's API-compatible with it) over the network. Since
Expand All @@ -92,7 +92,7 @@ databases. These are selected automatically based on the execution environment,
but this variable overrides the default choice and causes additional adapters to
be loaded if they're not part of the default distribution.

On Node.js the available local adapters are `leveldb` and `memory`. In the
On Node.js the available local adapters are `nodesqlite`, `leveldb` and `memory`. In the
browser they're `idb`, `indexeddb` and `memory`.

You can also set `ADAPTERS=http` to force all PouchDB databases to be created on
Expand Down Expand Up @@ -187,7 +187,7 @@ Comma-separated list of preferred view adapter backends that PouchDB will use.
This variable overrides the default choice and causes additional adapters to
be loaded if they're not part of the default distribution.

On Node.js the available adapters are `leveldb` and `memory`. In the
On Node.js the available adapters are `nodesqlite`, `leveldb` and `memory`. In the
browser they're `idb`, `indexeddb` and `memory`.


Expand Down
2 changes: 1 addition & 1 deletion docs/_includes/api/create_database.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
**Options for local databases:**

* `auto_compaction`: This turns on auto compaction, which means `compact()` is called after every change to the database. Defaults to `false`.
* `adapter`: One of `'indexeddb'`, `'idb'`, `'leveldb'`, or `'http'`.
* `adapter`: One of `'indexeddb'`, `'idb'`, `'leveldb'`, `'nodesqlite'`, or `'http'`.
* `revs_limit`: Specify how many old revisions we keep track (not a copy) of. Specifying a low value means Pouch may not be able to figure out whether a new revision received via replication is related to any it currently has which could result in a conflict. Defaults to `1000`.
* `deterministic_revs`: Use a md5 hash to create a deterministic revision number for documents. Setting it to false will mean that the revision number will be a random UUID. Defaults to true.
* `view_update_changes_batch_size`: Specify how many change records will be consumed at a time when rebuilding view indexes when the `query()` method is used. Defaults to 50.
Expand Down
24 changes: 15 additions & 9 deletions docs/adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ The LocalStorage plugin should be considered highly experimental, and the underl

#### In-memory

{% include alert/start.html variant="warning"%}
{% markdown %}
**Warning: deprecation notice.** The `memory` adapter will be deprecated in PouchDB version 10.0.0 and removed in version 11.0.0. You can read [the migration guide here](https://pouchdb.com/2026/04/10/migration-to-nodesqlite.html) and more about the topic in [this link](https://github.com/apache/pouchdb/issues/9163).
{% endmarkdown %}
{% include alert/end.html%}

Just as in the browser, you can also create a pure in-memory PouchDB:

```
Expand All @@ -139,23 +145,23 @@ This implementation is based on [MemDOWN](https://github.com/level/memdown), and

#### Node SQLite adapter

You can also use PouchDB over [SQLite3](https://github.com/mapbox/node-sqlite3) in Node, using the WebSQL adapter and
[node-websql](https://github.com/nolanlawson/node-websql):
You can also use PouchDB in Node.js' [native SQLite module](https://nodejs.org/api/sqlite.html), when using Node.js' `>22.5.0` version.

```js
const PouchDB = require('pouchdb');
PouchDB.plugin(require('pouchdb-adapter-node-websql'));
PouchDB.plugin(require('pouchdb-adapter-node-sqlite'));

const db = new PouchDB('mydatabase.db', {adapter: 'websql'});
const db = new PouchDB('mydatabase.db', {adapter: 'nodesqlite'});
```

In this case, PouchDB is directly using SQLite queries to build the database, exactly as the WebSQL adapter would.

See ["Prebuilt databases with PouchDB"]({{ site.baseurl }}/2016/04/28/prebuilt-databases-with-pouchdb.html)
for a guide to how you might use this adapter to create prebuilt SQLite database files for adapters such as Cordova or Electron.

#### Other LevelDOWN adapters

{% include alert/start.html variant="warning"%}
{% markdown %}
**Warning: deprecation notice.** The `leveldb` adapter will be deprecated in PouchDB version 10.0.0 and removed in version 11.0.0. You can read [the migration guide here](https://pouchdb.com/2026/04/10/migration-to-nodesqlite.html) and more about the topic in [this link](https://github.com/apache/pouchdb/issues/9163).
{% endmarkdown %}
{% include alert/end.html%}

Technically you are free to use
[any LevelDOWN-based implementation](https://github.com/rvagg/node-levelup/wiki/Modules#storage-back-ends) in either Node or the browser.
However this should be considered **extremely experimental** and not designed for production use.
Expand Down
12 changes: 12 additions & 0 deletions docs/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ console.log(db.adapter); // 'websql'

### [pouchdb-adapter-leveldb](https://npmjs.org/package/pouchdb-adapter-leveldb)

{% include alert/start.html variant="warning"%}
{% markdown %}
**Warning: deprecation notice.** The `leveldb` adapter will be deprecated in PouchDB version 10.0.0 and removed in version 11.0.0. You can read [the migration guide here](https://pouchdb.com/2026/04/10/migration-to-nodesqlite.html) and more about the topic in [this link](https://github.com/apache/pouchdb/issues/9163).
{% endmarkdown %}
{% include alert/end.html%}

The primary adapter used by PouchDB in Node.js, using LevelDB. The adapter name
is `'leveldb'`.

Expand Down Expand Up @@ -213,6 +219,12 @@ console.log(db.adapter); // 'http'

### [pouchdb-adapter-memory](https://npmjs.org/package/pouchdb-adapter-memory)

{% include alert/start.html variant="warning"%}
{% markdown %}
**Warning: deprecation notice.** The `memory` adapter will be deprecated in PouchDB version 10.0.0 and removed in version 11.0.0. You can read [the migration guide here](https://pouchdb.com/2026/04/10/migration-to-nodesqlite.html) and more about the topic in [this link](https://github.com/apache/pouchdb/issues/9163).
{% endmarkdown %}
{% include alert/end.html%}

An optional adapter that works in the browser and Node.js, fully in-memory. The adapter name
is `'memory'`.

Expand Down
57 changes: 57 additions & 0 deletions docs/posts/2026-04-10-migration-to-nodesqlite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
layout: post

title: PouchDB has a new adapter - nodesqlite
author: Alba Herrerías

---

Hello everyone! PouchDB has a new available adapter for you to use, `nodesqlite`, that internally uses Node.js's native SQLite module as its persistence layer. This will be, in PouchDB's release version 11.0.0, the default adapter for node environments, replacing the deprecated LevelDB ecosystem we currently depend on. You can read more about the details, discussion and timeline in this [issue](https://github.com/apache/pouchdb/issues/9163), and look at its implementation in this [pull request](https://github.com/apache/pouchdb/pull/9223).

## Migration guide

We suggest you to create a replication from your databases to new ones using the `nodesqlite` adapter. We have drafted a snippet you can copy and modify according to your needs.

```js
async function getDb (name) {
const oldDb = new PouchDB(name, { adapter: 'leveldb' })

// create a new database with new nodesqlite adapter
const newDb = new PouchDB(name, { adapter: 'nodesqlite' })

// set up promise wrapped around replication
return new Promise((resolve, reject) => {
console.log('Started migrating to nodesqlite...')

PouchDB.replicate(oldDb, newDb).on('complete', async () => {
// Do you want to remove the old database?
// If so, uncomment the following line:
// await oldDb.destroy()

console.log('All done!')
resolve(newDb)
}).on('change', (info) => {
console.log(`Docs written: ${info.docs_written}` )
}).on('denied', reject)
.on('error', reject)
})
}
```
Now, instead of getting your database like:
```js
const db = new PouchDB('my-db-name', { adapter: 'leveldb' })

// or like this, since `leveldb` is the default adapter in the Node.js environment
const db = new PouchDB('my-db-name')
```

Do it like this:
```js
const db = await getDb('my-db-name')
```

If you encounter a bug in this migration, please [file an issue](https://github.com/pouchdb/pouchdb/issues) and, ideally, modify this post for the benefit of others. Thanks!

## Get in touch

As always, we welcome feedback from the community. Please don't hesitate to [file issues](https://github.com/pouchdb/pouchdb/issues), [open discussions](https://github.com/pouchdb/pouchdb/discussions) or [get in touch](https://github.com/pouchdb/pouchdb/blob/master/CONTRIBUTING.md#get-in-touch). And of course, a big thanks to all of our [new and existing contributors](https://github.com/pouchdb/pouchdb/graphs/contributors)!
Binary file modified docs/static/img/pouchdb_adapters.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading