a1-database is an embedded, zero-dependency, zero-installation JSON database designed for simplicity and portability. As of version 1.8.0, it stores all data in a single file, making it ideal for development, local applications, or scenarios where a lightweight, persistent data store is required without external database server overhead. It operates directly on JavaScript objects, eliminating the need for an ORM, and returns query results as arrays of objects. The package provides methods that cater to both SQL-like (e.g., `insert`, `update` with `id` keys) and document-like (flexible `save` with custom filter functions for multi-key or heterogeneous data) paradigms. Each database instance is represented by a single file, facilitating easy backup and data dumping. Its primary release cadence is not explicitly stated, but ongoing development is implied by the version number, focusing on a straightforward API for common CRUD operations like `save`, `find`, and `delete`.
npm install a1-databaseVerified import paths — ran on the pinned version, not inferred.
Demonstrates database connection, saving data (including upsert behavior with IDs), finding records, checking existence, and deleting entries, along with proper cleanup of the database file.
Always use absolute paths or carefully manage the current working directory to ensure the database file is created and accessed in the intended location.
When using `save`, be explicit about providing `id` for upserts, or define precise filter functions to control replacement behavior. Use `insert` for strict 'add-only' semantics.
If an item might already exist, use `save` if overwriting is acceptable. If strict uniqueness is required for new entries, use `insert` and wrap calls in a `try...catch` block to handle potential duplicate ID errors.
For high-throughput applications, consider batching writes or evaluating if an in-memory or server-based database is more appropriate. Monitor disk I/O metrics if performance becomes a concern.
To fix this, either ensure that the `id` is unique before calling `db.insert()`, or use `db.save()` instead if the intention is to update/overwrite the existing item with the same `id`.
No dependency data recorded yet.