fix(数据库): 将时间戳字段从TEXT类型改为INTEGER类型

修改page_visit_daily表的created_at和updated_at字段类型,从TEXT改为INTEGER
同时更新相关插入和更新操作,使用时间戳而非ISO格式字符串
This commit is contained in:
anghunk
2026-01-22 10:44:23 +08:00
parent 17c31d7a1b
commit 0a7dca07ed
3 changed files with 5 additions and 5 deletions

View File

@@ -52,7 +52,7 @@ export const getVisitOverview = async (
).run();
await c.env.CWD_DB.prepare(
'CREATE TABLE IF NOT EXISTS page_visit_daily (id INTEGER PRIMARY KEY AUTOINCREMENT, date TEXT NOT NULL, domain TEXT, count INTEGER NOT NULL DEFAULT 0, created_at TEXT NOT NULL, updated_at TEXT NOT NULL)'
'CREATE TABLE IF NOT EXISTS page_visit_daily (id INTEGER PRIMARY KEY AUTOINCREMENT, date TEXT NOT NULL, domain TEXT, count INTEGER NOT NULL DEFAULT 0, created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL)'
).run();
const { results } = await c.env.CWD_DB.prepare(

View File

@@ -43,7 +43,7 @@ export const trackVisit = async (c: Context<{ Bindings: Bindings }>) => {
).run();
await c.env.CWD_DB.prepare(
'CREATE TABLE IF NOT EXISTS page_visit_daily (id INTEGER PRIMARY KEY AUTOINCREMENT, date TEXT NOT NULL, domain TEXT, count INTEGER NOT NULL DEFAULT 0, created_at TEXT NOT NULL, updated_at TEXT NOT NULL)'
'CREATE TABLE IF NOT EXISTS page_visit_daily (id INTEGER PRIMARY KEY AUTOINCREMENT, date TEXT NOT NULL, domain TEXT, count INTEGER NOT NULL DEFAULT 0, created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL)'
).run();
const nowDate = new Date();
@@ -117,14 +117,14 @@ export const trackVisit = async (c: Context<{ Bindings: Bindings }>) => {
await c.env.CWD_DB.prepare(
'INSERT INTO page_visit_daily (date, domain, count, created_at, updated_at) VALUES (?, ?, ?, ?, ?)'
)
.bind(today, domain, 1, nowIso, nowIso)
.bind(today, domain, 1, nowTs, nowTs)
.run();
} else {
const newCount = (dailyRow.count || 0) + 1;
await c.env.CWD_DB.prepare(
'UPDATE page_visit_daily SET count = ?, updated_at = ? WHERE id = ?'
)
.bind(newCount, nowIso, dailyRow.id)
.bind(newCount, nowTs, dailyRow.id)
.run();
}

View File

@@ -1,4 +1,4 @@
# 公开 API
# 公开 API 相关
无需认证即可访问的公开接口,包括评论获取、评论提交、配置获取和身份验证。