db.uts 954 字节
Newer Older
M
mehaotian 已提交
1
const APPID = uni.getSystemInfoSync().appId
M
mehaotian 已提交
2 3 4 5 6
export function dbSet<T>(name : string, value : T) {
	let data = uni.getStorageSync('$$STAT__DBDATA:' + APPID)
	let newData = {} as UTSJSONObject
	if (data != null && typeof data == 'object') {
		newData = data as UTSJSONObject
M
mehaotian 已提交
7 8 9
	}
	newData[name] = value
	uni.setStorageSync('$$STAT__DBDATA:' + APPID, newData)
M
mehaotian 已提交
10 11 12 13 14 15
}

export function dbGet<T>(name : string) : T | null {
	let data = uni.getStorageSync('$$STAT__DBDATA:' + APPID)
	if (data == null) return null
	if (typeof data != 'object') return null
M
mehaotian 已提交
16
	const newData = data as UTSJSONObject
M
mehaotian 已提交
17 18 19 20 21
	return newData[name] as T
}

export function dbRemove(name : string) {
	let data = uni.getStorageSync('$$STAT__DBDATA:' + APPID)
M
mehaotian 已提交
22 23 24
	if (data == '') {
		data = {}
	}
M
mehaotian 已提交
25 26 27 28 29 30 31 32
	if (data != null) {
		let newData = data as UTSJSONObject
		if (newData[name] != null) {
			newData[name] = null
			uni.setStorageSync('$$STAT__DBDATA:' + APPID, newData)
		}
	}
}