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 🙏

© 2024 – Pkg Stats / Ryan Hefner

nodedb

v0.0.16

Published

暂时想不到准确的描述方式,以后再 # 以下是一些笔记 - 这个“数据库”,目前能力有限,使用文件存储,而且是明文的,这个底层以后再想 - 每个“文档”存储一个文件,文件名为 md5(user_identity)+'_'+user_identity - 文件内容为json序列化,这个部分以后可能要注意try-catch - 导出的模块是个function,需要传入一个对象作为参数,对象包含一个属性 path,代表的是数据存储的位置,缺省是是当前目录 - 你要确保这个path有写入权限 - 模块

Downloads

30

Readme

nodedb

暂时想不到准确的描述方式,以后再

以下是一些笔记

  • 这个“数据库”,目前能力有限,使用文件存储,而且是明文的,这个底层以后再想
  • 每个“文档”存储一个文件,文件名为 md5(user_identity)+'_'+user_identity
  • 文件内容为json序列化,这个部分以后可能要注意try-catch
  • 导出的模块是个function,需要传入一个对象作为参数,对象包含一个属性 path,代表的是数据存储的位置,缺省是是当前目录
  • 你要确保这个path有写入权限
  • 模块初始化时会检查这个path下面有没有 _indexs 目录,否则会自行创建(一般也就第一次),这个是索引的目录
  • 说到索引,这是个反向索引,通过 路径+值来做hash,反向指向 uid
  • test

这里需要阐述一些名词

路径:文档的每一个节点都可以通过一个路径来访问,举个例子,一个uid为 baiqi 的文档如下
{
	'name':'小白',
	'age':17,
	'tel':{
		'work':110
	}
}
那么,通过  /baiqi/name  就可以读取到 '小白' ; 
通过 /baiqi/tel/work 就可以读到 110,
同样可以通过 /baiqi/tel 读取 {'work':110}

get 、 put 、 match 、 range

get
文档获取的方法,支持任意深度,如 
nodedb.get('/baiqi/name',function(e,r){
 	//r => '小白'
});

put 
写入数据的方法,节点不存在时会创建,节点存在时,只更新传入的属性,如
第二个参数为写入的数据,第三个参数会根据第二个参数类型变化,后面索引部分详细讲
nodedb.put('/baiqi/age',16,true,function(e,r){
	// 只会更新 age 信息,不影响 name 以及其他属性, true 表示对age=16做索引
});
也可以用对象形式写入,索引参数传数组
nodedb.put('/baiqi',{age:16,type:'农历'},['age'],function(e,r){
	 //只会更新 age 信息,不影响 name 以及其他属性,
	 //['age'] 表示针对 对象的age属性做索引,对type属性不索引,结果和上面的例子是一样的
});

match
对指定路径的值做全匹配查询,前提是put的时候做了索引,需要注意第一个参数的写法
nodedb.match('/age',16,function(e,r){
	// 返回一个数组  [{uid: 'baiqi',data:{name: '小白',age: 18} } ]
});

range
这个是对数字(整数)类型数据的范围查询,同样需要put的时候索引
nodedb.range('/age',[6,19],function(e,r){
	// 表示查询age在6,19之间的文档,返回数组
	//如果是 [19,6]表示大于等于19 或 小于等于6,两端延伸的开区间
});