Appearance
super-tools-lib - v1.74.0 / Modules / class / IndexedDB
Class: IndexedDB
class.IndexedDB
数据库
Since
1.62.0
Example
ts
import { IndexedDB } from 'super-tools-lib'
const db = new IndexedDB({dbName: '数据库名称', storeName: '容器名称', version: '1.0.0'})
// 设置数据
db.set('data', {value: '80'})
// 查询数据
db.get('data', (val) => {console.log(val)}) // {value: '80'}
// 更新数据,如果key值不存在则是添加
db.update('data', {value: 70})
// 删除数据
db.remove('data')
// 清空数据库
db.close()
Table of contents
Constructors
Properties
Methods
Constructors
constructor
• new IndexedDB(props
)
Parameters
Name | Type |
---|---|
props | IndexedDBProps |
Properties
db
• db: any
store
• store: any
storeName
• Private
storeName: string
Methods
close
▸ close(): void
清空数据库
Returns
void
get
▸ get(key
, callback
): void
获取数据库数据
Parameters
Name | Type | Description |
---|---|---|
key | string | 键 |
callback | (data : any ) => void | 回调函数 |
Returns
void
remove
▸ remove(key
): void
删除指定数据
Parameters
Name | Type |
---|---|
key | string |
Returns
void
set
▸ set(key
, value
): void
设置数据
Parameters
Name | Type | Description |
---|---|---|
key | string | 键 |
value | any | 值 |
Returns
void
update
▸ update(key
, newValue
): void
更新数据 (数据库中有key数据则更新,没有则添加)
Parameters
Name | Type | Description |
---|---|---|
key | string | 键 |
newValue | any | 值 |
Returns
void