fix postgres error

This commit is contained in:
mtvpls
2026-02-08 01:18:14 +08:00
parent 1d3a7f2732
commit a2e07011ec
4 changed files with 195 additions and 597 deletions

View File

@@ -35,6 +35,7 @@
"@types/crypto-js": "^4.2.2",
"@types/nprogress": "^0.2.3",
"@upstash/redis": "^1.25.0",
"@vercel/postgres": "^0.10.0",
"@vidstack/react": "^1.12.13",
"anime4k-webgpu": "^1.0.0",
"artplayer": "^5.3.0",

771
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -30,7 +30,17 @@ async function init() {
try {
// 执行 schema 创建
console.log('🔧 Creating database schema...');
await sql.unsafe(schemaSql);
// 将 SQL 脚本按语句分割并逐个执行
const statements = schemaSql
.split(';')
.map(s => s.trim())
.filter(s => s.length > 0);
for (const statement of statements) {
await sql.query(statement);
}
console.log('✅ Database schema created successfully!');
// 创建默认管理员用户

View File

@@ -77,8 +77,8 @@ class PostgresPreparedStatement implements D1PreparedStatement {
try {
const convertedQuery = this.convertQuery(this.query);
// 使用 Vercel Postgres 的 unsafe 方法执行参数化查询
const result = await sql.unsafe(convertedQuery, this.params);
// 使用 Vercel Postgres 的 query 方法执行参数化查询
const result = await sql.query(convertedQuery, this.params);
if (!result || result.rows.length === 0) return null;
@@ -100,7 +100,7 @@ class PostgresPreparedStatement implements D1PreparedStatement {
try {
const convertedQuery = this.convertQuery(this.query);
const result = await sql.unsafe(convertedQuery, this.params);
const result = await sql.query(convertedQuery, this.params);
return {
success: true,
@@ -126,7 +126,7 @@ class PostgresPreparedStatement implements D1PreparedStatement {
try {
const convertedQuery = this.convertQuery(this.query);
const result = await sql.unsafe(convertedQuery, this.params);
const result = await sql.query(convertedQuery, this.params);
return {
success: true,