A lightweight, zero-dependency, encrypted data store for Node.js.
npm install apiro-db"users.123.profile.name")
bash
npm install apiro-db
`
---
๐ Quick Start
`js
import { SecureStore } from "apiro-db";
const db = new SecureStore({
file: "./data.db"
});
await db.set("users.1.name", "Alice");
await db.add("users.1.balance", 50);
console.log(await db.get("users.1"));
// { name: 'Alice', balance: 50 }
`
---
๐ Path-Based Storage
All keys are treated as paths by default.
`js
await db.set("pages.404.title", "Page Not Found");
await db.set("pages.404.content", "404
");
await db.get("pages.404.title");
// "Page Not Found"
`
Nested objects are created automatically when missing.
---
๐ API Reference
$3
`js
const db = new SecureStore({
file: "./secure.db" // optional
});
`
| Option | Description | Default |
| ------ | ------------------ | ------------- |
| file | Database file path | ./secure.db |
---
$3
Returns the value at the given path.
`js
await db.get("settings.theme");
`
---
$3
Sets a value at the given path.
`js
await db.set("settings.theme", "dark");
`
---
$3
Checks if a path exists.
`js
await db.has("users.123"); // true / false
`
---
$3
Deletes a value at the given path.
`js
await db.delete("sessions.old");
`
Returns true if the value existed.
---
$3
Adds a number to the existing value (or initializes to 0).
`js
await db.add("stats.visits", 1);
`
---
$3
Subtracts a number from the existing value.
`js
await db.subtract("stats.visits", 1);
`
---
$3
Pushes a value into an array (or initializes one).
`js
await db.push("logs", { event: "login" });
`
---
$3
Forces a final write to disk. Useful on shutdown.
`js
await db.close();
`
---
๐ Security Model
* A 256-bit master key is generated automatically on first run
* The master key is encrypted and stored inside the database
* All data payloads are encrypted using the master key
* No plaintext data is ever written to disk
* No user-supplied keys required
If the database file is copied or stolen, its contents remain unreadable.
---
โก Performance Model
* Reads and writes operate entirely in memory
* Disk writes are debounced and batched
* Encryption occurs only on flush
* Typical read/write latency: sub-millisecond
* Disk writes: ~50ms debounce window
$3
Path handling is always routed through internal helpers (getByPath, setByPath, deleteByPath`) with no conditional branching, ensuring consistent hot-path performance.