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

toon-db-lite

v0.0.1

Published

A lightning-fast, file-based database powered by the TOON format with built-in indexing and smart query optimization.

Downloads

96

Readme

⚡ Toon DB Lite

A lightning-fast, file-based database powered by the TOON format (faster than JSON) with built-in indexing and a smart query optimizer.

npm version License: MIT PRs Welcome


✨ Features

  • 🆔 Auto ID Generation - Automatic id field (short 5-char UUID) for all records.
  • Faster than JSON - Uses the TOON format for high-performance data serialization.
  • 🔍 Built-in Indexing - Fast lookups with automatic indexing on id and custom fields.
  • 🧠 Smart Query Optimizer - Automatically detects equality checks in .where() and uses indexes for speed.
  • 🧩 Zod Validation - Type-safe schemas and validation out of the box.
  • Result-based API - Clean { data, error } pattern (no more try/catch blocks).

📦 Install

# npm
npm install toon-db-lite

🚀 Quick Start

import { ToonDB } from 'toon-db-lite';
import { z } from 'zod';

// 1. Define your schemas
const userSchema = z.object({
  name: z.string().min(3, 'Name must be at least 3 chars'),
  age: z.number().min(18, 'Age must be 18+'),
});

// 2. Initialize DB
const db = new ToonDB('db.toon', {
  user: userSchema,
});

// 3. Insert data (ID is auto-generated!)
const { data, error } = db.table('user').insert({
  name: 'Gaurav',
  age: 19,
});

if (error) {
  console.error('Validation failed:', error.zodError);
} else {
  console.log('User created:', data.id); // e.g., 'a1b2c'
}

🔍 Queries & Operations

Find Records

// Find by ID (⚡ auto-indexed)
const user = db
  .table('user')
  .where((u) => u.id === 'a1b2c')
  .first();

// Find by field (uses optimizer if indexed)
const results = db
  .table('user')
  .where((u) => u.name === 'Gaurav')
  .all();

// Direct index lookup (manual optimization)
const users = db.table('user').findBy('name', 'Gaurav').all();

Update & Delete

// Update multiple records
db.table('user').update((u) => u.age < 20, { status: 'young' });

// Delete records
db.table('user').delete((u) => u.id === 'some-id');

🧠 Smart Query Optimizer

ToonDB Lite includes a regex-based query optimizer. It automatically detects simple equality checks in your .where() callbacks and switches to an indexed lookup if available.

// ⚡ This will be automatically optimized to use the 'name' index!
db.table('user')
  .where((u) => u.name === 'Gaurav')
  .all();

To enable optimization for custom fields, create an index:

db.createIndex('user', 'name');

⚡ TOON vs JSON

| Feature | TOON ⚡ | JSON 🐢 | | :---------- | :------------------------ | :-------------------- | | Speed | 🚀 Significantly Faster | 🐢 Standard | | Size | 📉 Smaller Footprint | 📈 Larger | | Parsing | ⚡ Efficient Stream-ready | 🐢 Blocks Main Thread |

Learn more about the format: toon-format


🛠️ API Reference

ToonDB(filename, schemas)

Initializes the database.

  • filename: Path to the .toon file.
  • schemas: An object where keys are table names and values are Zod schemas.

db.table(tableName)

Returns a Query object for the specified table.

Query Methods

  • .where(predicate): Filter records. Optimized for (x) => x.field === 'value'.
  • .insert(data): Add a new record. Returns { data, error }.
  • .update(predicate, data): Update matching records. Returns { data, error }.
  • .delete(predicate): Remove matching records.
  • .all(): Returns all results from the current query.
  • .first(): Returns the first result or undefined.
  • .findBy(field, value): Direct index-based search.

db.createIndex(tableName, field)

Manually create an index for a field to speed up queries.


📜 License

MIT © devgauravjatt