• 请不要在回答技术问题时复制粘贴 AI 生成的内容
Keppel
V2EX  ›  程序员

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

  •  
  •   Keppel · Apr 24, 2024 · 1541 views
    This topic created in 748 days ago, the information mentioned may be changed or developed.
    入参类似这种


    {
    "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 replies    2024-04-25 09:30:25 +08:00
    penny11
        1
    penny11  
       Apr 24, 2024 via iPhone
    递归遍历这颗树,就翻译成 sql 了啊。。。
    cydian
        2
    cydian  
       Apr 24, 2024
    实现 DSL ,也就是你说的 antlr4 ,有其他更优的解析器选择
    Keppel
        3
    Keppel  
    OP
       Apr 25, 2024
    入参举个例子,实际比这复杂
    Keppel
        4
    Keppel  
    OP
       Apr 25, 2024
    @cydian 其他的有推荐吗
    ZGame
        5
    ZGame  
       Apr 25, 2024
    https://github.com/jamsesso/json-logic-java 可以看看这个, 楼上其实正解了,
    工业界的事实标准应该就是 hasura 了吧 graphql 那一套
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5609 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 392ms · UTC 07:34 · PVG 15:34 · LAX 00:34 · JFK 03:34
    ♥ Do have faith in what you're doing.