sqliteactor

package
v0.0.0-...-5e0592e Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoTrace

func DoTrace(ctx context.Context, a *Actor, scope TraceScope, fn func(*sql.DB) error) error

func DoValue

func DoValue[T any](ctx context.Context, a *Actor, fn func(*sql.DB) (T, error)) (T, error)

func DoValueTrace

func DoValueTrace[T any](ctx context.Context, a *Actor, scope TraceScope, fn func(*sql.DB) (T, error)) (T, error)

func SetTraceSink

func SetTraceSink(sink TraceSink)

func TxTrace

func TxTrace(ctx context.Context, a *Actor, scope TraceScope, fn func(*sql.Tx) error) error

func TxValue

func TxValue[T any](ctx context.Context, a *Actor, fn func(*sql.Tx) (T, error)) (T, error)

func TxValueTrace

func TxValueTrace[T any](ctx context.Context, a *Actor, scope TraceScope, fn func(*sql.Tx) (T, error)) (T, error)

func WithTraceScope

func WithTraceScope(scope TraceScope, fn func())

Types

type Actor

type Actor struct {
	// contains filtered or unexported fields
}

Actor 是单 writer goroutine 排队写的执行器。 设计约束: - 写请求只能走 WriteTx,写连接只有一条 - 读请求走 Read,使用独立只读连接 - 所有查询句柄禁止带出闭包

func New

func New(db *sql.DB, readOnlyDB *sql.DB) (*Actor, error)

func (*Actor) Close

func (a *Actor) Close() error

func (*Actor) Read

func (a *Actor) Read(ctx context.Context, fn func(*sql.DB) error) error

Read 执行只读查询,查询句柄必须在闭包内关闭。

func (*Actor) WriteTx

func (a *Actor) WriteTx(ctx context.Context, fn func(*sql.Tx) error) error

WriteTx 把写请求投入写队列,由唯一 writer goroutine 顺序执行。 当前事务未结束时,下一个写请求只能排队。

type Opened

type Opened struct {
	DB    *sql.DB
	Actor *Actor
}

func Open

func Open(path string, debug bool) (*Opened, error)

type TraceEvent

type TraceEvent struct {
	TS             string   `json:"ts"`
	Operation      string   `json:"operation"`
	SQL            string   `json:"sql"`
	SQLFingerprint string   `json:"sql_fingerprint"`
	Args           []any    `json:"args,omitempty"`
	ElapsedMS      int64    `json:"elapsed_ms"`
	RowsAffected   int64    `json:"rows_affected"`
	Err            string   `json:"err,omitempty"`
	RoundID        string   `json:"round_id,omitempty"`
	Trigger        string   `json:"trigger,omitempty"`
	Intent         string   `json:"intent,omitempty"`
	Stage          string   `json:"stage,omitempty"`
	CallerChain    []string `json:"caller_chain,omitempty"`
}

TraceEvent 是单条 SQL 的追踪记录。

type TraceScope

type TraceScope struct {
	RoundID     string
	Trigger     string
	Intent      string
	Stage       string
	CallerChain []string
}

TraceScope 是一次数据库调用的关联标签。 设计说明: - 这是纯运行时观测数据,不参与业务语义; - scope 由上层在进入 DB 能力入口前显式注入; - driver 层只负责把当前 goroutine 的 scope 贴到每条 SQL 上。

type TraceSink

type TraceSink interface {
	Handle(TraceEvent)
}

TraceSink 接收 SQL 追踪事件。

Jump to

Keyboard shortcuts

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