Documentation
¶
Overview ¶
Package sqlitedsn 提供 Pinax 所有 SQLite 打开点的统一 DSN 与连接池界。
规则(pinax-local-async-substrate-v1):operation、promptasset、agentmemory、 memory ledger 等所有 SQLite 打开点必须经本包打开,禁止裸 `sqlite.Open(path)` 直连(守卫测试 internal/sqlitedsn/guard_test.go 强制)。模式对齐 sonora internal/store 已验证行为:WAL(N 读者 + 1 写者),busy_timeout 经 DSN pragma 逐连接下发(池化下 db.Exec 只会打到池中一个连接),写经 busy_timeout 串行,保持单写者语义,不引入跨进程锁。
进程退出契约:本包登记所有打开的连接池;CLI 进程退出前必须调用 CloseAll, 让 SQLite checkpoint WAL 并移除 -wal/-shm sidecar,保持 vault 树在命令间 不残留运行时产物。
Index ¶
- Constants
- func Checkpoint(db *gorm.DB) error
- func CloseAll()
- func CloseAndRelease(db *gorm.DB) error
- func DSN(path string) string
- func Open(path string) (*gorm.DB, error)
- func OpenPoolCount() int
- func OpenReadOnly(path string) (*gorm.DB, error)
- func OpenReadSnapshot(path string) (*gorm.DB, func(), error)
- func ReadOnlyDSN(path string) string
Constants ¶
const ( // MaxOpenConns / MaxIdleConns 是统一读池界:读者并行、写者仍单写者。 MaxOpenConns = 4 MaxIdleConns = 4 )
const ReadSnapshotLimit int64 = 64 << 20
ReadSnapshotLimit bounds the complete main+WAL copy. Larger indexes are unavailable to this read-only diagnostic instead of consuming unbounded IO.
Variables ¶
This section is empty.
Functions ¶
func Checkpoint ¶
CloseAll 关闭本进程内经本包打开的全部 SQLite 连接,应在 CLI 进程退出 (main 与进程内命令测试收尾)时调用。幂等;调用后既有句柄不可再用。 Checkpoint 把 WAL 内容 checkpoint 回主库文件(TRUNCATE 模式,wal 文件 清零)。供需要确定性主文件字节(测试 digest、迁移后落盘)的调用方在 关闭连接池之前使用;连接机制归本包所有。
func CloseAndRelease ¶
CloseAndRelease 关闭连接池并把它从进程退出登记表中移除:一次性调用方 (如只读索引检查)必须用它收尾,否则进程内按请求次数累积已关闭的池 引用,内存无界增长。长生命周期池不调用它,仍由退出时 CloseAll 收口; 双重关闭与未登记句柄均安全。
func OpenPoolCount ¶
func OpenPoolCount() int
OpenPoolCount 返回当前登记在退出表中的连接池数量。测试用它断言一次性 调用方不随请求数累积登记项。
func OpenReadOnly ¶
OpenReadOnly 以只读 DSN 与池界打开 GORM SQLite 连接;数据库文件不存在时 返回错误(不创建),调用方负责先做存在性判断。
func OpenReadSnapshot ¶ added in v0.3.1
OpenReadSnapshot inspects a stable private main+WAL copy. SQLite may create transient WAL/SHM even with mode=ro; those files must not appear in the vault. Never mark an active source immutable, checkpoint it, or remove its sidecars. Two identical bounded observations are required; an active writer may cause a conservative failure. This is not a replacement for a live DB transaction.
func ReadOnlyDSN ¶
ReadOnlyDSN 返回只读 DSN(mode=ro + busy_timeout + foreign_keys)。 不设置 journal_mode:只读连接无法切换 journal mode,WAL 持久化属性由 写路径连接负责。
Types ¶
This section is empty.