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

@goldnet/localdb

v1.0.4

Published

不限制大小的本地存储库

Downloads

23

Readme

localdb

不限制大小的本地存储库

支持类型

number, string, json, blob, arraybuffer

安装

 npm i @goldnet/localdb

导入

import { LocalDB } from ' @goldnet/localdb';

示例

// 建立全局的存储库
const localDB = getLocalDB();

await localDB.open(1);

async function load() {
    // 相关模块使用
    const key = 'key1';
    let data = await localDB.get(key);

    if (!data) {
        console.log('存储');
        const res = await fetch('/colors.png', {
            "headers": {
                responseType: 'arraybuffer'
            }
        });
        const arraybuffer = await res.arrayBuffer();
        await localDB.put({ md5: '1', data: arraybuffer }, key);
    } else {
        console.log('读取');
        data = data.data;
    }

    console.log(data);
}

load();

API

快速创建

const localDB = getLocalDB();

实例创建

const localDB = new LocalDB(dbname);

需要添加数据库名,自定义 需要添加表明,自定义 版本号,默认1, 如果修改表或数据结构,版本号必须递增 在调用open方法之前,需要配置结构

    localDB.configStoreObject([
        {
            name: tableName,
            options: {
                autoIncrement: true
            }
        }
    ]);

打开数据库

await localDB.open(version);

version 如果不传,默认版本号为1.

更新/添加数据

const result = await localDB.put(value,id);

value 要存储的数据,可以是 number, string, json, blob, arraybuffer id,用于查找的键值,如果没传入,会返回递增键值, 如果传入一个已经存在的,会更新数据 result 如果为 undefined, 数据库可能关闭、写入失败

获取

const result = await localDB.get(id);

获取版本

const result = await localDB.version();

只有版本变更才会更新 localDB.configStoreObject 中的数据结构,在每次版本变更需要考虑之前的结构,或调用删除方法

删除

const result = await localDB.delete(id);

如果没有返回值,删除成功

清除所有

await localDB.clear();