Closed Colstuwjx closed 3 years ago
你是说想实现类似于这样的效果吗:
NamedQuery(`select * from tb1 join tb2 where {{condition}}`, map[string]interface{}{
"condition": WhereBuilder(whereMap),
})
@caibirdme 是的!
应该是可以转成public方法的,我看看
简单写了一下: 3058cf281f17, 但是仔细一想发现 NamedQuery 用的是 {{ xxx }}
+ map[string]interface{}{}
的写法来组合出最终语句的,而 BuildWhere
的话会直接产出 cond
和 values
。
感觉还是维持原样好一些吧,开放出构造 Where 子句的方法并没有真正需要消费它的地方。
目前我们使用 where ( 一个
map[string]interface{}
)一般是配套 builder 的,比如builder.BuildSelect(table, where, selectFields)
带上一个 where 的 map。我这边有个需求是想使用 NamedQuery 做一个复杂查询,但是这样一来,where 查询部分也就不能通过 map 来表现了。是否可以通过将 whereConnector 这样的方法或者搞个类似的公开方法,将 where map 转换为具体 SQL 的这块功能开放给用户?这样的话,NamedQuery 也可以传入一个 where map 来做查询了。
希望能够考量一下是否可行!谢谢!