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

apdb

v1.0.0

Published

Red-black-tree-based data storage (for small program / light application / node / browser ), efficient and lightweight, support for persistence and temporary storage!

Downloads

4

Readme

Apdb

Red-black-tree-based data storage (for small program / light application / node / browser ), efficient and lightweight, support for persistence and temporary storage!

Usage

Install

npm i apdb --save

1. Import

  1. for nodejs
    import apdb from 'apdb/node';
  2. for wechat mini app
    import apdb from 'apdb/wechat';
  3. for web browser
    import apdb from 'apdb/web';

2. Initial

const apdb = new apdb( params );

params [object]

| key | desc | default | | --- | --- | --- | | table | [string] storage table name | 'default' |

3. Insert

const result = await apdb.insert( params );

result [boolean]

if insert successful, result is true

params [object]

| key | desc | default | | --- | --- | --- | | key | [string] primary key | Date.now() + Math.random() | | value | [object] value | null | | update | [boolean] update current tree to storage, improve multi-line insert performance | true |

demo

await apdb.insert({
  key: 'apdb key', 
  value: {
    name: 'apdb',
    author: 'echosoar'
  }
});

4. Select

const result = await apdb.select( params );

result [object]

| key | desc | | --- | --- | | total | [number] Total number of data | | result | [array] all lines satisfying conditions | | result[n].key | primary key | | result[n].value | value |

params [object]

| key | desc | default | | --- | --- | --- | | table | [string] storage table name | 'default' | | key | [array string] which fields are returned | []: return all fields | | where | [object] conditions for select, key value pair; use $key as key to select primary key | null | | order | [object] depend on certain columns for sorting, the value can be desc or asc | null | | limit | [object] | null | | limit.start | [number] limit which line to start returning | 0 | | limit.size | [number] limit number of returns | null : return all lines |

demo

const list = await apdb.select({
  where: {
    $key: /8/
  },
  order: {
    num: 'desc'
  },
  limit: {
    size: 5
  }
});

5. Update

const result = await apdb.update( params );

result [number]

result is the amount of updated lines

params [object]

| key | desc | default | | --- | --- | --- | | table | [string] storage table name | 'default' | | where | [object] conditions for update, key value pair; use $key as key to select primary key | null | | value | [object] new value | {} | | newValue | [boolean] if ture, the original value columns will be discarded | false |

demo

const updateCount = await apdb.update({
    where: {
      num: 302910
    },
    value: { 
      up: 'test new value'
    },
});
  

6. Delete

const result = await apdb.delete( params );

result [number]

result is the amount of deleted lines

params [object]

| key | desc | default | | --- | --- | --- | | table | [string] storage table name | 'default' | | where | [object] conditions for delete, key value pair; use $key as key to select primary key | null |

demo

const deleteCount = await apdb.delete({
    where: {
      num: 302909
    }
});

Performance

Node environment

| type | amount(lines) | operate | time usage(ms) | space usage(MB) | | --- | --- | --- | --- | --- | | json | 1,000,000 | init | 2000 | - | | json | 1,000,000 | insert | 14451 | 130.8 | | msgpack | 1,000,000 | init | 7281 | - | | msgpack | 1,000,000 | insert | 16288 | 100.7 | | - all | 1,000,000 | order desc | 1729 | | | - all | 1,000,000 | order asc | 1746 | | | - all | 1,000,000 | select where normal | 103 | | | - all | 1,000,000 | select where regexp | 7197 | |

Each line format

{
  key: "1545802142928test13",
  value: {
    "num":302910,
    "key":"1545801896834test302910"
  }
}