Registry / database / fastify-sqlite

fastify-sqlite

JSON →
library1.1.0jsnpmunverified

Fastify plugin that integrates SQLite3 databases via the sqlite3 package. Current version 1.1.0, compatible with Fastify v4. Supports both callback-based and promise-based APIs (via sqlite wrapper). Provides options for in-memory databases, file-based storage, verbose logging, and named decorators. A lightweight alternative to more feature-rich ORMs like TypeORM or Sequelize for SQLite.

npm install fastify-sqlite
INSTALL
IMPORT
SIG · FASTIFY-SQLITE
F
fastify-sqlite
databasejavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

fastifySqlite
import fastifySqlite from 'fastify-sqlite'
const fastifySqlite = require('fastify-sqlite')
ESM import; CJS require also works.
app.sqlite
app.sqlite.all('SELECT * FROM table', callback)
app.sqlite().all(...) / app.get('sqlite').all(...)
sqlite is a decorator on the Fastify instance, not a function.
app.sqlite.myDb
app.sqlite.myDb.all(...) // when registered with name option
app.sqlite.myDb() // not a function
Named databases are accessed as properties under app.sqlite.

Shows registering plugin with promise-based API and running a simple query.

import Fastify from 'fastify' import fastifySqlite from 'fastify-sqlite' const app = Fastify() await app.register(fastifySqlite, { dbFile: ':memory:', promiseApi: true }) await app.ready() const rows = await app.sqlite.all('SELECT 1 AS test') console.log(rows) await app.close()
Debug
Known issues
breakingIn version 1.0.0, the promiseApi option changed behavior: previously it used a custom promisify, now it uses the sqlite wrapper package.
fix
Update to 1.1.0 and ensure sqlite package is installed if using promiseApi: true.
affects: <=1.0.0
gotchaThe sqlite decorator is attached to the Fastify instance but only available after calling await app.ready().
fix
Always await app.ready() before accessing app.sqlite.
affects: *
gotchaWhen using promiseApi: false (default), all sqlite3 methods are callback-based and do not return promises.
fix
Use promiseApi: true if you need async/await support. Note: requires installing the 'sqlite' package as a peer dependency.
affects: *
deprecatedFastify v3 support was dropped in version 1.0.0; only Fastify v4 is supported.
fix
Upgrade Fastify to v4 if you are on v3 and want to use this plugin.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'sqlite'
Using promiseApi: true without installing the 'sqlite' package.
fix
Run npm install sqlite or yarn add sqlite.
TypeError: Cannot read property 'all' of undefined
Accessing app.sqlite before app.ready() completes.
fix
Ensure you await app.ready() before using app.sqlite.
Error: SQLITE_ERROR: no such table: myTable
Querying a table that hasn't been created yet, or using a different database file (e.g., :memory: loses data after close).
fix
Create the table before querying, or ensure you are using a persistent dbFile.
AssertionError [ERR_ASSERTION]: The module 'fastify-sqlite' is not a valid fastify plugin
Importing the package incorrectly (e.g., importing from a subpath that doesn't export a function).
fix
Import as import fastifySqlite from 'fastify-sqlite' and register it.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
fastifyrequiredpeer dependency for Fastify plugin interface
sqlite3requiredruntime dependency for SQLite database operations
sqliteoptionaloptional runtime dependency when promiseApi: true
Agent activity
5 hits · last 30 days
node
4
Resources
fastify-sqlite — npm install fastify-sqlite · libregistry