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

@@ -25,6 +25,8 @@ import (
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
"github.com/Wei-Shaw/sub2api/ent/usersubscription"
stdsql "database/sql"
)
// Client is the client that holds all ent builders.
@@ -1948,3 +1950,29 @@ type (
UserAllowedGroup, UserSubscription []ent.Interceptor
}
)
// ExecContext 透传到底层 driver用于在 ent 事务中执行原生 SQL例如同步 legacy 字段)。
// ExecContext allows calling the underlying ExecContext method of the driver if it is supported by it.
// See, database/sql#DB.ExecContext for more information.
func (c *config) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error) {
ex, ok := c.driver.(interface {
ExecContext(context.Context, string, ...any) (stdsql.Result, error)
})
if !ok {
return nil, fmt.Errorf("Driver.ExecContext is not supported")
}
return ex.ExecContext(ctx, query, args...)
}
// QueryContext 透传到底层 driver用于在事务内执行原生查询并共享锁/一致性语义。
// QueryContext allows calling the underlying QueryContext method of the driver if it is supported by it.
// See, database/sql#DB.QueryContext for more information.
func (c *config) QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error) {
q, ok := c.driver.(interface {
QueryContext(context.Context, string, ...any) (*stdsql.Rows, error)
})
if !ok {
return nil, fmt.Errorf("Driver.QueryContext is not supported")
}
return q.QueryContext(ctx, query, args...)
}