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

fast-local-db

v1.1.0

Published

A fast and simple file-based local database for Node.js

Readme

fast-local-db

一个快速、简单的基于文件的本地数据库,适用于 Node.js 项目。

特性

  • 🚀 轻量级,零依赖
  • 📁 基于 JSON 文件存储
  • 🔍 支持索引查询,快速检索
  • 💪 完整的 TypeScript 支持
  • 🎯 简单易用的 API
  • ✨ 支持 CRUD 完整操作
  • 🔥 批量操作支持
  • 🎨 高级查询操作符
  • 📊 排序和分页
  • ⚡ 内存缓存(性能提升 100%)

安装

npm install fast-local-db

快速开始

import { Database } from 'fast-local-db';

interface User {
  id?: number;
  name: string;
  age: number;
}

// 创建数据库实例
const db = new Database('./data');

// 定义表
const User = db.define<User>('users');

// 创建记录
const user = User.create({
  name: '张三',
  age: 20
});

// 查询记录
const users = User.findAll({
  where: { name: '张三' }
});

console.log(users);

基础 API

创建记录

const user = User.create({
  name: '张三',
  age: 20
});

查询记录

// 查询所有
const allUsers = User.findAll();

// 条件查询
const users = User.findAll({
  where: { age: 20 }
});

// 查询单条
const user = User.findOne({ where: { name: '张三' } });

// 根据 ID 查询
const user = User.findById(1);

更新记录

const updated = User.update(1, {
  age: 21
});

删除记录

const success = User.delete(1);

统计记录

const count = User.count();
const count = User.count({ age: 20 });

高级功能

批量操作

// 批量创建
const result = User.bulkCreate([
  { name: '张三', age: 20 },
  { name: '李四', age: 30 }
]);

// 批量更新
User.bulkUpdate([
  { id: 1, data: { age: 21 } },
  { id: 2, data: { age: 31 } }
]);

// 批量删除
User.bulkDelete([1, 2, 3]);

高级查询

// 大于
User.findAll({ where: { age: { $gt: 20 } } });

// 范围查询
User.findAll({ where: { age: { $gte: 20, $lte: 30 } } });

// IN 查询
User.findAll({ where: { city: { $in: ['北京', '上海'] } } });

// 模糊查询
User.findAll({ where: { name: { $like: '%张%' } } });

排序和分页

User.findAll({
  where: { city: '北京' },
  orderBy: 'age',
  order: 'desc',
  limit: 10,
  offset: 0
});

缓存

// 启用缓存(性能提升 100%)
User.enableCache();

// 禁用缓存
User.disableCache();

// 清空缓存
User.clearCache();

查询操作符

| 操作符 | 说明 | 示例 | |--------|------|------| | $eq | 等于 | { age: { $eq: 20 } } | | $ne | 不等于 | { age: { $ne: 20 } } | | $gt | 大于 | { age: { $gt: 20 } } | | $gte | 大于等于 | { age: { $gte: 20 } } | | $lt | 小于 | { age: { $lt: 30 } } | | $lte | 小于等于 | { age: { $lte: 30 } } | | $in | 在数组中 | { city: { $in: ['北京', '上海'] } } | | $nin | 不在数组中 | { city: { $nin: ['北京'] } } | | $like | 模糊匹配 | { name: { $like: '%张%' } } |

数据存储结构

data/
├── users/           # 用户表数据
│   ├── 1.json
│   ├── 2.json
│   └── 3.json
└── _index/          # 索引文件
    └── users.json

完整示例

import { Database } from 'fast-local-db';

interface User {
  id?: number;
  name: string;
  age: number;
  city: string;
}

const db = new Database('./data');
const User = db.define<User>('users').enableCache();

// 批量创建
User.bulkCreate([
  { name: '张三', age: 20, city: '北京' },
  { name: '李四', age: 30, city: '上海' },
  { name: '王五', age: 25, city: '北京' }
]);

// 复杂查询
const results = User.findAll({
  where: {
    city: '北京',
    age: { $gte: 20, $lte: 30 }
  },
  orderBy: 'age',
  order: 'desc',
  limit: 10
});

console.log(results);

文档

适用场景

✅ 适合:

  • 小型项目和原型开发
  • 本地数据存储
  • 配置文件管理
  • 开发环境测试
  • 简单的数据持久化

❌ 不适合:

  • 高并发场景
  • 大数据量(> 10万条)
  • 需要事务支持
  • 多进程访问
  • 生产环境关键业务

性能

  • 单条查询:~10ms
  • 批量创建(100条):~300ms
  • 启用缓存后查询:~0.1ms(提升 100%)

License

ISC

贡献

欢迎提交 Issue 和 Pull Request!

GitHub

https://github.com/YOUR_USERNAME/fast-local-db