-
JSON & SQLite Backends
// Uses JSON if file ends with .json const jsonDB = new QuantumDB('data.json'); // Uses SQLite if file ends with .db/.sqlite const sqlDB = new QuantumDB('data.db');
-
Automatic File Creation
- Creates
quantum.sqlite
by default if no file specified - Initializes empty JSON/SQLite files when they don't exist
- Creates
-
Basic CRUD Operations
await db.set('key', 'value'); const value = await db.get('key'); await db.delete('key');
-
Enhanced Security
- Strict key validation (256 char max)
- File permission controls (0600)
- Path traversal protection
npm install qd.db better-sqlite3
Method | Description | Example |
---|---|---|
set(key, value) |
Stores any serializable value | await db.set('config', { darkMode: true }) |
get(key) |
Retrieves stored value | const config = await db.get('config') |
delete(key) |
Removes key-value pair | await db.delete('temp') |
Method | Description |
---|---|
push(key, value) |
Appends to array (auto-creates if needed) |
pull(key, value) |
Removes all occurrences of value from array |
Method | Description |
---|---|
add(key, amount) |
Increments number (default +1) |
subtract(key, amount) |
Decrements number (default -1) |
Method | Description |
---|---|
bulkDelete(keys) |
Deletes multiple keys at once |
getAll() |
Returns all key-value pairs |
clearAll() |
Clears entire database |
Method | Description |
---|---|
has(key) |
Checks if key exists |
findKeys(pattern) |
Regex search for keys |
startsWith(prefix) |
Finds keys with prefix |
const { QuantumDB } = require('qd.db');
// Default SQLite database
const db = new QuantumDB();
// Or specify file
const jsonDB = new QuantumDB('config.json');
await db.add('visits', 1); // Increment counter
await db.subtract('balance', 50); // Decrease balance
await db.push('todos', 'Buy milk');
await db.pull('todos', 'Buy milk');
The library throws descriptive errors:
try {
await db.set('', 'value'); // Empty key
} catch (err) {
console.error(err.message); // "Key must be a non-empty string"
}
- All database files created with restrictive permissions (0600)
- Only allows
.json
,.db
, and.sqlite
extensions - Keys are validated against invalid characters
Join our developer community for support and updates: Discord Server
MIT © Quantum Developers