重构: 虚拟资源改用 NewVirtualResource 显式构造,移除 WithVirtual

WithVirtual(bool) 只是给 New() 打一个标记位,虚拟资源需要的表达式(子查询)没有
承载的地方,之前借用 table string 字段硬拼字符串。改成 NewVirtualResource(res,
code, table, opts...) 专门构造:table 参数直接接收 exp.SQLExpression,
GetTableExpr 对虚拟资源直接用它生成子查询表达式,不用再手工拼括号和字符串;
container/conn/historyRoles 从传入的父资源上直接复用。

GetTableExpr 返回值类型从 exp.LiteralExpression 放宽成 exp.Aliaseable,
兼容 db.T(...)(IdentifierExpression)和 db.L(...)(LiteralExpression)两种
返回值。
This commit is contained in:
2026-08-20 15:58:03 +08:00
parent acb55bb53a
commit 5cdf1cc00d
4 changed files with 46 additions and 15 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ type Resource interface {
// GetTable 原始表名
GetTable() string
// GetTableExpr 可用于 FROM/JOIN 的表引用表达式
GetTableExpr() exp.LiteralExpression
GetTableExpr() exp.Aliaseable
DB() *db.Database
BeginTransaction() (*db.TxDatabase, error)