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

57 lines
979 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'
const { Types } = BaseModel
const COLUMNS = {
// 用户IDqq为数字
ltuid: {
type: Types.INTEGER,
primaryKey: true
},
// MysUser类型mys / hoyolab
type: {
type: Types.STRING,
defaultValue: 'mys',
notNull: true
},
// CK
ck: Types.STRING,
device: Types.STRING,
gsUids: Types.STRING,
srUids: Types.STRING
}
class MysUserDB extends BaseModel {
static async find (ltuid = '', create = false) {
// DB查询
let mys = await MysUserDB.findByPk(ltuid)
if (!mys && create) {
mys = await MysUserDB.build({
ltuid
})
}
return mys || false
}
static async findByCK (ck = '') {
let ltuid = 0
let mys = await MysUserDB.find(ltuid)
if (!mys) {
mys = await MysUserDB.build({
ltuid,
ck
})
}
return mys._cacheThis()
}
}
BaseModel.initDB(MysUserDB, COLUMNS)
await MysUserDB.sync()
export default MysUserDB