我想实现一个根据可视化界面配置的用户标签筛选的功能,我该如何翻译这个过程成 SQL 执行?

63 天前
 Keppel
入参类似这种


{
"type": "rules_relation",
"relation": "and",
"rules": [
{
"type": "rules_relation",
"relation": "or",
"rules": [
{
"type": "profile_rule",
"field": "user.gender",
"function": "equal",
"params": [
"男"
],
"cname": "性别",
"icon": "user-property"
},
{
"type": "profile_rule",
"field": "user.city",
"function": "equal",
"params": [
"北京"
],
"cname": "城市",
"icon": "user-property"
}
]
}
]
}


我是应该直接根据入参用代码实现解析成 sql 的条件,然后拼接还是采用 antlr4 这种解析器?
857 次点击
所在节点    程序员
5 条回复
penny11
63 天前
递归遍历这颗树,就翻译成 sql 了啊。。。
cydian
63 天前
实现 DSL ,也就是你说的 antlr4 ,有其他更优的解析器选择
Keppel
62 天前
入参举个例子,实际比这复杂
Keppel
62 天前
@cydian 其他的有推荐吗
ZGame
62 天前
https://github.com/jamsesso/json-logic-java 可以看看这个, 楼上其实正解了,
工业界的事实标准应该就是 hasura 了吧 graphql 那一套

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1035357

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX