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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@zenithdb/storage

v0.3.0

Published

Storage adapters and interfaces for Zenith database engine

Readme

ZenithDB Storage

Storage adapters and interfaces that provide a powerful wrapper around IndexedDB and other storage backends with a unified API for the ZenithDB database engine.

Description

@zenithdb/storage provides pluggable storage adapters that abstract different storage backends behind a common interface. The primary adapter wraps IndexedDB with enhanced features like automatic transaction management, optimized bulk operations, and schema migrations, while maintaining compatibility with the browser's native storage capabilities.

Installation

NPM

# Install storage package
npm install @zenithdb/storage @zenithdb/types

# Or install everything at once
npm install @zenithdb/kit

Note: For complete functionality, consider using @zenithdb/kit which includes all ZenithDB packages.

Quick Start

IndexedDB Adapter

import { IndexedDBAdapter } from "@zenithdb/storage";
import { createDatabase, createSchema, fields } from "@zenithdb/core";

// Create IndexedDB adapter
const adapter = new IndexedDBAdapter("myapp", {
  version: 1,
});

// Use with Zenith database
const schema = createSchema({
  name: "MyApp",
  version: 1,
  tables: {
    users: {
      primaryKey: "id",
      schema: {
        id: fields.string({ required: true }),
        name: fields.string({ required: true }),
        email: fields.string({ unique: true }),
      },
    },
  },
  adapter: "indexeddb",
});

const db = await createDatabase(schema);

Direct Adapter Usage

import { IndexedDBAdapter } from "@zenithdb/storage";

const adapter = new IndexedDBAdapter("direct-usage");

// Open connection
await adapter.open({
  name: "DirectDB",
  version: 1,
  tables: {
    items: {
      id: { type: "string", primaryKey: true },
      data: { type: "object" },
    },
  },
});

// Direct CRUD operations
await adapter.insert("items", {
  id: "item-1",
  data: { name: "Test Item" },
});

const item = await adapter.get("items", "item-1");
console.log("Retrieved item:", item);

// Bulk operations
await adapter.bulkInsert("items", [
  { id: "item-2", data: { name: "Bulk Item 1" } },
  { id: "item-3", data: { name: "Bulk Item 2" } },
]);

// Queries
const results = await adapter.find("items", {
  where: [{ field: "data.name", operator: "contains", value: "Bulk" }],
  orderBy: [{ field: "id", direction: "asc" }],
  limit: 10,
});

await adapter.close();

Custom Storage Adapter

import {
  StorageAdapter,
  DatabaseConfig,
  QueryOptions,
} from "@zenithdb/storage";

class CustomStorageAdapter implements StorageAdapter {
  async open(config: DatabaseConfig): Promise<void> {
    // Initialize your storage backend
    console.log("Opening custom storage:", config.name);
  }

  async close(): Promise<void> {
    // Cleanup connections
    console.log("Closing custom storage");
  }

  async insert(table: string, data: any): Promise<any> {
    // Implement insert logic
    return { ...data, _id: generateId() };
  }

  async get(table: string, key: any): Promise<any | null> {
    // Implement get logic
    return null;
  }

  async update(table: string, key: any, data: Partial<any>): Promise<any> {
    // Implement update logic
    return data;
  }

  async delete(table: string, key: any): Promise<boolean> {
    // Implement delete logic
    return true;
  }

  async find(table: string, options?: QueryOptions): Promise<any[]> {
    // Implement query logic
    return [];
  }

  async count(table: string, options?: QueryOptions): Promise<number> {
    // Implement count logic
    return 0;
  }

  async bulkInsert(table: string, items: any[]): Promise<any[]> {
    // Implement bulk insert logic
    return Promise.all(items.map((item) => this.insert(table, item)));
  }

  async beginTransaction(tables: string[]): Promise<any> {
    // Implement transaction begin
    return {};
  }

  async commitTransaction(transaction: any): Promise<void> {
    // Implement transaction commit
  }

  async rollbackTransaction(transaction: any): Promise<void> {
    // Implement transaction rollback
  }

  async createIndex(
    table: string,
    indexName: string,
    keyPath: string | string[],
    unique?: boolean,
  ): Promise<void> {
    // Implement index creation
  }

  async dropIndex(table: string, indexName: string): Promise<void> {
    // Implement index removal
  }
}

// Use custom adapter
const customAdapter = new CustomStorageAdapter();
const db = new Database({
  name: "CustomApp",
  version: 1,
  adapter: customAdapter,
  tables: {
    /* your schema */
  },
});

Storage Adapter Interface

All storage adapters implement the StorageAdapter interface:

interface StorageAdapter {
  // Database lifecycle
  open(config: DatabaseConfig): Promise<void>;
  close(): Promise<void>;

  // CRUD operations
  insert(table: string, data: any): Promise<any>;
  get(table: string, key: any): Promise<any | null>;
  update(table: string, key: any, data: Partial<any>): Promise<any>;
  delete(table: string, key: any): Promise<boolean>;

  // Query operations
  find(table: string, options?: QueryOptions): Promise<any[]>;
  count(table: string, options?: QueryOptions): Promise<number>;

  // Bulk operations
  bulkInsert(table: string, items: any[]): Promise<any[]>;
  bulkUpdate(
    table: string,
    updates: Array<{ key: any; data: Partial<any> }>,
  ): Promise<any[]>;
  bulkDelete(table: string, keys: any[]): Promise<boolean[]>;

  // Transaction management
  beginTransaction(tables: string[]): Promise<any>;
  commitTransaction(transaction: any): Promise<void>;
  rollbackTransaction(transaction: any): Promise<void>;

  // Index management
  createIndex(
    table: string,
    indexName: string,
    keyPath: string | string[],
    unique?: boolean,
  ): Promise<void>;
  dropIndex(table: string, indexName: string): Promise<void>;
}

Available Adapters

IndexedDBAdapter

The primary adapter that wraps IndexedDB with enhanced features:

  • Full CRUD operations with automatic transaction management
  • Complex queries with multiple conditions and sorting
  • Bulk operations optimized for performance
  • Schema migrations with version management
  • Index management for query optimization
  • Transaction support with rollback capabilities

Future Adapters

  • SQLiteAdapter - For Node.js environments
  • WebSQLAdapter - Legacy browser support