diff --git a/src/main/java/com/njcn/influx/constant/InfluxDbSqlConstant.java b/src/main/java/com/njcn/influx/constant/InfluxDbSqlConstant.java index 37a3a0c..080eff9 100644 --- a/src/main/java/com/njcn/influx/constant/InfluxDbSqlConstant.java +++ b/src/main/java/com/njcn/influx/constant/InfluxDbSqlConstant.java @@ -61,6 +61,12 @@ public interface InfluxDbSqlConstant { */ String ASC = StrPool.C_SPACE + "ASC" + StrPool.C_SPACE; + /** + * “LIMIT ” + */ + String LIMIT = StrPool.C_SPACE + "LIMIT" + StrPool.C_SPACE; + + /** * " as value " diff --git a/src/main/java/com/njcn/influx/query/InfluxQueryWrapper.java b/src/main/java/com/njcn/influx/query/InfluxQueryWrapper.java index a2e1dc7..bb3bd1f 100644 --- a/src/main/java/com/njcn/influx/query/InfluxQueryWrapper.java +++ b/src/main/java/com/njcn/influx/query/InfluxQueryWrapper.java @@ -47,6 +47,10 @@ public class InfluxQueryWrapper { */ private final List orderColumn = new ArrayList<>(); + /*** + * LIMIT 子句,返回查询结果的前N条points + */ + private String limitSql = ""; /*** * 查询目标表 @@ -1361,6 +1365,17 @@ public class InfluxQueryWrapper { return this; } + /*** + * LIMIT 子句,返回查询结果的前N条points + * @author hongawen + * @return InfluxQueryWrapper + * 输出 limit 10 + */ + public InfluxQueryWrapper limit(int limit) { + limitSql = InfluxDbSqlConstant.LIMIT + limit; + return this; + } + /*** * 根据配置后的实体生成对应的sql @@ -1414,6 +1429,11 @@ public class InfluxQueryWrapper { .append(String.join(StrPool.COMMA, orderColumn)); } + //判断是否有limit子句 + if(StrUtil.isNotBlank(limitSql)){ + sqlSelect.append(limitSql); + } + //最后拼接上时区 sqlSelect.append(InfluxDbSqlConstant.TZ);