Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Tencent/APIJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyLemon committed Oct 22, 2023
2 parents 790f8c5 + 99ec292 commit c6cba97
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5255,7 +5255,7 @@ else if (userId instanceof Subquery) {}
Object deletedKey = accessFakeDeleteMap == null ? null : accessFakeDeleteMap.get(KEY_DELETED_KEY);
boolean hasKey = deletedKey instanceof String && StringUtil.isNotEmpty(deletedKey, true);
Object deletedValue = hasKey ? accessFakeDeleteMap.get(KEY_DELETED_VALUE) : null;
boolean containNotDeletedValue = hasKey ? accessFakeDeleteMap.containsKey(KEY_NOT_DELETED_VALUE) : null;
boolean containNotDeletedValue = hasKey ? accessFakeDeleteMap.containsKey(KEY_NOT_DELETED_VALUE) : false;
Object notDeletedValue = containNotDeletedValue ? accessFakeDeleteMap.get(KEY_NOT_DELETED_VALUE) : null;

if (deletedValue != null || containNotDeletedValue) {
Expand Down Expand Up @@ -6020,4 +6020,4 @@ public AbstractSQLConfig setWithAsExprPreparedValueList(List<Object> list) {
this.withAsExprPreparedValueList = list;
return this;
}
}
}
2 changes: 1 addition & 1 deletion Document.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ DELETE: <br > 删除数据 | base_url/delete/ | {<br > &nbsp;&nbsp; TableName:{<
增加 或 扩展 | "key+":Object,Object的类型由key指定,且类型为Number,String,JSONArray中的一种。如 82001,"apijson",["url0","url1"] 等。只用于PUT请求 | "praiseUserIdList+":[82001],对应SQL是`json_insert(praiseUserIdList,82001)`,添加一个点赞用户id,即这个用户点了赞
减少 或 去除 | "key-":Object,与"key+"相反 | "balance-":100.00,对应SQL是`balance = balance - 100.00`,余额减少100.00,即花费了100元
比较运算 | >, <, >=, <= 比较运算符,用于 <br />① 提供 "id{}":"<=90000" 这种条件范围的简化写法 <br /><br />② 实现子查询相关比较运算<br /><br />不支持 "key=":Object 和 "key!=":Object 这两种写法,直接用更简单的 "key":Object 和 "key!":Object 替代。 | ① ["id<=":90000](http://apijson.cn:8080/get/{"[]":{"User":{"id<=":90000}}}),对应SQL是`id<=90000`,查询符合id<=90000的一个User数组<br /><br /> ② ["id>@":{<br /> &nbsp;&nbsp; "from":"Comment",<br /> &nbsp;&nbsp; "Comment":{<br /> &nbsp;&nbsp; &nbsp;&nbsp; "@column":"min(userId)" <br /> &nbsp;&nbsp; }<br />}](http://apijson.cn:8080/get/{"User":{"id>@":{"from":"Comment","Comment":{"@column":"min(userId)"}}}})<br /> WHERE id>(SELECT min(userId) FROM Comment)
逻辑运算 | &, \|, ! 逻辑运算符,对应数据库 SQL 中的 AND, OR, NOT。 <br />横或纵与:同一键值对的值内条件默认 \| 或连接,可以在 key 后加逻辑运算符来具体指定;不同键值对的条件默认 & 与连接,可以用下面说明的对象关键词 @combine 来具体指定。 <br /><br />① & 可用于"key&{}":"条件"等<br /><br />② \| 可用于"key\|{}":"条件", "key\|{}":[]等,一般可省略<br /><br />③ ! 可单独使用,如"key!":Object,也可像&,\|一样配合其他功能符使用 <br /> "key!":null 无效,null 值会导致整个键值对被忽略解析,可以用 "key{}":"!=null" 替代,<br />"key":null 同理,用 "key{}":"=null" 替代。 | ① ["id&{}":">80000,<=90000"](http://apijson.cn:8080/head/{"User":{"id&{}":">80000,<=90000"}}),对应SQL是`id>80000 AND id<=90000`,即id满足id>80000 & id<=90000<br /><br /> ② ["id\|{}":">90000,<=80000"](http://apijson.cn:8080/head/{"User":{"id\|{}":">90000,<=80000"}}),同"id{}":">90000,<=80000",对应SQL是`id>80000 OR id<=90000`,即id满足id>90000 \| id<=80000<br /><br /> ③ ["id!{}":[82001,38710]](http://apijson.cn:8080/head/{"User":{"id!{}":[82001,38710]}}),对应SQL是`id NOT IN(82001,38710)`,即id满足 ! (id=82001 \| id=38710),可过滤黑名单的消息
逻辑运算 | &, \|, ! 逻辑运算符,对应数据库 SQL 中的 AND, OR, NOT。 <br />横或纵与:同一键值对的值内条件默认 \| 或连接,可以在 key 后加逻辑运算符来具体指定;不同键值对的条件默认 & 与连接,可以用下面说明的对象关键词 @combine 来具体指定。 <br /><br />① & 可用于"key&{}":"条件"等<br /><br />② \| 可用于"key\|{}":"条件", "key\|{}":[]等,一般可省略<br /><br />③ ! 可单独使用,如"key!":Object,也可像&,\|一样配合其他功能符使用 <br /> "key!":null 无效,null 值会导致整个键值对被忽略解析,可以用 "key{}":"!=null" 替代,<br />"key":null 同理,用 "key{}":"=null" 替代。 | ① ["id&{}":">80000,<=90000"](http://apijson.cn:8080/head/{"User":{"id&{}":">80000,<=90000"}}),对应SQL是`id>80000 AND id<=90000`,即id满足id>80000 & id<=90000<br /><br /> ② ["id\|{}":">90000,<=80000"](http://apijson.cn:8080/head/{"User":{"id\|{}":">90000,<=80000"}}),同"id{}":">90000,<=80000",对应SQL是`id>90000 OR id<=80000`,即id满足id>90000 \| id<=80000<br /><br /> ③ ["id!{}":[82001,38710]](http://apijson.cn:8080/head/{"User":{"id!{}":[82001,38710]}}),对应SQL是`id NOT IN(82001,38710)`,即id满足 ! (id=82001 \| id=38710),可过滤黑名单的消息
数组关键词,可自定义 | "key":Object,key为 "[]":{} 中{}内的关键词,Object的类型由key指定<br /><br />① "count":Integer,查询数量,0 表示最大值,默认最大值为100 <br /><br />② "page":Integer,查询页码,从0开始,默认最大值为100,一般和count一起用<br /><br />③ "query":Integer,查询内容<br />0-对象,1-总数和分页详情,2-数据、总数和分页详情<br />总数关键词为 total,分页详情关键词为 info,<br /> 它们都和 query 同级,通过引用赋值得到,例如 <br />"total@":"/[]/total", "info@":"/[]/info" <br />这里query及total仅为GET类型的请求提供方便,<br /> 一般可直接用HEAD类型的请求获取总数<br /><br />④ "join":"&/Table0,\</Table1/key1@" 或 <br />"join":{<br /> &nbsp;&nbsp; "&/Table0":{}, // 支持 ON 多个字段关联,<br /> &nbsp;&nbsp; "\</Table1/key1@":{ // ON 只允许指定的 key1 关联<br /> &nbsp;&nbsp;&nbsp;&nbsp; "key0":value0, // 其它ON条件 <br /> &nbsp;&nbsp;&nbsp;&nbsp; "key2":value2,<br /> &nbsp;&nbsp;&nbsp;&nbsp; ... <br /> &nbsp;&nbsp;&nbsp;&nbsp; "@combine":"...", // 其它ON条件的组合方式 <br /> &nbsp;&nbsp;&nbsp;&nbsp; "@column":"...", // 外层 SELECT <br /> &nbsp;&nbsp;&nbsp;&nbsp; "@group":"...", // 外层 GROUP BY <br /> &nbsp;&nbsp;&nbsp;&nbsp; "@having":"..." // 外层 HAVING <br /> &nbsp;&nbsp; }<br />}<br />多表连接方式:<br /> "@" - APP JOIN <br /> "\<" - LEFT JOIN <br /> ">" - RIGHT JOIN <br /> "&" - INNER JOIN <br /> "\|" - FULL JOIN <br /> "!" - OUTER JOIN <br /> "*" - CROSS JOIN <br /> "^" - SIDE JOIN <br /> "(" - ANTI JOIN <br /> ")" - FOREIGN JOIN <br />其中 @ APP JOIN 为应用层连表,会从已查出的主表里取得所有副表 key@ 关联的主表内的 refKey 作为一个数组 refKeys: [value0, value1...],然后把原来副表 count 次查询 key=$refKey 的 SQL 用 key IN($refKeys) 的方式合并为一条 SQL 来优化性能;<br /> 其它 JOIN 都是 SQL JOIN,具体功能和 MySQL,PostgreSQL 等数据库的 JOIN 一一对应 <br />`"join":"</ViceTable/key@",`<br />`"MainTable":{},`<br />`"ViceTable":{"key@":"/MainTable/refKey"}`<br />会对应生成 <br />`MainTable LEFT JOIN ViceTable` <br />`ON ViceTable.key=MainTable.refKey` AND 其它ON条件 <br /> 除了 = 等价关联,也支持 ! 不等关联、\> \< \>= \<= 等比较关联和 $ ~ {} <> 等其它复杂关联方式 <br /><br />⑤ "otherKey":Object,自定义关键词,名称和以上系统关键词不一样,且原样返回上传的值 | ① 查询User数组,最多5个:<br />["count":5](http://apijson.cn:8080/get/{"[]":{"count":5,"User":{}}})<br />对应SQL是`LIMIT 5` <br /><br /> ② 查询第3页的User数组,每页5个:<br />["count":5,<br />"page":3](http://apijson.cn:8080/get/{"[]":{"count":5,"page":3,"User":{}}})<br />对应SQL是`LIMIT 5 OFFSET 15` <br /><br /> ③ 查询User数组和对应的User总数:<br />["[]":{<br /> &nbsp;&nbsp; "query":2,<br /> &nbsp;&nbsp; "User":{}<br />},<br />"total@":"/[]/total",<br />"info@":"/[]/info"](http://apijson.cn:8080/get/{"[]":{"query":2,"count":5,"User":{}},"total@":"%252F[]%252Ftotal","info@":"%252F[]%252Finfo"})<br /> 返回的数据中,总数及分页详情结构为: <br /> "total":139, //总数 <br /> "info":{ //分页详情 <br /> &nbsp;&nbsp; "total":139, //总数 <br /> &nbsp;&nbsp; "count":5, //每页数量 <br /> &nbsp;&nbsp; "page":0, //当前页码 <br /> &nbsp;&nbsp; "max":27, //最大页码 <br /> &nbsp;&nbsp; "more":true, //是否还有更多 <br /> &nbsp;&nbsp; "first":true, //是否为首页 <br /> &nbsp;&nbsp; "last":false //是否为尾页 <br />} <br /><br /> ④ Moment INNER JOIN User LEFT JOIN Comment:<br />["[]":{<br /> &nbsp;&nbsp; "join":"&/User/id@,\</Comment",<br /> &nbsp;&nbsp; "Moment":{<br />&nbsp;&nbsp;&nbsp;&nbsp; "@group":"id" //主副表不是一对一,要去除重复数据<br />&nbsp;&nbsp; },<br /> &nbsp;&nbsp; "User":{<br /> &nbsp;&nbsp;&nbsp;&nbsp; "name~":"t",<br /> &nbsp;&nbsp;&nbsp;&nbsp; "id@":"/Moment/userId"<br /> &nbsp;&nbsp; },<br /> &nbsp;&nbsp; "Comment":{<br /> &nbsp;&nbsp;&nbsp;&nbsp; "momentId@":"/Moment/id"<br /> &nbsp;&nbsp; }<br />}](http://apijson.cn/api/?type=JSON&url=http://apijson.cn:8080/get&json=%7B%22%5B%5D%22:%7B%22count%22:5,%22join%22:%22%26%2FUser%2Fid@,%3C%2FComment%22,%22Moment%22:%7B%22@column%22:%22id,userId,content%22,%22@group%22:%22id%22%7D,%22User%22:%7B%22name~%22:%22t%22,%22id@%22:%22%2FMoment%2FuserId%22,%22@column%22:%22id,name,head%22%7D,%22Comment%22:%7B%22momentId@%22:%22%2FMoment%2Fid%22,%22@column%22:%22id,momentId,content%22%7D%7D%7D)<br /><br /> ⑤ 每一层都加当前用户名:<br />["User":{},<br />"[]":{<br /> &nbsp;&nbsp; "name@":"User/name", //自定义关键词<br /> &nbsp;&nbsp; "Moment":{}<br />}](http://apijson.cn:8080/get/{"User":{},"[]":{"name@":"User%252Fname","Moment":{}}})
对象关键词,可自定义 | "@key":Object,@key为 Table:{} 中{}内的关键词,Object的类型由@key指定<br /><br />① "@combine":"key0 \| (key1 & (key2 \| !key3))...",条件组合方式,最终按 <br /> (其它key条件 AND 连接) AND (key0条件 OR (key1条件 AND (key2条件 OR (NOT key3条件)))) <br />这种方式连接,其中 "其它key" 是指与 @combine 在同一对象,且未被它声明的条件 key,默认都是 & 连接。注意不要缺少或多余任何一个空格。 <br /><br />② "@column":"column;function(arg)...",返回字段<br /><br />③ "@order":"column0+,column1-...",排序方式<br /><br />④ "@group":"column0,column1...",分组方式。如果@column里声明了Table的id,则id也必须在@group中声明;其它情况下必须满足至少一个条件:<br />1.分组的key在@column里声明<br />2.Table主键在@group中声明 <br /><br />⑤ "@having":"function0(...)?value0;function1(...)?value1;function2(...)?value2..." // OR 连接,或 <br />"@having&":"function0(...)?value0;function1(...)?value1;function2(...)?value2..." // AND 连接,或 <br />"@having":{<br />&nbsp;&nbsp; "h0":"function0(...)?value0",<br />&nbsp;&nbsp; "h1":function1(...)?value1",<br />&nbsp;&nbsp; "h2":function2(...)?value2...",<br />&nbsp;&nbsp; "@combine":"h0 & (h1 \| !h2)" // 任意组合,非必传<br />}<br />SQL函数条件,一般和@group一起用,函数一般在@column里声明<br /><br />⑥ "@schema":"sys",集合空间(数据库名/模式),非默认的值可通过它来指定,可以在最外层作为全局默认配置<br /><br />⑦ "@database":"POSTGRESQL",数据库类型,非默认的值可通过它来指定,可以在最外层作为全局默认配置<br /><br />⑧ "@datasource":"DRUID",跨数据源,非默认的值可通过它来指定,可以在最外层作为全局默认配置<br /><br />⑨ "@json":"key0,key1...",转为 JSON 格式返回,符合 JSONObject 则转为 {...},符合 JSONArray 则转为 \[...] <br /><br />⑩ "@role":"OWNER",来访角色,包括<br />UNKNOWN,LOGIN,CONTACT,CIRCLE,OWNER,ADMIN,<br />可以在最外层作为全局默认配置,<br />可自定义其它角色并重写 Verifier.verify 等相关方法来自定义校验 <br /><br />⑪ "@explain":true,性能分析,可以在最外层作为全局默认配置 <br /><br />⑫ "@raw":"key0,key1...",其中 key0, key1 都对应有键值对<br /> "key0":"SQL片段或SQL片段的别名", <br /> "key1":"SQL片段或SQL片段的别名" <br /> 自定义原始SQL片段,可扩展嵌套SQL函数等复杂语句,必须是后端已配置的,只有其它功能符都做不到才考虑,谨慎使用,注意防SQL注入<br /><br />⑬ "@otherKey":Object,自定义关键词,名称和以上系统关键词不一样,且原样返回上传的值 | ① 搜索name或tag任何一个字段包含字符a的User列表:<br /> ["name~":"a",<br />"tag~":"a",<br />"@combine":"name~ \| tag~"](http://apijson.cn:8080/get/{"User[]":{"count":10,"User":{"@column":"id,name,tag","name~":"a","tag~":"a","@combine":"name~%20%7C%20tag~"}}}) <br />对应SQL是`name REGEXP 'a' OR tag REGEXP 'a'` <br /><br /> ② 只查询id,sex,name这几列并且请求结果也按照这个顺序:<br />["@column":"id,sex,name"](http://apijson.cn:8080/get/{"User":{"@column":"id,sex,name","id":38710}})<br />对应SQL是`SELECT id,sex,name` <br /><br /> ③ 查询按 name降序、id默认顺序 排序的User数组:<br />["@order":"name-,id"](http://apijson.cn:8080/get/{"[]":{"count":10,"User":{"@column":"name,id","@order":"name-,id"}}})<br />对应SQL是`ORDER BY name DESC,id` <br /><br /> ④ 查询按userId分组的Moment数组:<br />["@group":"userId,id"](http://apijson.cn:8080/get/{"[]":{"count":10,"Moment":%7B"@column":"userId,id","@group":"userId,id"}}})<br />对应SQL是`GROUP BY userId,id` <br /><br /> ⑤ 查询 按userId分组、id最大值>=100 的Moment数组:<br />["@column":"userId;max(id)",<br />"@group":"userId",<br />"@having":"max(id)>=100"](http://apijson.cn:8080/get/{"[]":{"count":10,"Moment":{"@column":"userId%253Bmax(id)","@group":"userId","@having":"max(id)>=100"}}})<br />对应SQL是`SELECT userId,max(id) ... GROUP BY userId HAVING max(id)>=100` <br />还可以指定函数返回名:<br />["@column":"userId;max(id):maxId",<br />"@group":"userId",<br />"@having":"(maxId)>=100"](http://apijson.cn:8080/get/{"[]":{"count":10,"Moment":{"@column":"userId%253Bmax(id):maxId","@group":"userId","@having":"(maxId)>=100"}}})<br />对应SQL是`SELECT userId,max(id) AS maxId ... GROUP BY userId HAVING (maxId)>=100` <br /><br /> ⑥ 查询 sys 内的 User 表:<br />["@schema":"sys"](http://apijson.cn:8080/get/{"User":{"@schema":"sys"}})<br />对应SQL是`FROM sys.User` <br /><br /> ⑦ 查询 PostgreSQL 数据库的 User 表:<br />["@database":"POSTGRESQL"](http://apijson.cn:8080/get/{"User":{"@database":"POSTGRESQL","@explain":true}})<br /><br /> ⑧ 使用 Druid 连接池查询 User 表:<br />["@datasource":"DRUID"](http://apijson.cn:8080/get/{"User":{"@datasource":"DRUID"}})<br /><br /> ⑨ 将 VARCHAR 字符串字段 get 转为 JSONArray 返回:<br />["@json":"get"](http://apijson.cn:8080/get/{"Access":{"@json":"get"}})<br /><br /> ⑩ 查询当前用户的动态:<br />["@role":"OWNER"](http://apijson.cn:8080/get/{"[]":{"Moment":{"@role":"OWNER"}}})<br /><br /> ⑪ 开启性能分析:<br />["@explain":true](http://apijson.cn:8080/get/{"[]":{"Moment":{"@explain":true}}})<br />对应SQL是`EXPLAIN` <br /><br /> ⑫ 统计最近一周偶数userId的数量<br />["@column":"date;left(date,10):day;sum(if(userId%2=0,1,0))",<br />"@group":"day",<br />"@having":"to_days(now())-to_days(\`date\`)<=7",<br />"@raw":"@column,@having"](http://apijson.cn:8080/get/{"[]":{"Moment":{"@column":"date%3bleft(date,10):day%3bsum(if(userId%252=0,1,0))","@group":"day","@having":"to_days(now())-to_days(\`date\`)<=7","@raw":"@column,@having"}}})<br />对应SQL是``SELECT date, left(date,10) AS day, sum(if(userId%2=0,1,0)) ... GROUP BY day HAVING to_days(now())-to_days(`date`)<=7`` <br /><br /> ⑬ 从pictureList获取第0张图片:<br />["@position":0, //自定义关键词<br />"firstPicture()":"getFromArray(pictureList,@position)"](http://apijson.cn:8080/get/{"User":{"id":38710,"@position":0,"firstPicture()":"getFromArray(pictureList,@position)"}})
全局关键词 | 为最外层对象 {} 内的关键词。其中 @database,@schema, @datasource, @role, @explain 基本同对象关键词,见上方说明,区别是全局关键词会每个表对象中没有时自动放入,作为默认值。 <br /><br />① "tag":String,后面的 tag 是非 GET、HEAD 请求中匹配请求的 JSON 结构的标识,一般是要查询的 Table 的名称或该名称对应的数组 Table[] 或 Table:[],由后端 Request 表中指定。 <br /><br />② "version":Integer,接口版本,version 不传、为 null 或 <=0 都会使用最高版本,传了其它有效值则会使用最接近它的最低版本,由后端 Request 表中指定。<br /><br />③ "format":Boolean,格式化返回 Response JSON 的 key,一般是将 TableName 转为 tableName, TableName[] 转为 tableNameList, Table:alias 转为 alias, TableName-key[] 转为 tableNameKeyList 等小驼峰格式。 | ① 查隐私信息:<br />[{"tag":"Privacy","Privacy":{"id":82001}}](http://apijson.cn/api?url=http%3A%2F%2Fapijson.cn%3A8080%2Fgets&type=JSON&json={%22tag%22:%22Privacy%22,%22Privacy%22:{%22id%22:82001}})<br /><br /> ② 使用第 1 版接口查隐私信息:<br />[{"version":1,"tag":"Privacy","Privacy":{"id":82001}}](http://apijson.cn/api?url=http%3A%2F%2Fapijson.cn%3A8080%2Fgets&type=JSON&json={%22version%22:1,%22tag%22:%22Privacy%22,%22Privacy%22:{%22id%22:82001}}) <br /><br /> ③ 格式化朋友圈接口返回 JSON 中的 key:<br />[{<br > &nbsp;&nbsp; "format":true, <br > &nbsp;&nbsp; "[]":{<br > &nbsp;&nbsp;&nbsp;&nbsp; "page":0, <br > &nbsp;&nbsp;&nbsp;&nbsp; "count":3, <br > &nbsp;&nbsp;&nbsp;&nbsp; "Moment":{}, <br > &nbsp;&nbsp;&nbsp;&nbsp; "User":{<br > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "id@":"/Moment/userId"<br > &nbsp;&nbsp;&nbsp;&nbsp; },<br > &nbsp;&nbsp;&nbsp;&nbsp; "Comment[]":{<br > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "count":3,<br > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Comment":{<br > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "momentId@":"[]/Moment/id"<br > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br > &nbsp;&nbsp;&nbsp;&nbsp; }<br > &nbsp;&nbsp; }<br >}](http://apijson.cn:8080/get/{"format":true,"[]":{"page":0,"count":3,"Moment":{},"User":{"id@":"%252FMoment%252FuserId"},"Comment[]":{"count":3,"Comment":{"momentId@":"[]%252FMoment%252Fid"}}}})
Expand Down
Loading

0 comments on commit c6cba97

Please sign in to comment.