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