🐛 support mysql of statistics

This commit is contained in:
Martial BE 2023-12-21 10:24:07 +08:00
parent a4138aec1a
commit c60f755715
No known key found for this signature in database
GPG Key ID: D06C32DF0EDB9084

View File

@ -194,8 +194,14 @@ func DeleteOldLog(targetTimestamp int64) (int64, error) {
} }
func SearchLogsByDayAndModel(user_id, start, end int) (LogStatistics []*LogStatistic, err error) { func SearchLogsByDayAndModel(user_id, start, end int) (LogStatistics []*LogStatistic, err error) {
groupSelect := "DATE_FORMAT(FROM_UNIXTIME(created_at), '%Y-%m-%d') as day"
if common.UsingPostgreSQL {
groupSelect = "TO_CHAR(date_trunc('day', to_timestamp(created_at)), 'YYYY-MM-DD') as day"
}
err = DB.Raw(` err = DB.Raw(`
SELECT TO_CHAR(date_trunc('day', to_timestamp(created_at)), 'YYYY-MM-DD') as day, SELECT `+groupSelect+`,
model_name, count(1) as request_count, model_name, count(1) as request_count,
sum(quota) as quota, sum(quota) as quota,
sum(prompt_tokens) as prompt_tokens, sum(prompt_tokens) as prompt_tokens,