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

fudb

v0.0.2-node

Published

a simple db based on btree data structure

Downloads

18

Readme

jsDB - 一个实现btree索引的小玩具

简单实现一个基于btree索引的小玩具,文件存放磁盘中,实现简单的查询和插入功能,代码还有点乱;

Requirements

  • node(>= v9.0.0)
  • lru-cache(用来做page缓存)

Quick Start

npm install fudb;
  • 创建一个db并且写入数据的操作:
  const fudb = require('fudb');
  
  const fn = async (itemNum) => {
  	const db = await fudb.Create('js', 'name');
  	for (let i = 0; i < itemNum; i += 1) {
  		await db.put({
  	      name: `funer80900090009${i}`,
  	      sex: `${{ 0: 'female', 1: 'male', 2: 'shemale' }[i % 3]}`,
  	      className: `super${i}`,
  	    }); // eslint-disable-line
  	}
  	await db.flush();
  }
  fn(100);

这样就在该项目目录下生成一个js目录,里面有连个文件js.dbjs.index,分别为原始数据文件,索引文件;注意一点由于简化实现,添加数据要小于一定值(1kb);

  • 打开一个该类型的文件:
const fudb = require('fudb');

const fn = async () => {
  const db = await fudb.Connect('js');
  for (let i = 0; i < 100; i += 1) {
    const result = await db.findByKey('name', `funer80900090009${i}`);
    console.log(result);
    if (!result) {
      throw new Error('error!');
    }
  }
}
fn();
  • 范围查询:
const fudb = require('fudb');

const fn = async () => {
  const db = await fudb.Connect('js');
  db.range('name', { lt: 'funer809000900091', gt: 'funer809000900091' }).then((data) => {
    console.log('count', data.total());
    console.log('ids', data.cells);
    data.fetch().then((details) => {
      details.forEach((d) => {
        console.log('detail', fudb.Parse(d));
      });
    });
  });
}
fn();

注意查询的时候必须要有{lt:, gt:},暂不支持单边的查找,以后慢慢支持;range函数返回的是一个Promise; 且该方法是先统计btree的id的个数,并未实际获取真实的rawdata,该Promise返回的数据为:

{
  count: () => {}, // 返回range查询的item总数,这里是统计的id的数量
  cells: [{id: 'xxx'}],// 返回为包含id的对象数组
  fetch: async() => {} // 通过索引id去加载rawdata
}

ToDo List

  • 实现删除的操作(进行中)
  • 不限制1kb的数据大小
  • 实现page缓存处理,不用lru-cache依赖
  • 完善代码