refactor: @ocas/fs var/tag 存储从 JSONL 迁移到 better-sqlite3 #59

Closed
opened 2026-06-03 01:29:50 +00:00 by xiaoju · 1 comment
Owner

背景

当前 @ocas/fs 的 var 和 tag 存储使用 JSONL 文件 + 内存 Map:

  • 启动时全量 parse JSONL 到内存
  • 删除/更新靠 append 标记,文件只增不减
  • list/filter 全是遍历 Map,无索引
  • 数据量大时启动慢、内存占用高

目标

迁移到 better-sqlite3

  1. var store: _vars.jsonl → SQLite 表
  2. tag store: _tags.jsonl → SQLite 表
  3. 按需查询,不全量加载
  4. 索引支持高效 filter/sort/pagination
  5. 保持 Store 接口不变

注意

  • @ocas/core 保持零 SQLite 依赖(已有测试守护)
  • better-sqlite3 作为 @ocas/fs 的 dependency
  • 数据库文件放 store 目录下(如 _meta.db
  • 旧 JSONL 文件可做一次性迁移后删除

小橘 🍊(NEKO Team)

## 背景 当前 `@ocas/fs` 的 var 和 tag 存储使用 JSONL 文件 + 内存 Map: - 启动时全量 parse JSONL 到内存 - 删除/更新靠 append 标记,文件只增不减 - list/filter 全是遍历 Map,无索引 - 数据量大时启动慢、内存占用高 ## 目标 迁移到 `better-sqlite3`: 1. var store: `_vars.jsonl` → SQLite 表 2. tag store: `_tags.jsonl` → SQLite 表 3. 按需查询,不全量加载 4. 索引支持高效 filter/sort/pagination 5. 保持 Store 接口不变 ## 注意 - `@ocas/core` 保持零 SQLite 依赖(已有测试守护) - `better-sqlite3` 作为 `@ocas/fs` 的 dependency - 数据库文件放 store 目录下(如 `_meta.db`) - 旧 JSONL 文件可做一次性迁移后删除 --- 小橘 🍊(NEKO Team)
Author
Owner

\u5df2\u5b8c\u6210\uff1a@ocas/fs \u5df2\u8fc1\u79fb\u5230 node:sqlite\uff08createSqliteVarStore\uff09\uff0cvar \u548c tag \u90fd\u8d70 SQLite\u3002\u65e7 JSONL \u6709\u4e00\u6b21\u6027\u8fc1\u79fb\u903b\u8f91\u3002 \u2014\u2014 \u5c0f\u6a58

\u5df2\u5b8c\u6210\uff1a@ocas/fs \u5df2\u8fc1\u79fb\u5230 node:sqlite\uff08createSqliteVarStore\uff09\uff0cvar \u548c tag \u90fd\u8d70 SQLite\u3002\u65e7 JSONL \u6709\u4e00\u6b21\u6027\u8fc1\u79fb\u903b\u8f91\u3002 \u2014\u2014 \u5c0f\u6a58
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shazhou/ocas#59