fix: db错误

This commit is contained in:
ningmengchongshui 2024-06-15 12:28:49 +08:00
parent b790a79f98
commit fc1020d310
5 changed files with 38 additions and 103 deletions

@ -0,0 +1 @@
Subproject commit 0a44a0f65aa24c5ca97c9a7af3ecf3f3676e990e

View File

@ -1,29 +1,17 @@
import { Sequelize, DataTypes, Model } from 'sequelize'
import { Data } from '../miao.js'
import { join } from 'path'
import { Data } from '#miao'
/**
*
*/
Data.createDir('/data/db', 'root')
/**
* DB自定义
*/
export const sequelize = new Sequelize({
// TODO DB自定义
const sequelize = new Sequelize({
dialect: 'sqlite',
storage: join(process.cwd(), '/data/db/data.db'),
storage: process.cwd() + '/data/db/data.db',
logging: false
})
/**
*
*/
await sequelize.authenticate()
/**
*
*/
export default class BaseModel extends Model {
static Types = DataTypes
@ -34,3 +22,4 @@ export default class BaseModel extends Model {
model.COLUMNS = columns
}
}
export { sequelize }

View File

@ -1,28 +1,26 @@
import BaseModel from './BaseModel.js'
import { DataTypes } from 'sequelize'
/**
*
*/
const { Types } = BaseModel
const COLUMNS = {
// 用户IDqq为数字
ltuid: {
type: DataTypes.INTEGER,
type: Types.INTEGER,
primaryKey: true
},
// MysUser类型mys / hoyolab
type: {
type: DataTypes.STRING,
type: Types.STRING,
defaultValue: 'mys',
notNull: true
},
// CK
ck: DataTypes.STRING,
device: DataTypes.STRING,
ck: Types.STRING,
device: Types.STRING,
uids: {
type: DataTypes.STRING,
type: Types.STRING,
get() {
let data = this.getDataValue('uids')
let ret = {}
@ -39,15 +37,7 @@ const COLUMNS = {
}
}
/**
*
*/
class MysUserDB extends BaseModel {
ck = null
type = null
device = null
uids = null
static async find(ltuid = '', create = false) {
// DB查询
let mys = await MysUserDB.findByPk(ltuid)
@ -59,6 +49,11 @@ class MysUserDB extends BaseModel {
return mys || false
}
ck = null
type = null
device = null
uids = null
async saveDB(mys) {
if (!mys.ck || !mys.device || !mys.db) {
return false
@ -72,17 +67,7 @@ class MysUserDB extends BaseModel {
}
}
/**
*
*/
BaseModel.initDB(MysUserDB, COLUMNS)
/**
*
*/
await MysUserDB.sync()
/**
*
*/
export default MysUserDB

View File

@ -1,34 +1,34 @@
import BaseModel from './BaseModel.js'
import lodash from 'lodash'
import { UserGameDB } from './index.js'
import MysUtil from '../mys/MysUtil.js'
import { DataTypes } from 'sequelize'
import MysUserDB from './MysUserDB.js'
const { Types } = BaseModel
/**
*
*/
const COLUMNS = {
// 用户IDqq为数字
id: {
type: DataTypes.STRING,
type: Types.STRING,
autoIncrement: false,
primaryKey: true
},
type: {
type: DataTypes.STRING,
type: Types.STRING,
defaultValue: 'qq',
notNull: true
},
// 昵称
name: DataTypes.STRING,
name: Types.STRING,
// 头像
face: DataTypes.STRING,
face: Types.STRING,
ltuids: DataTypes.STRING,
ltuids: Types.STRING,
games: {
type: DataTypes.STRING,
type: Types.STRING,
get() {
let data = this.getDataValue('games')
let ret = {}
@ -50,19 +50,10 @@ const COLUMNS = {
this.setDataValue('games', JSON.stringify(data))
}
},
data: DataTypes.STRING
data: Types.STRING
}
/**
*
*/
class UserDB extends BaseModel {
/**
*
* @param id
* @param type
* @returns
*/
static async find(id, type = 'qq') {
// user_id
id = type === 'qq' ? '' + id : type + id
@ -77,16 +68,9 @@ class UserDB extends BaseModel {
return user
}
games = null
ltuids = null
/**
*
* @param user
*/
async saveDB(user) {
const db = this
const ltuids = []
let db = this
let ltuids = []
lodash.forEach(user.mysUsers, mys => {
if (mys.ck && mys.ltuid) {
ltuids.push(mys.ltuid)
@ -111,17 +95,7 @@ class UserDB extends BaseModel {
}
}
/**
*
*/
BaseModel.initDB(UserDB, COLUMNS)
/**
*
*/
await UserDB.sync()
/**
*
*/
export default UserDB

View File

@ -1,18 +1,17 @@
import { DataTypes } from 'sequelize'
import BaseModel from './BaseModel.js'
import lodash from 'lodash'
/**
*
*/
const { Types } = BaseModel
const COLUMNS = {
// 用户IDqq为数字
userId: {
type: DataTypes.STRING
type: Types.STRING
},
game: DataTypes.STRING,
uid: DataTypes.STRING,
game: Types.STRING,
uid: Types.STRING,
data: {
type: DataTypes.STRING,
type: Types.STRING,
get() {
let data = this.getDataValue('data')
let ret = {}
@ -34,22 +33,9 @@ const COLUMNS = {
}
}
/**
*
*/
class UserGameDB extends BaseModel {}
/**
*
*/
BaseModel.initDB(UserGameDB, COLUMNS)
/**
*
*/
await UserGameDB.sync()
/**
*
*/
export default UserGameDB