import mysql from "mysql2/promise"; import * as sanitizeHtml from 'sanitize-html'; export const pool = mysql.createPool({ connectionLimit: 10, // 连接池允许的最大连接数 host: "sh-cdb-qlkmuvd2.sql.tencentcdb.com", port: 63982, user: "root", password: "cr654654.", database: "demo", waitForConnections: true, maxIdle: 10, // max idle connections, the default value is the same as `connectionLimit` idleTimeout: 60000, // idle connections timeout, in milliseconds, the default value 60000 queueLimit: 0, enableKeepAlive: true, keepAliveInitialDelay: 0, }); export const insert = async (pool, data) => { const { msg_content, user_id, user_nickName, user_avatar, user_gender, user_isAdmin, user_is_super_admin, user_level, user_fans_club_level, user_fans_club_name, user_follower_count, user_display_id, isGift, gift_id, gift_number, create_time, } = data; try { const [rows, fields] = await pool.execute( "INSERT INTO danmu(msg_content,user_id,user_nickName,user_avatar,user_gender,user_isAdmin,user_is_super_admin,user_level,user_fans_club_level,user_fans_club_name,user_follower_count,user_display_id,isGift,gift_id,gift_number,create_time) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", [ msg_content ?? "", user_id ?? "", user_nickName ?? "", user_avatar ?? "", user_gender ?? "", user_isAdmin ?? false, user_is_super_admin ?? false, user_level ?? "", user_fans_club_level ?? "", user_fans_club_name ?? "", user_follower_count ?? "", user_display_id ?? "", isGift ?? false, gift_id ?? "", gift_number ?? "", create_time ?? "", ] ); console.log("Insert successful:", rows); } catch (error) { console.error("Error in insertion:", error); } };