Socket
Socket
Sign inDemoInstall

apdb

Package Overview
Dependencies
1
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

apdb


Version published
Weekly downloads
0
Maintainers
1
Install size
963 kB
Created
Weekly downloads
 

Readme

Source

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]
keydescdefault
table[string] storage table name'default'

3. Insert

const result = await apdb.insert( params );
result [boolean]

if insert successful, result is true

params [object]
keydescdefault
key[string] primary keyDate.now() + Math.random()
value[object] valuenull
update[boolean] update current tree to storage, improve multi-line insert performancetrue
demo
await apdb.insert({
  key: 'apdb key', 
  value: {
    name: 'apdb',
    author: 'echosoar'
  }
});

4. Select

const result = await apdb.select( params );
result [object]
keydesc
total[number] Total number of data
result[array] all lines satisfying conditions
result[n].keyprimary key
result[n].valuevalue
params [object]
keydescdefault
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 keynull
order[object] depend on certain columns for sorting, the value can be desc or ascnull
limit[object]null
limit.start[number] limit which line to start returning0
limit.size[number] limit number of returnsnull : 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]
keydescdefault
table[string] storage table name'default'
where[object] conditions for update, key value pair; use $key as key to select primary keynull
value[object] new value{}
newValue[boolean] if ture, the original value columns will be discardedfalse
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]
keydescdefault
table[string] storage table name'default'
where[object] conditions for delete, key value pair; use $key as key to select primary keynull
demo
const deleteCount = await apdb.delete({
    where: {
      num: 302909
    }
});

Performance

Node environment
typeamount(lines)operatetime usage(ms)space usage(MB)
json1,000,000init2000-
json1,000,000insert14451130.8
msgpack1,000,000init7281-
msgpack1,000,000insert16288100.7
- all1,000,000order desc1729
- all1,000,000order asc1746
- all1,000,000select where normal103
- all1,000,000select where regexp7197
Each line format
{
  key: "1545802142928test13",
  value: {
    "num":302910,
    "key":"1545801896834test302910"
  }
}

Keywords

FAQs

Last updated on 30 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc