{"id":50990060,"url":"https://github.com/devgauravjatt/toon-db-lite","last_synced_at":"2026-06-20T01:02:53.024Z","repository":{"id":345801555,"uuid":"1187442250","full_name":"devgauravjatt/toon-db-lite","owner":"devgauravjatt","description":"A lightning-fast, file-based database powered by the TOON format (faster than JSON) with built-in indexing and a smart query optimizer.","archived":false,"fork":false,"pushed_at":"2026-03-20T18:37:44.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-21T09:46:03.682Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devgauravjatt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-20T18:21:33.000Z","updated_at":"2026-03-20T18:37:47.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/devgauravjatt/toon-db-lite","commit_stats":null,"previous_names":["devgauravjatt/toon-db-lite"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/devgauravjatt/toon-db-lite","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devgauravjatt%2Ftoon-db-lite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devgauravjatt%2Ftoon-db-lite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devgauravjatt%2Ftoon-db-lite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devgauravjatt%2Ftoon-db-lite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devgauravjatt","download_url":"https://codeload.github.com/devgauravjatt/toon-db-lite/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devgauravjatt%2Ftoon-db-lite/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34553461,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-19T02:00:06.005Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-20T01:02:52.267Z","updated_at":"2026-06-20T01:02:53.015Z","avatar_url":"https://github.com/devgauravjatt.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ⚡ Toon DB Lite\n\n\u003e A lightning-fast, file-based database powered by the **TOON format** (faster than JSON) with built-in indexing and a smart query optimizer.\n\n[![npm version](https://img.shields.io/npm/v/toon-db-lite.svg)](https://www.npmjs.com/package/toon-db-lite)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com)\n\n---\n\n## ✨ Features\n\n- 🆔 **Auto ID Generation** - Automatic `id` field (short 5-char UUID) for all records.\n- ⚡ **Faster than JSON** - Uses the [TOON format](https://github.com/toon-format/toon) for high-performance data serialization.\n- 🔍 **Built-in Indexing** - Fast lookups with automatic indexing on `id` and custom fields.\n- 🧠 **Smart Query Optimizer** - Automatically detects equality checks in `.where()` and uses indexes for speed.\n- 🧩 **Zod Validation** - Type-safe schemas and validation out of the box.\n- ✅ **Result-based API** - Clean `{ data, error }` pattern (no more `try/catch` blocks).\n\n---\n\n## 📦 Install\n\n```bash\n# npm\nnpm install toon-db-lite\n```\n\n---\n\n## 🚀 Quick Start\n\n```ts\nimport { ToonDB } from 'toon-db-lite';\nimport { z } from 'zod';\n\n// 1. Define your schemas\nconst userSchema = z.object({\n  name: z.string().min(3, 'Name must be at least 3 chars'),\n  age: z.number().min(18, 'Age must be 18+'),\n});\n\n// 2. Initialize DB\nconst db = new ToonDB('db.toon', {\n  user: userSchema,\n});\n\n// 3. Insert data (ID is auto-generated!)\nconst { data, error } = db.table('user').insert({\n  name: 'Gaurav',\n  age: 19,\n});\n\nif (error) {\n  console.error('Validation failed:', error.zodError);\n} else {\n  console.log('User created:', data.id); // e.g., 'a1b2c'\n}\n```\n\n---\n\n## 🔍 Queries \u0026 Operations\n\n### Find Records\n\n```ts\n// Find by ID (⚡ auto-indexed)\nconst user = db\n  .table('user')\n  .where((u) =\u003e u.id === 'a1b2c')\n  .first();\n\n// Find by field (uses optimizer if indexed)\nconst results = db\n  .table('user')\n  .where((u) =\u003e u.name === 'Gaurav')\n  .all();\n\n// Direct index lookup (manual optimization)\nconst users = db.table('user').findBy('name', 'Gaurav').all();\n```\n\n### Update \u0026 Delete\n\n```ts\n// Update multiple records\ndb.table('user').update((u) =\u003e u.age \u003c 20, { status: 'young' });\n\n// Delete records\ndb.table('user').delete((u) =\u003e u.id === 'some-id');\n```\n\n---\n\n## 🧠 Smart Query Optimizer\n\nToonDB 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.\n\n```ts\n// ⚡ This will be automatically optimized to use the 'name' index!\ndb.table('user')\n  .where((u) =\u003e u.name === 'Gaurav')\n  .all();\n```\n\nTo enable optimization for custom fields, create an index:\n\n```ts\ndb.createIndex('user', 'name');\n```\n\n---\n\n## ⚡ TOON vs JSON\n\n| Feature     | TOON ⚡                   | JSON 🐢               |\n| :---------- | :------------------------ | :-------------------- |\n| **Speed**   | 🚀 Significantly Faster   | 🐢 Standard           |\n| **Size**    | 📉 Smaller Footprint      | 📈 Larger             |\n| **Parsing** | ⚡ Efficient Stream-ready | 🐢 Blocks Main Thread |\n\nLearn more about the format: [toon-format](https://github.com/toon-format/toon)\n\n---\n\n## 🛠️ API Reference\n\n### `ToonDB(filename, schemas)`\n\nInitializes the database.\n\n- `filename`: Path to the `.toon` file.\n- `schemas`: An object where keys are table names and values are Zod schemas.\n\n### `db.table(tableName)`\n\nReturns a `Query` object for the specified table.\n\n### `Query` Methods\n\n- `.where(predicate)`: Filter records. Optimized for `(x) =\u003e x.field === 'value'`.\n- `.insert(data)`: Add a new record. Returns `{ data, error }`.\n- `.update(predicate, data)`: Update matching records. Returns `{ data, error }`.\n- `.delete(predicate)`: Remove matching records.\n- `.all()`: Returns all results from the current query.\n- `.first()`: Returns the first result or `undefined`.\n- `.findBy(field, value)`: Direct index-based search.\n\n### `db.createIndex(tableName, field)`\n\nManually create an index for a field to speed up queries.\n\n---\n\n## 📜 License\n\nMIT © [devgauravjatt](https://github.com/devgauravjatt)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevgauravjatt%2Ftoon-db-lite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevgauravjatt%2Ftoon-db-lite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevgauravjatt%2Ftoon-db-lite/lists"}