继续完善保险项目和养殖端小程序
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
{
|
||||
"development": {
|
||||
"username": "root",
|
||||
"password": "aiotAiot123!",
|
||||
"database": "insurance_data",
|
||||
"host": "129.211.213.226",
|
||||
"port": 9527,
|
||||
"dialect": "mysql",
|
||||
"timezone": "+08:00",
|
||||
"dialectOptions": {
|
||||
"dateStrings": true,
|
||||
"typeCast": true
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"username": "root",
|
||||
"password": "aiotAiot123!",
|
||||
"database": "insurance_data_test",
|
||||
"host": "129.211.213.226",
|
||||
"port": 9527,
|
||||
"dialect": "mysql",
|
||||
"timezone": "+08:00"
|
||||
},
|
||||
"production": {
|
||||
"username": "root",
|
||||
"password": "aiotAiot123!",
|
||||
"database": "insurance_data_prod",
|
||||
"host": "129.211.213.226",
|
||||
"port": 9527,
|
||||
"dialect": "mysql",
|
||||
"timezone": "+08:00"
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
const { Sequelize } = require('sequelize');
|
||||
require('dotenv').config();
|
||||
|
||||
// 创建Sequelize实例
|
||||
const sequelize = new Sequelize({
|
||||
dialect: process.env.DB_DIALECT || 'mysql',
|
||||
host: process.env.DB_HOST || '129.211.213.226',
|
||||
port: process.env.DB_PORT || 9527,
|
||||
database: process.env.DB_DATABASE || 'insurance_data',
|
||||
username: process.env.DB_USER || 'root',
|
||||
password: process.env.DB_PASSWORD || 'aiotAiot123!',
|
||||
logging: process.env.NODE_ENV === 'development' ? console.log : false,
|
||||
pool: {
|
||||
max: 10,
|
||||
min: 0,
|
||||
acquire: 30000,
|
||||
idle: 10000
|
||||
},
|
||||
define: {
|
||||
timestamps: true,
|
||||
underscored: true,
|
||||
charset: 'utf8mb4',
|
||||
collate: 'utf8mb4_unicode_ci'
|
||||
},
|
||||
dialectOptions: {
|
||||
// 解决MySQL严格模式问题
|
||||
dateStrings: true,
|
||||
typeCast: true,
|
||||
// 允许0000-00-00日期值
|
||||
connectAttributes: {
|
||||
sql_mode: 'TRADITIONAL'
|
||||
}
|
||||
},
|
||||
timezone: '+08:00' // 设置时区为东八区
|
||||
});
|
||||
|
||||
// 测试数据库连接
|
||||
const testConnection = async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('✅ 数据库连接成功');
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('❌ 数据库连接失败:', error.message);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { sequelize, testConnection };
|
||||
@@ -1,42 +0,0 @@
|
||||
const redis = require('redis');
|
||||
require('dotenv').config();
|
||||
|
||||
// 创建Redis客户端
|
||||
const createRedisClient = () => {
|
||||
const client = redis.createClient({
|
||||
socket: {
|
||||
host: process.env.REDIS_HOST || 'localhost',
|
||||
port: process.env.REDIS_PORT || 6379
|
||||
},
|
||||
password: process.env.REDIS_PASSWORD || '',
|
||||
legacyMode: false
|
||||
});
|
||||
|
||||
// 错误处理
|
||||
client.on('error', (err) => {
|
||||
console.error('❌ Redis连接错误:', err);
|
||||
});
|
||||
|
||||
// 连接成功
|
||||
client.on('connect', () => {
|
||||
console.log('✅ Redis连接成功');
|
||||
});
|
||||
|
||||
return client;
|
||||
};
|
||||
|
||||
// 创建并连接Redis客户端
|
||||
const redisClient = createRedisClient();
|
||||
|
||||
// 连接Redis
|
||||
const connectRedis = async () => {
|
||||
try {
|
||||
await redisClient.connect();
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('❌ Redis连接失败:', error.message);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { redisClient, connectRedis };
|
||||
Reference in New Issue
Block a user