1.0.14 • Published 8 months ago

pallas-db v1.0.14

Weekly downloads
-
License
BSD-2-Clause
Repository
github
Last release
8 months ago

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

  1. get(key: string, defaultValue?: any): Promise<any>
    Retrieve a value by its key.

    const value = await db.get('settings.language', 'en');
  2. set(key: string, value: any): Promise<void>
    Set a value by its key.

    await db.set('settings.language', 'en');
  3. add(key: string, amount: number): Promise<void>
    Increment a numeric value by the specified amount.

    await db.add('stats.score', 10);
  4. sub(key: string, amount: number): Promise<void>
    Decrement a numeric value by the specified amount.

    await db.sub('stats.score', 5);
  5. delete(key: string): Promise<void>
    Remove a key and its value.

    await db.delete('settings.language');
  6. has(key: string): Promise<boolean>
    Check if a key exists.

    const exists = await db.has('settings.language');
  7. all(): Promise<Array<{ id: string; value: any }>>
    Retrieve all data from the current table.

    const records = await db.all();
  8. push(key: string, element: any): Promise<void>
    Add an element to an array.

    await db.push('users.favorites', 'new-item');
  9. cache(key: string, value: any, time: number): Promise<void>
    Set a temporary value.

    await db.cache('temp.key', 'value', 5000); // Deletes after 5 seconds
  10. deleteAll(): Promise<void>
    Remove all records from the current table.

    await db.deleteAll();
  11. 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.
1.0.14

8 months ago

1.0.13

8 months ago

1.0.12

8 months ago

1.0.11

8 months ago

1.0.9

8 months ago

1.0.8

8 months ago

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago