pallas-db
v1.0.14
Published
All in the name
Downloads
355
Maintainers
Readme
Documentation for PallasDB
PallasDB is a database management library supporting SQLite, PostgreSQL, and MySQL, focusing on simple key-value operations.
Installation
npm install pallas-db
Creating an Instance
// IF ESM
import { PallasDB } from 'pallas-db';
// IF CommonJS
const { PallasDB } = require("pallas-db");
const db = new PallasDB({
dialect: 'sqlite', // 'postgres' or 'mysql'
storage: './database.sqlite', // Path for SQLite
tables: ['users', 'settings'], // List of tables
enableVerbose: true, // For logging
});
Methods
get(key: string, defaultValue?: any): Promise<any>
Retrieve a value by its key.const value = await db.get('settings.language', 'en');
set(key: string, value: any): Promise<void>
Set a value by its key.await db.set('settings.language', 'en');
add(key: string, amount: number): Promise<void>
Increment a numeric value by the specified amount.await db.add('stats.score', 10);
sub(key: string, amount: number): Promise<void>
Decrement a numeric value by the specified amount.await db.sub('stats.score', 5);
delete(key: string): Promise<void>
Remove a key and its value.await db.delete('settings.language');
has(key: string): Promise<boolean>
Check if a key exists.const exists = await db.has('settings.language');
all(): Promise<Array<{ id: string; value: any }>>
Retrieve all data from the current table.const records = await db.all();
push(key: string, element: any): Promise<void>
Add an element to an array.await db.push('users.favorites', 'new-item');
cache(key: string, value: any, time: number): Promise<void>
Set a temporary value.await db.cache('temp.key', 'value', 5000); // Deletes after 5 seconds
deleteAll(): Promise<void>
Remove all records from the current table.await db.deleteAll();
table(name: string): PallasDB
Switch to another table.const settingsTable = db.table('settings');
Example Usage
await db.set('users.anais', { age: 19, role: 'admin' });
const user = await db.get('users.anais');
console.log(user.age); // 19
await db.add('users.anais.age', 1);
await db.delete('users.anais.role');
Features
- Supports nested keys (
key.subkey
). - Simple integration with Sequelize.
- Automatic table synchronization.