A Node.js wrapper around better-sqlite3 providing shorthand query methods, automatic migration support, and a singleton pattern for simple server apps. Version 3.x (latest 3.1.7) uses better-sqlite3 v7, drops Node <10, and requires @types/better-sqlite3 as a peer dependency for TypeScript support. It simplifies database access with methods like query(), queryFirstRow(), insert(), and update(), and includes a migration system that runs SQL files on startup. Compared to better-sqlite3 alone, it reduces boilerplate by managing a global instance and handling migrations automatically. Release cadence is irregular; last release was Sep 2023.
npm install better-sqlite3-helperNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows core usage: configuring the singleton, executing DDL, inserting, and querying with shorthand methods.
Upgrade Node.js version to >=10 and use ':memory:' as path for in-memory databases.
Use DB().query(...) or const db = DB(); db.query(...).
Ensure better-sqlite3 >=5 is installed if using better-sqlite3-helper v2.
Either chain configuration and usage: DB(options); const db = DB(). Or use a two-step pattern.
Ensure migration files are named sequentially and exist at the configured path.
Replace 'new DB()' with 'DB()'.
Ensure the first call to DB() includes configuration options, then subsequent calls return the instance. Or call DB() without arguments after configuration.
Use db.query(), db.execute(), db.insert() etc. For direct access, use db.raw property to get the underlying better-sqlite3 Database object.
Use an absolute path or ensure the migrations directory is at the application root.