129 Star 386 Fork 98

drinkjava2/jSqlBox

将新增数据库图查询语法,功能类似于GraphQL,但更简单,且完全用Java语法来表达

Done
owner
Opened this issue  
2022-09-03 05:23

功能描述如下:

Object[] qry= 
[
  "select * from users where age>?", par(10), 
      [key("order"),  //key可任意取名
       "select * from orders where price>0 ",
       "and userId in ", pid("id")," order by id", pagin(1, 10),
          [key("comments "), 
           "select * from comments where star>=5 and orderId in ", pid("id")
          ]
      ],
    [key("address"),
      "select * from addresses",
      " where userId in ", pid("id"),
    ]
];

实际执行SQL:
select * from users where age>10  // 返回user的id=1, 3, 5, 9
select * from orders where price>0 and userId in (1, 3, 5, 9) order by id limit 1, 10
select * from comments where sar>=5 and orderId in (2,4,6) 
select * from addresses where userId in (1, 3, 5, 9) 

内部根据主从ID值生成对象树并返回List<Map>结构的对象,如json化后则为:
[
   {
      "id":"u1",
      "name":"user1",
      "order":[
         {
            "id":"o1",
            "name":"order1",
            "userId":"u1",
            "comments":[{}, {}]  
         },
         {
            "id":"o2",
            "name":"order1",
            "userId":"u2",
            "comments":[{}, {}]  
         }
      ],
      "address":[
             {
            "id":"a1",
            "name":"address1",
            "userId":"u1"
         }
      ]
   },
   {
      "id":"u2",
      "name":"user2",
      "order":[
         {
            "id":"o3",
            "name":"user2",
            "userId":"u2",
            "comments":[{}, {}]  
         },
         {
            "id":"o4",
            "name":"order2",
            "userId":"u2",
            "comments":[{}, {}]  
         }
      ],
      "address":[
             {
            "id":"a2",
            "name":"address2",
            "userId":"u2"
         }
      ]
   }
]

Comments (0)

drinkjava2 created任务 3 years ago
drinkjava2 changed description 3 years ago
drinkjava2 changed description 3 years ago
drinkjava2 changed description 3 years ago
drinkjava2 changed issue state from 待办的 to 已完成 3 years ago
Expand operation logs

Sign in to comment

Status
Assignees
Milestones
Pull Requests
Successfully merging a pull request will close this issue.
Branches
Planed to start   -   Planed to end
-
Top level
Priority
参与者(1)
920504 drinkjava2 1578935955
Java
1
https://gitee.com/drinkjava2/jsqlbox.git
git@gitee.com:drinkjava2/jsqlbox.git
drinkjava2
jsqlbox
jSqlBox

Search