V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Keppel
V2EX  ?  程序员

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

  •  
  •   Keppel · 10 天前 · 632 次点击
    入参类似这种


    {
    "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 这种解析器?
    5 条回复  ?  2024-04-25 09:30:25 +08:00
    penny11
        1
    penny11  
       10 天前 via iPhone
    递归遍历这颗树,就翻译成 sql 了啊。。。
    cydian
        2
    cydian  
       10 天前
    实现 DSL ,也就是你说的 antlr4 ,有其他更优的解析器选择
    Keppel
        3
    Keppel  
    OP
       9 天前
    入参举个例子,实际比这复杂
    Keppel
        4
    Keppel  
    OP
       9 天前
    @cydian 其他的有推荐吗
    ZGame
        5
    ZGame  
       9 天前
    https://github.com/jamsesso/json-logic-java 可以看看这个, 楼上其实正解了,
    工业界的事实标准应该就是 hasura 了吧 graphql 那一套
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   819 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 74ms · UTC 22:46 · PVG 06:46 · LAX 15:46 · JFK 18:46
    Developed with CodeLauncher
    ? Do have faith in what you're doing.


    http://www.vxiaotou.com