diff options
Diffstat (limited to 'src/hub/src/spreadspace.org/sfive/s5store.go')
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5store.go | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5store.go b/src/hub/src/spreadspace.org/sfive/s5store.go index 569abc4..17ddbd1 100644 --- a/src/hub/src/spreadspace.org/sfive/s5store.go +++ b/src/hub/src/spreadspace.org/sfive/s5store.go @@ -159,25 +159,33 @@ func getFilteredDataUpdateSelect(filter *StatsFilter) (string, map[string]interf parameters := make(map[string]interface{}) needsAnd := false - query += " WHERE" - - if filter.start != nil { - query += insertAnd(&needsAnd) - query += " StartTime >= :filterstart" - parameters["filterstart"] = filter.start.Unix() - needsAnd = true - } - if filter.end != nil { - query += insertAnd(&needsAnd) - query += " StartTime < :filterend" - parameters["filterend"] = filter.end.Unix() - needsAnd = true - } - if filter.afterUpdateId != nil { - query += insertAnd(&needsAnd) - query += " " + dataUpdatesTn + ".Id > :afterUpdateId" - parameters["afterUpdateId"] = *filter.afterUpdateId - needsAnd = true + if filter.start != nil || filter.end != nil || filter.afterUpdateId != nil { + query += " WHERE" + + if filter.start != nil { + query += insertAnd(&needsAnd) + query += " StartTime >= :filterstart" + parameters["filterstart"] = filter.start.Unix() + needsAnd = true + } + if filter.end != nil { + query += insertAnd(&needsAnd) + query += " StartTime < :filterend" + parameters["filterend"] = filter.end.Unix() + needsAnd = true + } + if filter.afterUpdateId != nil { + query += insertAnd(&needsAnd) + query += " " + dataUpdatesTn + ".Id > :afterUpdateId" + parameters["afterUpdateId"] = *filter.afterUpdateId + needsAnd = true + } + } + + if filter.sortOrder != nil { + if *filter.sortOrder == "desc" { + query += " ORDER BY " + dataUpdatesTn + ".Id DESC" + } } if filter.limit != nil { query += " LIMIT :limit" @@ -431,10 +439,10 @@ func (s sqliteStore) GetUpdatesAfter(id int) (res []StatisticsData, err error) { func (s sqliteStore) GetUpdates(filter *StatsFilter) (res []StatisticsData, err error) { sourceSql, parameters := getFilteredDataUpdateSelect(filter) + sql := "SELECT " + updateColumnSelect + " FROM " + sourceSql + s5tl.Printf("store: sql: %s", sql) updates, err := s.db.Select( - dataUpdateQueryResult{}, - "SELECT "+updateColumnSelect+" FROM "+sourceSql, - parameters) + dataUpdateQueryResult{}, sql, parameters) if err == nil { res = make([]StatisticsData, len(updates)) for i := range updates { |