fix: postgres ifnull issue
This commit is contained in:
parent
639f8d34d4
commit
cb7de84771
12
model/log.go
12
model/log.go
@ -3,8 +3,9 @@ package model
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"gorm.io/gorm"
|
|
||||||
"one-api/common"
|
"one-api/common"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Log struct {
|
type Log struct {
|
||||||
@ -134,7 +135,14 @@ func SearchUserLogs(userId int, keyword string) (logs []*Log, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SumUsedQuota(logType int, startTimestamp int64, endTimestamp int64, modelName string, username string, tokenName string, channel int) (quota int) {
|
func SumUsedQuota(logType int, startTimestamp int64, endTimestamp int64, modelName string, username string, tokenName string, channel int) (quota int) {
|
||||||
tx := DB.Table("logs").Select("ifnull(sum(quota),0)")
|
var tx *gorm.DB
|
||||||
|
|
||||||
|
if common.UsingPostgreSQL {
|
||||||
|
// PostgreSQL does not support the ISNULL function
|
||||||
|
tx = DB.Table("logs").Select("COALESCE(sum(quota),0)")
|
||||||
|
} else {
|
||||||
|
tx = DB.Table("logs").Select("ifnull(sum(quota),0)")
|
||||||
|
}
|
||||||
if username != "" {
|
if username != "" {
|
||||||
tx = tx.Where("username = ?", username)
|
tx = tx.Where("username = ?", username)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user