chore(生成代码): 更新 ent 客户端与事务代码

同步生成文件以匹配最新的 schema 与运行时变更
This commit is contained in:
yangjianbo
2025-12-29 19:24:29 +08:00
parent ae191f72a4
commit 74db0c15ae
3 changed files with 58 additions and 1 deletions

View File

@@ -4,6 +4,8 @@ package ent
import (
"context"
stdsql "database/sql"
"fmt"
"sync"
"entgo.io/ent/dialect"
@@ -235,3 +237,29 @@ func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error
}
var _ dialect.Driver = (*txDriver)(nil)
// ExecContext 透传到底层事务,用于在 ent 事务中执行原生 SQL与 ent 写入保持同一事务)。
// ExecContext allows calling the underlying ExecContext method of the transaction if it is supported by it.
// See, database/sql#Tx.ExecContext for more information.
func (tx *txDriver) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error) {
ex, ok := tx.tx.(interface {
ExecContext(context.Context, string, ...any) (stdsql.Result, error)
})
if !ok {
return nil, fmt.Errorf("Tx.ExecContext is not supported")
}
return ex.ExecContext(ctx, query, args...)
}
// QueryContext 透传到底层事务,用于在 ent 事务中执行原生查询并共享锁语义。
// QueryContext allows calling the underlying QueryContext method of the transaction if it is supported by it.
// See, database/sql#Tx.QueryContext for more information.
func (tx *txDriver) QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error) {
q, ok := tx.tx.(interface {
QueryContext(context.Context, string, ...any) (*stdsql.Rows, error)
})
if !ok {
return nil, fmt.Errorf("Tx.QueryContext is not supported")
}
return q.QueryContext(ctx, query, args...)
}