This commit is contained in:
2023-08-09 09:55:19 +08:00
parent 0d6b383f9d
commit 38cc3a0699
2 changed files with 26 additions and 0 deletions

View File

@@ -61,6 +61,12 @@ public interface InfluxDbSqlConstant {
*/ */
String ASC = StrPool.C_SPACE + "ASC" + StrPool.C_SPACE; String ASC = StrPool.C_SPACE + "ASC" + StrPool.C_SPACE;
/**
* “LIMIT ”
*/
String LIMIT = StrPool.C_SPACE + "LIMIT" + StrPool.C_SPACE;
/** /**
* " as value " * " as value "

View File

@@ -47,6 +47,10 @@ public class InfluxQueryWrapper {
*/ */
private final List<String> orderColumn = new ArrayList<>(); private final List<String> orderColumn = new ArrayList<>();
/***
* LIMIT 子句返回查询结果的前N条points
*/
private String limitSql = "";
/*** /***
* 查询目标表 * 查询目标表
@@ -1361,6 +1365,17 @@ public class InfluxQueryWrapper {
return this; return this;
} }
/***
* LIMIT 子句返回查询结果的前N条points
* @author hongawen
* @return InfluxQueryWrapper
* 输出 limit 10
*/
public InfluxQueryWrapper limit(int limit) {
limitSql = InfluxDbSqlConstant.LIMIT + limit;
return this;
}
/*** /***
* 根据配置后的实体生成对应的sql * 根据配置后的实体生成对应的sql
@@ -1414,6 +1429,11 @@ public class InfluxQueryWrapper {
.append(String.join(StrPool.COMMA, orderColumn)); .append(String.join(StrPool.COMMA, orderColumn));
} }
//判断是否有limit子句
if(StrUtil.isNotBlank(limitSql)){
sqlSelect.append(limitSql);
}
//最后拼接上时区 //最后拼接上时区
sqlSelect.append(InfluxDbSqlConstant.TZ); sqlSelect.append(InfluxDbSqlConstant.TZ);