# @hocuspocus/extension-sqlite [![Version](https://img.shields.io/npm/v/@hocuspocus/extension-sqlite.svg?label=version)](https://www.npmjs.com/package/@hocuspocus/extension-sqlite) [![Downloads](https://img.shields.io/npm/dm/@hocuspocus/extension-sqlite.svg)](https://npmcharts.com/compare/tiptap?minimal=true) [![License](https://img.shields.io/npm/l/@hocuspocus/extension-sqlite.svg)](https://www.npmjs.com/package/@hocuspocus/extension-sqlite) [![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub)](https://github.com/sponsors/ueberdosis) Persist [Hocuspocus](https://github.com/ueberdosis/hocuspocus) documents to a local SQLite database. Zero-config storage for development, self-hosted single-instance deployments, and small production setups. Uses [`better-sqlite3`](https://github.com/WiseLibs/better-sqlite3). ## Installation ```bash npm install @hocuspocus/extension-sqlite ``` ## Usage ```js import { Server } from "@hocuspocus/server" import { SQLite } from "@hocuspocus/extension-sqlite" const server = new Server({ extensions: [ new SQLite({ database: "db.sqlite" }), ], }) server.listen() ``` `database` accepts: - a filename (persisted to disk, e.g. `"db.sqlite"`) - `":memory:"` for an in-memory database - `""` for an anonymous on-disk database Omit the option entirely to default to `":memory:"`. ## Requirements `better-sqlite3` ships prebuilt binaries for Linux (glibc and musl), macOS and Windows on x64 and arm64. They need: - **Node.js 22.14.0 through 22.x, or 23.6.0 or later.** Older releases lack Node-API 10 and crash when the database is opened. - **glibc 2.34 or later** on glibc-based Linux. This rules out Debian 11, Ubuntu 20.04, RHEL 8 and Amazon Linux 2, for example. On other systems you have to build `better-sqlite3` from source. Since v13 it no longer does that automatically during `npm install`. ## Troubleshooting ### Building `better-sqlite3` from source If loading the native addon fails (for example ``version `GLIBC_2.34' not found`` or `Cannot find module '.../better_sqlite3.node'`), compile it from your server project's root. The first line finds the copy of `better-sqlite3` that the extension loads, which isn't always `node_modules/better-sqlite3` (pnpm, or another version of `better-sqlite3` in your project): ```bash cd "$(node -p "path.dirname(require.resolve('better-sqlite3/package.json', { paths: [path.dirname(require.resolve('@hocuspocus/extension-sqlite'))] }))")" npx --yes node-gyp@12 rebuild --release --force_build=1 ``` `node-gyp@12` is pinned because the latest node-gyp no longer supports Node 22.14. The compiled addon in `build/Release` takes precedence over the prebuilt binaries. It needs Python 3 and a C++20 toolchain (Xcode Command Line Tools on macOS, `build-essential` on Debian/Ubuntu, Visual Studio Build Tools on Windows). Run it again after every reinstall of `better-sqlite3`. ## Documentation Schema, custom `fetch`/`store`, and migration guides: [tiptap.dev/docs/hocuspocus/server/extensions/sqlite](https://tiptap.dev/docs/hocuspocus/server/extensions/sqlite). ## License MIT — see [LICENSE.md](https://github.com/ueberdosis/hocuspocus/blob/main/LICENSE.md).