Skip to content

Commit

Permalink
Fix github-issue-220: Incorrect query to Pg
Browse files Browse the repository at this point in the history
  • Loading branch information
Артемьев Вячеслав authored and Артемьев Вячеслав committed Jul 10, 2019
1 parent e31b8ca commit 28fcf51
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 3 deletions.
3 changes: 1 addition & 2 deletions core/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ func incidentsUpdatesDB() *gorm.DB {
func (s *Service) HitsBetween(t1, t2 time.Time, group string, column string) *gorm.DB {
selector := Dbtimestamp(group, column)
if CoreApp.DbConnection == "postgres" {
timeQuery := fmt.Sprintf("service = %v AND created_at BETWEEN '%v.000000' AND '%v.000000'", s.Id, t1.UTC().Format(types.POSTGRES_TIME), t2.UTC().Format(types.POSTGRES_TIME))
return hitsDB().Select(selector).Where(timeQuery)
return hitsDB().Select(selector).Where("service = ? AND created_at BETWEEN ? AND ?", s.Id, t1.UTC().Format(types.TIME), t2.UTC().Format(types.TIME))
} else {
return hitsDB().Select(selector).Where("service = ? AND created_at BETWEEN ? AND ?", s.Id, t1.UTC().Format(types.TIME_DAY), t2.UTC().Format(types.TIME_DAY))
}
Expand Down
1 change: 0 additions & 1 deletion types/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
const (
TIME_NANO = "2006-01-02T15:04:05Z"
TIME = "2006-01-02 15:04:05"
POSTGRES_TIME = "2006-01-02 15:04"
CHART_TIME = "2006-01-02T15:04:05.999999-07:00"
TIME_DAY = "2006-01-02"
)
Expand Down

0 comments on commit 28fcf51

Please sign in to comment.