Skip to content

Commit 36a5612

Browse files
committed
新增支持 NULL 值 @null:"tag" 和类型转换 @cast:"date:DATE"
1 parent 028093d commit 36a5612

5 files changed

Lines changed: 337 additions & 163 deletions

File tree

APIJSONORM/src/main/java/apijson/JSONObject.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public JSONObject setUserIdIn(List<Object> list) {
134134
// public static final String KEY_KEEP = "@keep"; //一定会返回,为 null 或 空对象时,会使用默认值(非空),解决其它对象因为不关联的第一个对为空导致也不返回
135135
public static final String KEY_DEFULT = "@default"; //TODO 自定义默认值 { "@default":true },@default 可完全替代 @keep
136136
public static final String KEY_NULL = "@null"; //TODO 值为 null 的键值对 "@null":"tag,pictureList",允许 is NULL 条件判断, SET tag = NULL 修改值为 NULL 等
137+
public static final String KEY_CAST = "@cast"; //TODO 类型转换 cast(date AS DATE)
137138

138139
public static final String KEY_ROLE = "@role"; //角色,拥有对某些数据的某些操作的权限
139140
public static final String KEY_DATABASE = "@database"; //数据库类型,默认为MySQL
@@ -161,6 +162,8 @@ public JSONObject setUserIdIn(List<Object> list) {
161162
TABLE_KEY_LIST.add(KEY_CACHE);
162163
TABLE_KEY_LIST.add(KEY_COLUMN);
163164
TABLE_KEY_LIST.add(KEY_FROM);
165+
TABLE_KEY_LIST.add(KEY_NULL);
166+
TABLE_KEY_LIST.add(KEY_CAST);
164167
TABLE_KEY_LIST.add(KEY_COMBINE);
165168
TABLE_KEY_LIST.add(KEY_GROUP);
166169
TABLE_KEY_LIST.add(KEY_HAVING);
@@ -275,15 +278,45 @@ public JSONObject setColumn(String keys) {
275278
return puts(KEY_COLUMN, keys);
276279
}
277280

281+
/**set keys whose value is null
282+
* @param keys key0, key1, key2 ...
283+
* @return {@link #setNull(String)}
284+
*/
285+
public JSONObject setNull(String... keys) {
286+
return setNull(StringUtil.getString(keys, true));
287+
}
288+
/**set keys whose value is null
289+
* @param keys "key0,key1,key2..."
290+
* @return
291+
*/
292+
public JSONObject setNull(String keys) {
293+
return puts(KEY_NULL, keys);
294+
}
295+
296+
/**set keys and types whose value should be cast to type, cast(value AS DATE)
297+
* @param keyTypes key0:type0, key1:type1, key2:type2 ...
298+
* @return {@link #setCast(String)}
299+
*/
300+
public JSONObject setCast(String... keyTypes) {
301+
return setCast(StringUtil.getString(keyTypes, true));
302+
}
303+
/**set keys and types whose value should be cast to type, cast(value AS DATE)
304+
* @param keyTypes "key0:type0,key1:type1,key2:type2..."
305+
* @return
306+
*/
307+
public JSONObject setCast(String keyTypes) {
308+
return puts(KEY_CAST, keyTypes);
309+
}
310+
278311
/**set combination of keys for conditions
279-
* @param keys key0,&key1,|key2,!kye3 ...
312+
* @param keys key0,&key1,|key2,!key3 ... TODO or key0> | (key1{} & !key2)...
280313
* @return {@link #setColumn(String)}
281314
*/
282315
public JSONObject setCombine(String... keys) {
283316
return setCombine(StringUtil.getString(keys, true));
284317
}
285318
/**set combination of keys for conditions
286-
* @param keys key0,&key1,|key2,!kye3 ...
319+
* @param keys key0,&key1,|key2,!key3 ... TODO or key0> | (key1{} & !key2)...
287320
* @return
288321
*/
289322
public JSONObject setCombine(String keys) {

APIJSONORM/src/main/java/apijson/SQL.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ public class SQL {
1414
public static final String AND = " AND ";
1515
public static final String NOT = " NOT ";
1616
public static final String AS = " AS ";
17-
public static final String IS = " is ";
18-
public static final String NULL = " null ";
17+
public static final String IS = " IS ";
18+
public static final String NULL = " NULL ";
19+
public static final String IS_NOT = " IS NOT ";
20+
public static final String IS_NULL = " IS NULL ";
21+
public static final String IS_NOT_NULL = " IS NOT NULL ";
1922

2023
//括号必须紧跟函数名! count (...) 报错!
2124
public static final String COUNT = "count";

APIJSONORM/src/main/java/apijson/orm/AbstractParser.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,8 @@ else if (childKeys.length == 1 && JSONRequest.isTableKey(childKeys[0])) { //
13221322
JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_SCHEMA);
13231323
JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_DATASOURCE);
13241324
JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_COLUMN);
1325+
JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_NULL);
1326+
JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_CAST);
13251327
JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_COMBINE);
13261328
JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_GROUP);
13271329
JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_HAVING);
@@ -1330,7 +1332,7 @@ else if (childKeys.length == 1 && JSONRequest.isTableKey(childKeys[0])) { //
13301332
}
13311333

13321334
/**JOIN 多表同时筛选
1333-
* @param join "&/User,</Moment/id@",@/Comment/toId@" 或 "&/User":{}, "</Moment/id@":{}, "@/Comment/toId@": {}
1335+
* @param join "&/User,</Moment/id@",@/Comment/toId@" 或 "&/User":{}, "</Moment/id@":{"@column":"id"}, "@/Comment/toId@": {"@group":"toId", "@having":"toId>0"}
13341336
* @param request
13351337
* @return
13361338
* @throws Exception

0 commit comments

Comments
 (0)