npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pallas-db

v1.0.14

Published

All in the name

Downloads

355

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

  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.