memory-level is an in-memory database implementation that adheres to the `abstract-level` API specification, designed for both Node.js and browser environments. It is currently at version 3.1.0 and is actively maintained, with releases often coinciding with upgrades to its underlying `abstract-level` interface. This package serves as the modern successor to earlier in-memory Level implementations like `memdown` and `level-mem`. A key differentiator is its backing by a fully persistent red-black tree, providing reliable in-memory data storage that supports implicit and explicit snapshots. Unlike disk-backed databases, closing or reopening a `memory-level` instance does not affect its stored data, which is only discarded when all references to the database are released. It offers flexible `storeEncoding` options to optimize for Buffer, Uint8Array, or UTF8 string storage, impacting how data types are handled internally for consistency and performance.
npm install memory-levelVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing an in-memory `MemoryLevel` database, performing basic `put`, `batch`, `get`, and `iterator` operations, and closing the database.
Review the `abstract-level` v3 migration guide for updated API signatures and behaviors. Update your database operations accordingly.
Refer to the `abstract-level` v2 migration guide for necessary changes in your application's database interactions.
Upgrade your Node.js environment to version 18 or newer to ensure compatibility and stability.
If immutability is required for Buffer values, explicitly clone the Buffer before storing it (e.g., `db.put(key, Buffer.from(myBuffer))`).
These options can be safely omitted or ignored when creating a `MemoryLevel` instance, as the in-memory nature makes them superfluous.
Use named imports for ESM: `import { MemoryLevel } from 'memory-level'`. For CommonJS, use destructuring: `const { MemoryLevel } = require('memory-level')`.Ensure your project's module configuration (`package.json` `type` field or file extensions like `.mjs`/`.cjs`) aligns with how you are importing `memory-level`. For newer projects, consider using ESM throughout. If forced to mix, ensure correct imports for each module system. If using TypeScript, check `tsconfig.json`'s `moduleResolution` and `module` settings.
Update your code to use the modern Promise-based `async/await` syntax for `get`, `put`, `del`, `batch`, and `iterator` operations as demonstrated in the quickstart, in line with `abstract-level` v2 and v3.