Skip to content

Instantly share code, notes, and snippets.

@wewindy
Last active May 24, 2021 01:28
Show Gist options
  • Save wewindy/098f967b88540552cf8428c961024b59 to your computer and use it in GitHub Desktop.
Save wewindy/098f967b88540552cf8428c961024b59 to your computer and use it in GitHub Desktop.
localForage-demo
import localForage from 'localforage'
// 创建仓库对象,并创建名为 “test” 的 indexeddb 以及 名为 “testidb” 的表
const store = localForage.createInstance({
driver: localForage.INDEXEDDB,
name: "test",
storeName: "testidb"
})
// 设置 key-value
store.setItem("t1", new Float32Array([113.24, 44.55, 12.512]))
// 5 秒后删除 “test” 数据库的 “testidb” 这个表
setTimeout(() => {
localForage.dropInstance({
name: "test",
storeName: "testidb"
})
}, 5000)
@wewindy
Copy link
Author

wewindy commented Apr 22, 2021

name: indexeddb 数据库名
storeName: 表名,因为 indexeddb 是 nosql 数据库,所以也可以将表叫做 “文档”

数据库与文档是一对多的关系

@wewindy
Copy link
Author

wewindy commented Apr 22, 2021

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment