fix: profile_upsert payload binding

This commit is contained in:
root
2026-10-17 12:05:56 +08:00
parent 7331111379
commit 500d59ba58
4 changed files with 61 additions and 0 deletions
+9
View File
@@ -203,6 +203,15 @@ CREATE TRIGGER IF NOT EXISTS footprint_au AFTER UPDATE OF search_text ON footpri
END;
CREATE INDEX IF NOT EXISTS idx_footprint_start ON footprint(start_date);
CREATE TABLE IF NOT EXISTS profile (
id INTEGER PRIMARY KEY AUTOINCREMENT,
uuid TEXT,
content TEXT NOT NULL DEFAULT '{}',
deleted_at TEXT,
origin TEXT,
hlc TEXT
);
CREATE INDEX IF NOT EXISTS idx_footprint_type ON footprint(type_id);
CREATE INDEX IF NOT EXISTS idx_footprint_group ON footprint(group_id);
CREATE INDEX IF NOT EXISTS idx_footprint_hlc ON footprint(hlc);
+28
View File
@@ -1107,6 +1107,34 @@ function listFootprints(d, query) {
return { ok: true };
}
case 'profile_get': {
// 个人信息(单行 JSON):供个人信息页与简历生成使用
const row = d.prepare('SELECT * FROM profile WHERE deleted_at IS NULL ORDER BY id DESC LIMIT 1').get();
let content = {};
if (row) { try { content = JSON.parse(row.content || '{}'); } catch { content = {}; } }
return { content };
}
case 'profile_upsert': {
const p = payload;
// 单行语义:更新现有行或插入首行
const content = JSON.stringify(p.content ?? {});
const existing = d.prepare('SELECT * FROM profile WHERE deleted_at IS NULL ORDER BY id DESC LIMIT 1').get();
withTx(d, () => {
const h = hlcNext(d);
if (existing) {
d.prepare('UPDATE profile SET content=?, hlc=? WHERE id=?').run(content, h, existing.id);
touchOplog(d, 'profile', existing.uuid, 'upsert', h);
} else {
const uuid = uuidv7();
d.prepare('INSERT INTO profile (content, uuid, hlc, origin) VALUES (?,?,?,?)')
.run(content, uuid, h, getDeviceId(d));
touchOplog(d, 'profile', uuid, 'upsert', h);
}
});
return { ok: true };
}
case 'view_list':
return { items: d.prepare('SELECT * FROM saved_view WHERE deleted_at IS NULL ORDER BY id').all().map(v => ({
...v, filter: JSON.parse(v.filter || '{}'), sort: JSON.parse(v.sort || '{}'), is_default: !!v.is_default