package exec import "fmt" // HookError 是 Hooks.Before/After 失败时必须返回的类型,外部通过 db.HookError 引用。 type HookError struct { Err error } func (e *HookError) Error() string { return fmt.Sprintf("hook error: %s", e.Err) } func (e *HookError) Unwrap() error { return e.Err } // Hooks 钩子实例 type Hooks interface { Before(dataset interface{}) *HookError After(dataset interface{}, result interface{}) *HookError // UseTx 在 Before 之前调用,dataset 是即将执行的 *InsertDataset/*UpdateDataset/*DeleteDataset // (类型与 Before 收到的一致),此时数据集尚未绑定要执行的连接。返回非 nil 的 QueryFactory 时, // 调用方会用它替换默认连接来执行这次写操作;返回 nil, nil 表示沿用默认连接。 UseTx(dataset interface{}) (QueryFactory, error) }