feat: 新增all选项
This commit is contained in:
parent
49aee3a2ed
commit
bc4af6be86
14
db.go
14
db.go
@ -79,8 +79,13 @@ func GetSensorData(sensorID int, limit int, startDate time.Time, endDate time.Ti
|
|||||||
args = append(args, endDate)
|
args = append(args, endDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
query += " ORDER BY timestamp DESC LIMIT ?"
|
query += " ORDER BY timestamp DESC"
|
||||||
|
|
||||||
|
// 只有当limit > 0时才添加LIMIT子句
|
||||||
|
if limit > 0 {
|
||||||
|
query += " LIMIT ?"
|
||||||
args = append(args, limit)
|
args = append(args, limit)
|
||||||
|
}
|
||||||
|
|
||||||
rows, err := db.Query(query, args...)
|
rows, err := db.Query(query, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -128,8 +133,13 @@ func GetAllSensorData(limit int, startDate time.Time, endDate time.Time) ([]Sens
|
|||||||
args = append(args, endDate)
|
args = append(args, endDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
query += " ORDER BY timestamp DESC LIMIT ?"
|
query += " ORDER BY timestamp DESC"
|
||||||
|
|
||||||
|
// 只有当limit > 0时才添加LIMIT子句
|
||||||
|
if limit > 0 {
|
||||||
|
query += " LIMIT ?"
|
||||||
args = append(args, limit)
|
args = append(args, limit)
|
||||||
|
}
|
||||||
|
|
||||||
rows, err := db.Query(query, args...)
|
rows, err := db.Query(query, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -81,7 +81,7 @@ func handleGetData(w http.ResponseWriter, r *http.Request) {
|
|||||||
if limitStr != "" {
|
if limitStr != "" {
|
||||||
if limitStr == "all" {
|
if limitStr == "all" {
|
||||||
noLimit = true
|
noLimit = true
|
||||||
limit = 1000000 // 使用一个非常大的数值作为实际上的"无限制"
|
limit = 0 // 设置为0表示不使用LIMIT子句
|
||||||
} else {
|
} else {
|
||||||
limit, err = strconv.Atoi(limitStr)
|
limit, err = strconv.Atoi(limitStr)
|
||||||
if err != nil || limit <= 0 {
|
if err != nil || limit <= 0 {
|
||||||
|
|||||||
@ -159,6 +159,7 @@
|
|||||||
<option value="1000">1000</option>
|
<option value="1000">1000</option>
|
||||||
<option value="2000">2000</option>
|
<option value="2000">2000</option>
|
||||||
<option value="5000">5000</option>
|
<option value="5000">5000</option>
|
||||||
|
<option value="50000">50000</option>
|
||||||
<option value="all">全部</option>
|
<option value="all">全部</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user