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 🙏

© 2025 – Pkg Stats / Ryan Hefner

deepbase

v3.2.0

Published

⚡ DeepBase - Fastest and simplest way to add persistence to your projects.

Downloads

1,663

Readme

deepbase

DeepBase - Multi-driver persistence system with JSON driver included.

Installation

npm install deepbase
# Automatically includes deepbase-json as dependency

What is DeepBase?

DeepBase is a powerful database abstraction that orchestrates multiple storage drivers. It includes:

  • JSON driver included: deepbase-json comes as a dependency for filesystem storage
  • Multi-driver management: Use multiple storage backends simultaneously
  • Automatic fallback: Read from first available driver
  • Replication: Write to all drivers or just primary
  • Migration: Built-in data migration between drivers
  • Driver interface: Base class for creating custom drivers

Quick Start

Simple Usage (JSON Driver - Built-in!)

import DeepBase from 'deepbase';

// Backward-compatible syntax - uses JSON driver by default
const db = new DeepBase({ path: './data', name: 'mydb' });
await db.connect();

await db.set('users', 'alice', { name: 'Alice' });
const alice = await db.get('users', 'alice');

Explicit Driver Usage

import DeepBase, { JsonDriver } from 'deepbase';

const db = new DeepBase(new JsonDriver({ path: './data' }));
await db.connect();

await db.set('users', 'alice', { name: 'Alice' });
const alice = await db.get('users', 'alice');

Additional Drivers

The JSON driver (deepbase-json) is included automatically. Install additional drivers as needed:

  • deepbase-sqlite - SQLite embedded database
  • deepbase-mongodb - MongoDB storage
  • deepbase-redis - Redis Stack storage

Multi-Driver Example

import DeepBase, { JsonDriver } from 'deepbase';
import MongoDriver from 'deepbase-mongodb';

const db = new DeepBase([
  new MongoDriver({ url: 'mongodb://localhost:27017' }),
  new JsonDriver({ path: './backup' })
], {
  writeAll: true,           // Write to both drivers
  readFirst: true,          // Read from first available
  failOnPrimaryError: false // Continue if MongoDB fails
});

await db.connect();

Timeout Configuration

Prevent operations from hanging indefinitely with configurable timeouts:

import DeepBase, { JsonDriver } from 'deepbase';

// Global timeout for all operations
const db = new DeepBase(new JsonDriver(), {
  timeout: 5000  // 5 seconds
});

// Different timeouts for reads and writes
const db2 = new DeepBase(new JsonDriver(), {
  readTimeout: 3000,   // 3 seconds for reads
  writeTimeout: 10000  // 10 seconds for writes
});

// All operations will timeout if they exceed the limit
try {
  await db.get('some', 'key');
} catch (error) {
  // Error: get() timed out after 5000ms
  console.error(error.message);
}

Timeout Options:

  • timeout: Global timeout for all operations (default: 0 = disabled)
  • readTimeout: Timeout for get, keys, values, entries (default: timeout)
  • writeTimeout: Timeout for set, del, inc, dec, add, upd (default: timeout)
  • connectTimeout: Timeout for connection operation (default: timeout)

See TIMEOUT_FEATURE.md for detailed documentation.

API

Constructor

new DeepBase(drivers, options)

Parameters:

  • drivers: Single driver or array of drivers
  • options:
    • writeAll (default: true): Write to all drivers
    • readFirst (default: true): Read from first available
    • failOnPrimaryError (default: true): Throw on primary failure
    • lazyConnect (default: true): Auto-connect on first operation
    • timeout (default: 0): Global timeout in ms (0 = disabled)
    • readTimeout (default: timeout): Timeout for read operations in ms
    • writeTimeout (default: timeout): Timeout for write operations in ms
    • connectTimeout (default: timeout): Timeout for connection in ms

Methods

Connection

  • await db.connect() - Connect all drivers
  • await db.disconnect() - Disconnect all drivers

Data Operations

  • await db.get(...path) - Get value at path
  • await db.set(...path, value) - Set value at path
  • await db.del(...path) - Delete value at path
  • await db.inc(...path, amount) - Increment value
  • await db.dec(...path, amount) - Decrement value
  • await db.add(...path, value) - Add with auto-generated ID
  • await db.upd(...path, fn) - Update with function

Query Operations

  • await db.keys(...path) - Get keys at path
  • await db.values(...path) - Get values at path
  • await db.entries(...path) - Get entries at path

Migration

  • await db.migrate(fromIndex, toIndex, options) - Migrate data
  • await db.syncAll(options) - Sync primary to all others

Driver Management

  • db.getDriver(index) - Get specific driver
  • db.getDrivers() - Get all drivers

Creating Custom Drivers

Extend the DeepBaseDriver class:

import { DeepBaseDriver } from '@deepbase/core';

class MyDriver extends DeepBaseDriver {
  async connect() { /* ... */ }
  async disconnect() { /* ... */ }
  async get(...args) { /* ... */ }
  async set(...args) { /* ... */ }
  async del(...args) { /* ... */ }
  async inc(...args) { /* ... */ }
  async dec(...args) { /* ... */ }
  async add(...args) { /* ... */ }
  async upd(...args) { /* ... */ }
}

License

MIT - Copyright (c) Martin Clasen