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

arraystorage

v1.0.5

Published

a simple helper for use indexeddb easily just like Array

Downloads

3

Readme

ArrayStorage

ArrayStorage 是一个基于ES6 Promise的对 indexeddb 封装的使用非常简单的库

ArrayStorage 使用精简的API,就像 JavaScript 的 Array


预览: crud在线demo


获取:

方式一: 使用NPM

$ npm i arraystorage
import ArrayStorage from 'arraystorage';

const store = new ArrayStorage();
store.getAll().then(() => console.log('数据库已加载'))

方式二: 直接使用 html 标签

<script src="https://github.com/zaqmjuop/arraystorage/blob/master/docs/arraystorage.js"></script>
<script>
  const store = new ArrayStorage();
  store.getAll().then(() => console.log('数据库已加载'))
</script>

API

创建对象

import ArrayStorage from 'arraystorage';

const store = new ArrayStorage();

新增数据

push(data)

push([data])

store.push({name: 'name1'}).then(primaryKeys => primaryKeys) // [1]
store.push([{name: 'name2'}, {name: 'name3'}]).then(primaryKeys => primaryKeys) // [2, 3]
// primaryKeys 是新增数据的主键属性 primaryKey 的集合
// primaryKey 是Integer主键,新增数据自动分配一个主键,可以使用主键对数据进行查询,修改,或删除

使用 primaryKey 查询数据

get(primaryKey)

get([primaryKey])

store.get(1).then(primaryKeys => primaryKeys) 
// [{name: 'name1', primaryKey: 1}]
store.get([2, 3]).then(primaryKeys => primaryKeys) 
// [{name: 'name2', primaryKey: 2}, {name: 'name3', primaryKey: 3}]

条件查询数据

find(callback) // 单数查询

filter(callback) // 复数查询

getAll() // 获取全部数据

store.find(item => item.primaryKey > 1).then(data => data) 
// {name: 'name2', primaryKey: 2}
store.filter(item => item.primaryKey > 1).then(datas => datas) 
// [{name: 'name2', primaryKey: 2}, {name: 'name3', primaryKey: 3}]
store.getAll().then(datas => datas) 
// [{name: 'name1', primaryKey: 1}, {name: 'name2', primaryKey: 2}, {name: 'name3', primaryKey: 3}]

遍历数据并获取副本

map(callback)

store.map(item => (item.primaryKey * 2)).then(datas => datas)
// [2, 4, 6]

更新数据

update(data)

update([data])

store.update({primaryKey: 1, name: 'name11'}).then(primaryKeys => primaryKeys) // [1]
store.update([{primaryKey: 2, name: 'name22'}, {primaryKey: 3, name: 'name33'}])
  .then(primaryKeys => primaryKeys) // [2, 3]

删除数据

remove(primaryKey)

remove([primaryKey])

store.remove(1).then(primaryKeys => primaryKeys) // [1]
store.remove([2, 3]).then(primaryKeys => primaryKeys) // [2, 3]