diff options
author | Markus Grüneis <gimpf@gimpf.org> | 2014-10-19 20:15:06 +0200 |
---|---|---|
committer | Markus Grüneis <gimpf@gimpf.org> | 2014-10-22 17:26:17 +0200 |
commit | 107beb0d222b1e85b1df616942ee68107ebbd841 (patch) | |
tree | 44897ce7bf8fd727c77f43eb2bc010df0ed4136b /src/hub/src | |
parent | added sample runit configs (diff) |
hub: fix and extend s5store
* fix filter sql generation (wrong field-name)
* extend with functions to query DataUpdates
Diffstat (limited to 'src/hub/src')
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5store.go | 26 | ||||
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5store_test.go | 2 |
2 files changed, 25 insertions, 3 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5store.go b/src/hub/src/spreadspace.org/sfive/s5store.go index e23c3db..e50daf3 100644 --- a/src/hub/src/spreadspace.org/sfive/s5store.go +++ b/src/hub/src/spreadspace.org/sfive/s5store.go @@ -175,13 +175,15 @@ func getFilteredDataUpdateSelect(filter *StatsFilter) (string, map[string]interf if filter.start != nil { query += insertAnd(&needsAnd) - query += " Start >= :filterstart" + query += " StartTime >= :filterstart" parameters["filterstart"] = filter.start + needsAnd = true } if filter.end != nil { query += insertAnd(&needsAnd) - query += " Start < :filterend" + query += " StartTime < :filterend" parameters["filterend"] = filter.end + needsAnd = true } // TODO other fields @@ -359,6 +361,26 @@ func (s sqliteStore) GetSource(id int) (res sourceDb, err error) { return } +func (s sqliteStore) GetUpdate(id int) (res dataUpdateDb, err error) { + err = s.db.SelectOne(&res, "select * from "+dataUpdatesTn+" where Id = ?", id) + return +} + +func (s sqliteStore) GetUpdates(filter *StatsFilter) (res []dataUpdateDb, err error) { + sourceSql, parameters := getFilteredDataUpdateSelect(filter) + updates, err := s.db.Select( + dataUpdateDb{}, + "select Id, SourceId, StartTime, ClientCount, BytesReceived, BytesSent from "+sourceSql, + parameters) + if err == nil { + res = make([]dataUpdateDb, len(updates)) + for i := range updates { + res[i] = *updates[i].(*dataUpdateDb) + } + } + return +} + func (s sqliteStore) CountUpdateEntries(filter *StatsFilter) (count int64, err error) { sourceSql, parameters := getFilteredDataUpdateSelect(filter) count, err = s.db.SelectInt("select count(*) from "+sourceSql, parameters) diff --git a/src/hub/src/spreadspace.org/sfive/s5store_test.go b/src/hub/src/spreadspace.org/sfive/s5store_test.go index ce4ce0f..2bf862e 100644 --- a/src/hub/src/spreadspace.org/sfive/s5store_test.go +++ b/src/hub/src/spreadspace.org/sfive/s5store_test.go @@ -9,7 +9,7 @@ func TestGetFilter(t *testing.T) { queryStartTime := time.Date(2015, time.December, 24, 1, 1, 1, 0, time.UTC) filterStruct := StatsFilter{start: &queryStartTime} fe, np := getFilteredDataUpdateSelect(&filterStruct) - if fe != "(select * from DataUpdates where Start >= :filterstart)" { + if fe != "(select * from DataUpdates where StartTime >= :filterstart)" { t.Errorf("get filter sql failed: fe: %v", fe) } if !queryStartTime.Equal(*np["filterstart"].(*time.Time)) { |