Documentation
¶
Overview ¶
Package sqlite 提供 SQLite 持久化后端 + FTS5 索引(任务 S03)。
对齐上游:packages/storage/sqlite-session
设计要点:
- 单 DB:一张 `session_events` 普通表存全部事件的 JSON 载荷(BLOB),并以 (session_id, seq) 为主键;
- 同库一张 FTS5 虚拟表 `session_events_fts` 索引每条的搜索文本,用于标题/消息 内容的全文检索(S04 的 Session Query 底层依托于此);
- 追加(Append)与批量追加(AppendBatch)均走事务,原子写入:普通行与 FTS 行要么一起提交要么一起回滚,保证索引与正文一致性;
- 从事件 Data 的派生文本可索引:user/assistant 消息取 Content,session/title 取 Title,其余类型为空。
Index ¶
- type Match
- type Store
- func (s *Store) Append(ctx context.Context, sessionID brand.SessionID, ev session.SessionEvent) error
- func (s *Store) AppendBatch(ctx context.Context, sessionID brand.SessionID, events []session.SessionEvent) error
- func (s *Store) Close() error
- func (s *Store) Count(ctx context.Context, sessionID brand.SessionID) (int, error)
- func (s *Store) FTSEnabled() bool
- func (s *Store) FTSUnavailable() bool
- func (s *Store) ListSessions(ctx context.Context) ([]string, error)
- func (s *Store) Load(ctx context.Context, sessionID brand.SessionID) ([]session.SessionEvent, error)
- func (s *Store) Search(ctx context.Context, query string) ([]Match, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Match ¶
type Match struct {
SessionID string `json:"sessionId"`
Seq uint64 `json:"seq"`
Text string `json:"text,omitempty"`
}
Match 是一次搜索命中(会话 + 序号 + 命中文本),按 session_id 排序。
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store 是 SQLite 会话事件存储(含 FTS5 索引)。
func (*Store) Append ¶
func (s *Store) Append(ctx context.Context, sessionID brand.SessionID, ev session.SessionEvent) error
Append 追加单条事件(普通行 + FTS 行,同一事务原子写入)。
func (*Store) AppendBatch ¶
func (s *Store) AppendBatch(ctx context.Context, sessionID brand.SessionID, events []session.SessionEvent) error
AppendBatch 在一笔事务内原子写入多条事件。
func (*Store) FTSUnavailable ¶
FTSUnavailable 表示当前驱动不支持 FTS5(供调用方提示)。
func (*Store) ListSessions ¶
ListSessions 返回全部出现过会话 ID(按字典序,确定性;供 Session Query 枚举)。
Click to show internal directories.
Click to hide internal directories.