db update

Former-commit-id: 3efab3f3c7cf7a34d78ebc1aebcf895fe1832970 [formerly 3efab3f3c7cf7a34d78ebc1aebcf895fe1832970 [formerly 3efab3f3c7cf7a34d78ebc1aebcf895fe1832970 [formerly 3efab3f3c7cf7a34d78ebc1aebcf895fe1832970 [formerly 3608951ec0d14f5fdda5f5c3d74ca1658b4c220a [formerly b3ea1a90fb68b439126a0e163a017e242a0a8dbd]]]]]
Former-commit-id: 452ee4fcd7e53cad75c82f54925db50caf4da311
Former-commit-id: a6b77ca047f33d44ec3cc9c7311ad85fda1cbdaf
Former-commit-id: 625313ff14d3e4a6c4496e0dbbc5d1e2e4624543 [formerly 7b93944ff7f9803377076bd9312f11c82ad60ddd]
Former-commit-id: dab47fcc9792a84172a95410cf8359e31c7c08de
Former-commit-id: e341761c086bb8eb5d842abf411189ec35699361
Former-commit-id: 2bada492361b11dc9e7c5e2eff0baaad7a1aa822
Former-commit-id: 66175c2c3ac72e9b31a66021d4d208c76348e70a
Former-commit-id: b6844ade3e3cdfabb5e58010df6ad0ffa2b2da97
This commit is contained in:
liyang
2018-08-11 22:16:16 +08:00
parent 33f547b42b
commit e5d8d022f0
7 changed files with 324 additions and 124 deletions

View File

@@ -17,16 +17,15 @@ function pathInit ({
validator = () => true,
defaultValue = ''
}) {
const sys = db.get(dbName)
const uuid = util.cookies.get('uuid') || 'ghost-uuid'
const currentPath = `${user ? `user.${uuid}` : 'public'}.${path}`
const value = sys.get(currentPath).value()
const currentPath = `${dbName}.${user ? `user.${uuid}` : 'public'}${path ? `.${path}` : ''}`
const value = db.get(currentPath).value()
if (!(value && validator(value))) {
sys
db
.set(currentPath, defaultValue)
.write()
}
return `${dbName}.${currentPath}`
return currentPath
}
export default {
@@ -71,6 +70,56 @@ export default {
}
},
actions: {
/**
* @description 获取存储数据库对象
*/
database () {
return new Promise(resolve => {
resolve(db.get(pathInit({
dbName: 'database',
user: false,
defaultValue: {}
})))
})
},
/**
* @description 清空存储数据库对象
*/
databaseClear () {
return new Promise(resolve => {
resolve(db.get(pathInit({
dbName: 'database',
user: false,
validator: () => false,
defaultValue: {}
})))
})
},
/**
* @description 获取存储数据库对象 [区分用户]
*/
databaseByUser () {
return new Promise(resolve => {
resolve(db.get(pathInit({
dbName: 'database',
user: true,
defaultValue: {}
})))
})
},
/**
* @description 清空存储数据库对象 [区分用户]
*/
databaseByUserClear () {
return new Promise(resolve => {
resolve(db.get(pathInit({
dbName: 'database',
user: true,
validator: () => false,
defaultValue: {}
})))
})
},
/**
* @description 获取数据
* @description 效果类似于 dbName.path || defaultValue
@@ -84,7 +133,7 @@ export default {
path = '',
defaultValue = ''
}) {
return new Promise((resolve, reject) => {
return new Promise(resolve => {
resolve(db.get(pathInit({
dbName,
path,