1.3.0 • Published 1 year ago

localstoredb v1.3.0

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

引入

import LocalStore from 'localstoredb';

API

  • 可以使用其中任意储存方式:'indexedDB', 'webSql', 'storage', 'miniprogram', 'cookies', 'jsonStorage'
  • 支持小程序:storeType: 'miniprogram',storageType: 'wechat' | 'alipay' | 'toutiao'| 'baidu',其他小程序后续支持

配置参数:

let options = {
  storeType: ['storage', 'indexedDB', 'cookies'], // 储存类型, 可以配置多个,如果浏览器不支持,则向下使用
  dbName: 'localStore', // 数据库名
  expire: 0, // 过期时间,0 不过期,单位ms
  /*
   * storage 下有效,默认local, 可选值:'local' | 'session';
   * miniprogram 下有可选值:'wechat'(微信) | 'alipay'(支付宝)| 'toutiao'(头条抖音小程序)| 'baidu'(百度小程序);
   */
  storageType: 'local', 
  size: 5242880 // webSql下数据库大小设置,单位kb
};
const localStore = LocalStore(options);

调用方法: 类似于storage方法, 返回一个Promise

// 获取数据, key: string, 
// jsonStorage类型下有callback参数;数据变化时触发;callback(newVal, oldVal): function
await localStore.getItem(key, callback?); 

// 储存数据, key: string, value: any
await localStore.setItem(key, value);

await localStore.setItem({key: value, key: value});

// 删除数据,key: string | string[]
await localStore.removeItem(key);

// 删除全部数据
await localStore.removeAll();

// 查询全部数据key值
await localStore.getKeys();

// 查询全部数据
await localStore.getAll();
1.2.0

1 year ago

1.2.8

1 year ago

1.1.9

1 year ago

1.2.7

1 year ago

1.1.8

1 year ago

1.2.6

1 year ago

1.1.7

1 year ago

1.2.5

1 year ago

1.1.6

1 year ago

1.2.4

1 year ago

1.1.5

1 year ago

1.2.3

1 year ago

1.1.4

1 year ago

1.3.0

1 year ago

1.2.1

1 year ago

1.2.9

1 year ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago