Miao-Yunzai/plugins/genshin/model/db/UserGameDB.js

43 lines
782 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import BaseModel from './BaseModel.js'
import lodash from 'lodash'
const { Types } = BaseModel
const COLUMNS = {
// 用户IDqq为数字
userId: {
type: Types.STRING
},
game: Types.STRING,
uid: Types.STRING,
data: {
type: Types.STRING,
get () {
let data = this.getDataValue('data')
let ret = {}
try {
data = JSON.parse(data)
} catch (e) {
data = []
}
lodash.forEach(data, (ds) => {
if (ds.uid) {
ret[ds.uid] = ds
}
})
return ret
},
set (data) {
this.setDataValue('data', JSON.stringify(lodash.values(data)))
}
}
}
class UserGameDB extends BaseModel {
}
BaseModel.initDB(UserGameDB, COLUMNS)
await UserGameDB.sync()
export default UserGameDB