Skip to content

Commit

Permalink
Merge pull request #1 from Tencent/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
haolingzhang1 authored Aug 1, 2021
2 parents ae09a87 + c663fb2 commit 08a8116
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
24 changes: 20 additions & 4 deletions APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public abstract class AbstractSQLConfig implements SQLConfig {
DATABASE_LIST.add(DATABASE_SQLSERVER);
DATABASE_LIST.add(DATABASE_ORACLE);
DATABASE_LIST.add(DATABASE_DB2);
DATABASE_LIST.add(DATABASE_CLICKHOUSE);


RAW_MAP = new LinkedHashMap<>(); // 保证顺序,避免配置冲突等意外情况
Expand Down Expand Up @@ -508,10 +509,17 @@ public boolean isDb2() {
public static boolean isDb2(String db) {
return DATABASE_DB2.equals(db);
}
@Override
public boolean isClickHouse() {
return isClickHouse(getSQLDatabase());
}
public static boolean isClickHouse(String db) {
return DATABASE_CLICKHOUSE.equals(db);
}

@Override
public String getQuote() {
return isMySQL() ? "`" : "\"";
return isMySQL() ? "`" : ( isClickHouse()? "" : "\"");
}

@Override
Expand Down Expand Up @@ -2158,6 +2166,9 @@ public String getRegExpString(String key, String value, boolean ignoreCase) {
if (isOracle()) {
return "regexp_like(" + getKey(key) + ", " + getValue(value) + (ignoreCase ? ", 'i'" : ", 'c'") + ")";
}
if (isClickHouse()) {
return "match(" + (ignoreCase ? "lower(" : "") + getKey(key) + (ignoreCase ? ")" : "") + ", " + (ignoreCase ? "lower(" : "") + getValue(value) + (ignoreCase ? ")" : "") + ")";
}
return getKey(key) + " REGEXP " + (ignoreCase ? "" : "BINARY ") + getValue(value);
}
//~ regexp >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Expand Down Expand Up @@ -2448,7 +2459,12 @@ else if (isOracle()) {
else {
boolean isNum = c instanceof Number;
String v = (isNum ? "" : "\"") + childs[i] + (isNum ? "" : "\"");
condition += ("json_contains(" + getKey(key) + ", " + getValue(v) + ")");
if (isClickHouse()) {
condition += condition + "has(JSONExtractArrayRaw(assumeNotNull(" + getKey(key) + "))" + ", " + getValue(v) + ")";
}
else {
condition += ("json_contains(" + getKey(key) + ", " + getValue(v) + ")");
}
}
}
}
Expand Down Expand Up @@ -2649,9 +2665,9 @@ public static String getSQL(AbstractSQLConfig config) throws Exception {
case POST:
return "INSERT INTO " + tablePath + config.getColumnString() + " VALUES" + config.getValuesString();
case PUT:
return "UPDATE " + tablePath + config.getSetString() + config.getWhereString(true) + (config.isMySQL() ? config.getLimitString() : "");
return "UPDATE " + tablePath + config.getSetString() + config.getWhereString(true) + (config.isMySQL()||config.isClickHouse() ? config.getLimitString() : "");
case DELETE:
return "DELETE FROM " + tablePath + config.getWhereString(true) + (config.isMySQL() ? config.getLimitString() : ""); // PostgreSQL 不允许 LIMIT
return "DELETE FROM " + tablePath + config.getWhereString(true) + (config.isMySQL()||config.isClickHouse() ? config.getLimitString() : ""); // PostgreSQL 不允许 LIMIT
default:
String explain = (config.isExplain() ? (config.isSQLServer() || config.isOracle() ? "SET STATISTICS PROFILE ON " : "EXPLAIN ") : "");
if (config.isTest() && RequestMethod.isGetMethod(config.getMethod(), true)) {
Expand Down
2 changes: 2 additions & 0 deletions APIJSONORM/src/main/java/apijson/orm/SQLConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public interface SQLConfig {
String DATABASE_SQLSERVER = "SQLSERVER";
String DATABASE_ORACLE = "ORACLE";
String DATABASE_DB2 = "DB2";
String DATABASE_CLICKHOUSE = "CLICKHOUSE";

String SCHEMA_INFORMATION = "information_schema"; //MySQL, PostgreSQL, SQL Server 都有的系统模式
String SCHEMA_SYS = "sys"; //SQL Server 系统模式
Expand All @@ -37,6 +38,7 @@ public interface SQLConfig {
boolean isSQLServer();
boolean isOracle();
boolean isDb2();
boolean isClickHouse();
//暂时只兼容以上 5 种
// boolean isSQL();
// boolean isTSQL();
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ https://github.com/Tencent/APIJSON/blob/master/CONTRIBUTING.md

### 腾讯犀牛鸟开源人才培养计划
https://github.com/Tencent/APIJSON/issues/229


#### qiujunlin **2.接入 presto/hive/clickhouse/db2 任意一个**

Expand All @@ -458,6 +459,18 @@ https://github.com/qiujunlin/APIJSONDemo
#### zhangshukun 2.接入 presto/hive/clickhouse/db2 任意一个
APIJSON-Demo接入db2 <br />
https://github.com/andream7/apijson-db2

#### hanxu 1.完善入门介绍视频
重构 APIJSON 文档 <br />
https://hanxu2018.github.io/APIJSON-DOC/ <br />
文档源码 <br />
https://github.com/HANXU2018/APIJSON-DOC <br />
配套评论区 apijson-doc-Comment <br />
https://github.com/HANXU2018/apijson-doc-Comment

#### chenyanlan 2.接入 presto/hive/clickhouse/db2 任意一个
APIJSON + SpringBoot连接ClickHouse使用的Demo <br />
https://github.com/chenyanlann/APIJSONDemo_ClickHouse

#### zhaoqiming 1.完善入门介绍视频
APIJSON 后端教程(1):简介
Expand All @@ -474,6 +487,10 @@ https://www.bilibili.com/video/BV18h411z7FK

APIJSON 后端教程(5):Final
https://www.bilibili.com/video/BV1GM4y1N7XJ

#### huwen 2.接入 presto/hive/clickhouse/db2 任意一个
APIJSON-Demo 接入presto
https://github.com/hclown9804/APIJSONDemo_presto

#### zhanghaoling 1.完善入门介绍视频
APIJSON结合已有项目,简化开发流程
Expand Down

0 comments on commit 08a8116

Please sign in to comment.