sqlite-level is a Node.js library that provides an `abstract-level` compliant interface, backed by a SQLite database. It leverages `better-sqlite3` for its underlying SQLite operations, offering a synchronous-like API while maintaining `abstract-level` compatibility. This allows developers familiar with the LevelDB API to utilize a durable, file-based store without needing to manage separate database processes or complex setups typical of other embedded databases. Currently stable at version 1.2.1, its release cadence is tied to the needs of the TinaCMS project, ensuring ongoing maintenance and updates. A key differentiator is its use of SQLite, offering ACID properties and wide tooling support, contrasting with LevelDB's LSM-tree design. It's particularly useful for server-side applications requiring a lightweight, transactional key-value store with data persistence for development or smaller deployments.
npm install sqlite-levelVerified import paths — ran on the pinned version, not inferred.
Demonstrates opening a SQLite-backed LevelDB, performing basic put, get, delete operations, and iterating over stored keys and values, ensuring proper database closure.
Ensure you have C++ build tools installed (e.g., `build-essential` on Debian/Ubuntu, Xcode Command Line Tools on macOS, or Visual Studio Build Tools on Windows). Consider using a Docker environment for consistent builds.
Implement retry logic for write operations, or design your application to minimize concurrent writes to the same database. Consider moving to a more robust database solution if high-volume, concurrent writes are a core requirement.
For Node.js projects, ensure your `package.json` specifies `"type": "module"` or use dynamic `import()` for `sqlite-level`. If using TypeScript, configure `"module": "NodeNext"` or `"ESNext"` in `tsconfig.json`.
Always ensure `db.close()` is called and awaited in a `finally` block or on application shutdown hooks. For long-running processes, consider implementing graceful shutdown procedures.
Change your importing code from `const { Level } = require('sqlite-level');` to `import { Level } from 'sqlite-level';`. Ensure your `package.json` for the consuming project has `"type": "module"` or dynamically import with `const { Level } = await import('sqlite-level');`.This often occurs in concurrent environments. Implement basic retry logic with a short delay for write operations. Ensure database connections are managed properly and closed when not in use. Consider using WAL mode if not already active.
Ensure all database operations are completed before `db.close()` is called. Use `db.isOpen()` to check the database state if you suspect it might be closed prematurely. Wrap operations in `try...finally` to ensure `db.close()` is called only when needed.