Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
74db0c15
Commit
74db0c15
authored
Dec 29, 2025
by
yangjianbo
Browse files
chore(生成代码): 更新 ent 客户端与事务代码
同步生成文件以匹配最新的 schema 与运行时变更
parent
ae191f72
Changes
3
Show whitespace changes
Inline
Side-by-side
backend/ent/client.go
View file @
74db0c15
...
...
@@ -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
...
)
}
backend/ent/generate.go
View file @
74db0c15
package
ent
//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate --feature sql/upsert,intercept --idtype int64 ./schema
// 启用 sql/execquery 以生成 ExecContext/QueryContext 的透传接口,便于事务内执行原生 SQL。
//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate --feature sql/upsert,intercept,sql/execquery --idtype int64 ./schema
backend/ent/tx.go
View file @
74db0c15
...
...
@@ -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
...
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment