Skip to content

Commit

Permalink
sql dialect constant
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Apr 14, 2024
1 parent 757a84a commit 57be22d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/database/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import (
"time"
)

const postgresDialect = "postgres"

type StatConfig struct {
Since string `query:"since"`
Per string `query:"per"`
}

func (sc *StatConfig) GetBucketString(sqlDialect string) string {
switch sqlDialect {
case "postgres":
case postgresDialect:
switch sc.Per {
case "year":
return "YYYY"
Expand All @@ -39,7 +41,7 @@ func (sc *StatConfig) GetBucketString(sqlDialect string) string {

func (sc *StatConfig) GetBucketFormatExpression(sqlDialect string) string {
switch sqlDialect {
case "postgres":
case postgresDialect:
return "to_char(workouts.date, '" + sc.GetBucketString(sqlDialect) + "') as bucket"
default:
return "strftime('" + sc.GetBucketString(sqlDialect) + "', workouts.date) as bucket"
Expand All @@ -48,7 +50,7 @@ func (sc *StatConfig) GetBucketFormatExpression(sqlDialect string) string {

func (sc *StatConfig) GetDateLimitExpression(sqlDialect string) string {
switch sqlDialect {
case "postgres":
case postgresDialect:
return "workouts.date > CURRENT_DATE + cast(? as interval)"
default:
return "workouts.date > DATE(CURRENT_DATE, ?)"
Expand Down

0 comments on commit 57be22d

Please sign in to comment.