From 99b70a07a6260daea0ffbd0cd0dde776e071f05e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=BB=AB?= <486494914@qq.com> Date: Mon, 19 Oct 2026 15:33:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=86=85=E5=AE=B9=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E5=8F=91=E5=B8=83=E5=88=B0=20AI=20=E5=AE=98=E7=BD=91?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=EF=BC=9AMySQL=20=E4=B8=A5=E6=A0=BC=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8D=E6=8E=A5=E5=8F=97=E5=B8=A6=E6=97=B6=E5=8C=BA?= =?UTF-8?q?=E7=9A=84=20ISO=20=E6=97=B6=E9=97=B4=EF=BC=88=E5=A6=82=202026-1?= =?UTF-8?q?0-19T06:55:53.409Z=EF=BC=89=EF=BC=8C=E5=86=99=E5=BA=93=E5=89=8D?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E8=BD=AC=E6=88=90=E6=9C=AC=E5=9C=B0=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- src/config/database.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/config/database.js b/src/config/database.js index a04b941..3c11106 100644 --- a/src/config/database.js +++ b/src/config/database.js @@ -5,6 +5,19 @@ let db; const requiredConfig = ['DB_HOST', 'DB_PORT', 'DB_NAME', 'DB_USER', 'DB_PASSWORD']; +// MySQL (strict mode) rejects ISO date strings with a time zone, e.g. "2026-10-19T06:55:53.409Z", in DATETIME +// columns. The models and the content ingest service write such strings, so they are turned into plain local +// date-times here. The server and MySQL both run on China time, which is how the existing rows are stored. +const ISO_DATETIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/; +const pad = (value) => String(value).padStart(2, '0'); +const toMySqlParam = (value) => { + if (typeof value !== 'string' || !ISO_DATETIME.test(value)) return value; + const date = new Date(value); + if (Number.isNaN(date.getTime())) return value; + return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` + + `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`; +}; + class MySqlStatement { constructor(connection, sql) { this.connection = connection; @@ -12,7 +25,7 @@ class MySqlStatement { } all(...params) { - const result = this.connection.query(this.sql, params); + const result = this.connection.query(this.sql, params.map(toMySqlParam)); return Array.isArray(result) ? result : []; } @@ -22,7 +35,7 @@ class MySqlStatement { } run(...params) { - const result = this.connection.query(this.sql, params) || {}; + const result = this.connection.query(this.sql, params.map(toMySqlParam)) || {}; return { changes: result.affectedRows || 0, lastInsertRowid: result.insertId || 0, @@ -83,4 +96,4 @@ const closeDb = () => { } }; -module.exports = { getDb, closeDb }; +module.exports = { getDb, closeDb, toMySqlParam };