Code Monkey home page Code Monkey logo

xdb's Introduction

xdb

基于indexedDB API二次封装的支持过期时间,且采用promise封装的存储库

使用

1.初始化数据库

// 连接indexedDB数据库并创建表
var tableName = 'cacheTable'
window.db = xdb.loadDB({ 
  name: 'cacheDB',
  onUpdate(e) {
    console.log('update', e)
    db.createTable(tableName, { keyPath: 'path'})
  },
  onSuccess(e) {
    console.log('success', e)
  }
})

2.获取表中的数据

db.get(tableName, 'keypath').then(res => {})
// 或者在async函数中
const res = await db.get(tableName, 'keypath')

3.添加table行数据

// 第三个参数为过期时间
db.add(tableName, data, 24 * 60 * 60 * 1000)

4. 删除数据

db.del(tableName, keyVal)

5. 清空table

db.clear()

6.更新行

db.update(tableName, data)

更多产品推荐 | More Production

name Description
H5-Dooring 让 H5 制作像搭积木一样简单, 轻松搭建 H5 页面, H5 网站, PC 端网站, LowCode 平台.
V6.Dooring 可视化大屏解决方案, 提供一套可视化编辑引擎, 助力个人或企业轻松定制自己的可视化大屏应用.
dooring-electron-lowcode 基于 electron 的 H5-Dooring 编辑器桌面端.
xijs 开箱即用的js业务工具库
DooringX 快速高效搭建可视化拖拽平台.

赞助 | Sponsored

开源不易, 有了您的赞助, 我们会做的更好~

技术反馈和交流群 | Technical feedback and communication

微信:beautifulFront

xdb's People

Contributors

mrxujiang avatar aleryxu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.