Registry / database / fastify-sqlite-typed

fastify-sqlite-typed

JSON →
library5.0.2jsnpmunverified

Fastify plugin for SQLite integration, providing typed database access using node-sqlite3 and node-sqlite. v5.0.2 supports Fastify v5; Fastify v4 compatible branch available. Features configurable driver settings (verbose, cached, tracing), in-memory/disk databases, and multiple mode flags. Ships TypeScript types. Released under MIT license.

npm install fastify-sqlite-typed
INSTALL
IMPORT
SIG · FASTIFY-SQLITE-TYP
F
fastify-sqlite-typed
databasejavascriptv5.0.2
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.

fpSqlitePlugin
import { fpSqlitePlugin } from 'fastify-sqlite-typed'
const { fpSqlitePlugin } = require('fastify-sqlite-typed')
Named export; plugin is wrapped with fastify-plugin to avoid encapsulation issues.
sqlitePlugin
import { sqlitePlugin } from 'fastify-sqlite-typed'
import sqlitePlugin from 'fastify-sqlite-typed'
Named export, not default. Use without fastify-plugin wrapper if you want to manage encapsulation yourself.
Dbmode
import { Dbmode } from 'fastify-sqlite-typed'
Exported enum for database mode flags (READWRITE, CREATE, etc.). TypeScript only.

Shows basic registration with in-memory SQLite database and a route querying all users.

import fastify from 'fastify'; import { fpSqlitePlugin } from 'fastify-sqlite-typed'; const app = fastify(); app.register(fpSqlitePlugin, { dbFilename: ':memory:', mode: 0x00000002 | 0x00000004, // READWRITE | CREATE }); app.get('/users', async (request, reply) => { const users = await app.db.all('SELECT * FROM users'); reply.send(users); }); app.listen({ port: 3000 }, (err, address) => { if (err) throw err; console.log(`Server listening on ${address}`); });
Debug
Known issues
breakingRequires Fastify v5, not compatible with v4. Use v4 branch for Fastify v4.
fix
For Fastify v4, install the package from the Fastify-V4.x.x branch (e.g., `npm install yoav0gal/fastify-sqlite-typed#Fastify-V4.x.x`).
affects: >=5.0.0
gotchaMust use `fpSqlitePlugin` (wrapped with fastify-plugin) to avoid encapsulation issues. Using `sqlitePlugin` may cause `app.db` to be undefined outside the plugin scope.
fix
Import `fpSqlitePlugin` instead of `sqlitePlugin` unless you understand Fastify encapsulation.
affects: >=0.0.0
gotchaThe plugin does not create a database if `dbFilename` is empty string; use ':memory:' for in-memory or a valid file path.
fix
Set `dbFilename` to ':memory:' or a non-empty path.
affects: >=0.0.0
deprecatedDbmode enum values are numeric; future versions may use string flags.
fix
Use numeric values for now; check changelog on upgrade.
affects: <=5.0.2
Errors
Common errors & fixes
Cannot find module 'fastify-sqlite-typed'
Module not installed or import path incorrect.
fix
Run `npm install fastify-sqlite-typed` and use `import { fpSqlitePlugin } from 'fastify-sqlite-typed'`.
app.db is undefined
Used `sqlitePlugin` without fastify-plugin wrapper, or registered outside route scope.
fix
Use `fpSqlitePlugin` import and ensure plugin registration occurs before route definitions.
TypeError: db.all is not a function
Database not opened properly; likely missing `await` or incorrect plugin registration.
fix
Ensure `app.register(fpSqlitePlugin, ...)` is called and routes are async with proper await on db methods.
Upgrade
Version history
5.0.2latest on npm
Audit
Dependencies
fastifyrequiredpeer dependency - plugin requires Fastify instance
Agent activity
9 hits · last 30 days
node
8
Resources
fastify-sqlite-typed — npm install fastify-sqlite-typed · libregistry