Skip to content

Commit

Permalink
新增支持 AI 向量数据库 Milvus
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyLemon committed Jan 4, 2024
1 parent f3dc785 commit 55064ee
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
37 changes: 30 additions & 7 deletions APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public abstract class AbstractSQLConfig<T extends Object> implements SQLConfig<T
DATABASE_LIST.add(DATABASE_HIVE);
DATABASE_LIST.add(DATABASE_PRESTO);
DATABASE_LIST.add(DATABASE_TRINO);
DATABASE_LIST.add(DATABASE_MILVUS);
DATABASE_LIST.add(DATABASE_INFLUXDB);
DATABASE_LIST.add(DATABASE_TDENGINE);
DATABASE_LIST.add(DATABASE_REDIS);
Expand Down Expand Up @@ -1191,6 +1192,14 @@ public static boolean isPresto(String db) {
return DATABASE_PRESTO.equals(db);
}

@Override
public boolean isTrino() {
return isTrino(getSQLDatabase());
}
public static boolean isTrino(String db) {
return DATABASE_TRINO.equals(db);
}

@Override
public boolean isSnowflake() {
return isSnowflake(getSQLDatabase());
Expand All @@ -1216,11 +1225,11 @@ public static boolean isCassandra(String db) {
}

@Override
public boolean isTrino() {
return isTrino(getSQLDatabase());
public boolean isMilvus() {
return isMilvus(getSQLDatabase());
}
public static boolean isTrino(String db) {
return DATABASE_TRINO.equals(db);
public static boolean isMilvus(String db) {
return DATABASE_MILVUS.equals(db);
}

@Override
Expand Down Expand Up @@ -1268,15 +1277,15 @@ public boolean isMQ() {
return isMQ(getSQLDatabase());
}
public static boolean isMQ(String db) {
return isKafka(db);
return DATABASE_MQ.equals(db) || isKafka(db);
}

@Override
public String getQuote() {
if(isElasticsearch()) {
return "";
}
return isMySQL() || isMariaDB() || isTiDB() || isClickHouse() || isTDengine() ? "`" : "\"";
return isMySQL() || isMariaDB() || isTiDB() || isClickHouse() || isTDengine() || isMilvus() ? "`" : "\"";
}

public String quote(String s) {
Expand All @@ -1290,6 +1299,7 @@ public String getSchema() {
}

@NotNull
@Override
public String getSQLSchema() {
String table = getTable();
//强制,避免因为全局默认的 @schema 自动填充进来,导致这几个类的 schema 为 sys 等其它值
Expand Down Expand Up @@ -2596,9 +2606,22 @@ public static int getOffset(int page, int count) {
*/
@JSONField(serialize = false)
public String getLimitString() {
if (count <= 0 || RequestMethod.isHeadMethod(getMethod(), true)) {
int count = getCount();

if (isMilvus()) {
if (count == 0) {
Parser<T> parser = getParser();
count = parser == null ? AbstractParser.MAX_QUERY_COUNT : parser.getMaxQueryCount();
}

int offset = getOffset(getPage(), count);
return " LIMIT " + offset + ", " + count; // 目前 moql-transx 的限制
}

if (count <= 0 || RequestMethod.isHeadMethod(getMethod(), true)) { // TODO HEAD 真的不需要 LIMIT ?
return "";
}

return getLimitString(
getPage()
, getCount()
Expand Down
5 changes: 4 additions & 1 deletion APIJSONORM/src/main/java/apijson/orm/SQLConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public interface SQLConfig<T extends Object> {
String DATABASE_SNOWFLAKE = "SNOWFLAKE"; // https://www.snowflake.com
String DATABASE_DATABRICKS = "DATABRICKS"; // https://www.databricks.com
String DATABASE_CASSANDRA = "CASSANDRA"; // https://cassandra.apache.org
String DATABASE_MILVUS = "MILVUS"; // https://milvus.io
String DATABASE_INFLUXDB = "INFLUXDB"; // https://www.influxdata.com/products/influxdb-overview
String DATABASE_TDENGINE = "TDENGINE"; // https://tdengine.com
String DATABASE_REDIS = "REDIS"; // https://redisql.com
Expand Down Expand Up @@ -79,10 +80,11 @@ public interface SQLConfig<T extends Object> {
boolean isClickHouse();
boolean isHive();
boolean isPresto();
boolean isTrino();
boolean isSnowflake();
boolean isDatabricks();
boolean isCassandra();
boolean isTrino();
boolean isMilvus();
boolean isInfluxDB();
boolean isTDengine();
boolean isRedis();
Expand Down Expand Up @@ -219,6 +221,7 @@ default int[] getDBVersionNums() {
String getDatabase();
SQLConfig setDatabase(String database);

String getSQLSchema();
String getSchema();
SQLConfig setSchema(String schema);

Expand Down

0 comments on commit 55064ee

Please sign in to comment.