An Egg.js plugin for SQLite database operations, built on top of better-sqlite3. Version 1.1.9 supports Egg.js 2.x and 3.x, with multi-instance configuration, optional snake_case-to-camelCase field conversion (since v1.1.6), built-in transaction support with automatic rollback, SQL execution time logging in development, and error messages including the executed SQL. It provides a simple API: select, selects, insert, update, del, run. The plugin uses synchronous better-sqlite3 API wrapped in promises for Egg.js async context. Key differentiators include automatic camelCase conversion (opt-in) and multi-database support via clients config.
npm install ruoyi-eggjs-sqliteNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates plugin setup in config/plugin.js and config/config.default.js, then uses app.sqlite methods: run, insert, select, selects in a controller.
Use better-sqlite3 prepared statements via app.sqlite.run() with placeholders? Actually the plugin's API does not expose prepared statement binding. Consider using raw better-sqlite3 via app.sqlite._db for parameterized queries: app.sqlite._db.prepare('SELECT * FROM users WHERE id = ?').get(userInput). Alternatively, escape inputs or use a query builder.For heavy queries, consider offloading to a worker or using a truly async SQLite library like sql.js (WebAssembly) or better-sqlite3's synchronous nature is actually a performance benefit for many use cases, but be aware it can block. No direct fix needed, just be mindful.
Upgrade to v1.1.6 or later and set camelCase: true in config if you want automatic conversion.
Ensure you use exactly one of 'client' (single) or 'clients' (multi) in config. Do not set both unless you intend to have a default client AND named clients (not documented).
If you need a shared in-memory database across instances, use a single client with path ':memory:'.
Ensure plugin is enabled in config/plugin.js. If using multi-instance, call app.sqlite.get('dbName').select(...). For single instance, ensure config uses 'client' not 'clients'.Install build tools: `npm install -g node-gyp`. On Windows, install windows-build-tools. Alternatively, use `npm install --build-from-source` or try a different SQLite plugin.
Run `app.sqlite.run('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)')` before querying.Check if the query returned undefined (single row select with no match). Handle null/undefined before conversion, or disable camelCase.