sqlite

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 7 Imported by: 0

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

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 Open

func Open(path string) (*Store, error)

Open 打开(或创建)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) Close

func (s *Store) Close() error

Close 关闭数据库连接。

func (*Store) Count

func (s *Store) Count(ctx context.Context, sessionID brand.SessionID) (int, error)

Count 返回某会话事件条数。

func (*Store) FTSEnabled

func (s *Store) FTSEnabled() bool

FTSEnabled 返回 FTS5 是否可用(测试断言用)。

func (*Store) FTSUnavailable

func (s *Store) FTSUnavailable() bool

FTSUnavailable 表示当前驱动不支持 FTS5(供调用方提示)。

func (*Store) ListSessions

func (s *Store) ListSessions(ctx context.Context) ([]string, error)

ListSessions 返回全部出现过会话 ID(按字典序,确定性;供 Session Query 枚举)。

func (*Store) Load

func (s *Store) Load(ctx context.Context, sessionID brand.SessionID) ([]session.SessionEvent, error)

Load 读取某会话的全部事件(按 seq 升序)。

func (*Store) Search

func (s *Store) Search(ctx context.Context, query string) ([]Match, error)

Search 用 FTS5 全文检索关键词;命中则返回匹配(session_id, seq)。 FTS5 trigram 分词要求查询 ≥3 字符;短查询(<3 rune)自动降级 LIKE。 FTS5 整体不可用时也降级 LIKE(语义一致,无词法倒排)。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL