diff options
Diffstat (limited to 'src/hub/src/spreadspace.org/sfive/s5store.go')
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5store.go | 67 |
1 files changed, 9 insertions, 58 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5store.go b/src/hub/src/spreadspace.org/sfive/s5store.go index 198069c..6aa3be8 100644 --- a/src/hub/src/spreadspace.org/sfive/s5store.go +++ b/src/hub/src/spreadspace.org/sfive/s5store.go @@ -9,58 +9,6 @@ import ( "github.com/coopernurse/gorp" ) -// compared to JSON DTOs, DB types are flattened, and use key-relations instead of collections -// this is very much not normalized at all, because I'm too lazy to type - -// table names -const ( - tagsTn = "Tags" - sourceTagsTn = "StreamToTagMap" - sourcesTn = "Sources" - clientdataUpdatesTn = "ClientDataUpdates" - dataUpdatesTn = "DataUpdates" -) - -// stored in tagsTn -type tagDb struct { - Id int - Name string -} - -// stored in sourceTagsTn -// Stream m:n Tag -type sourceTagsDb struct { - TagId int // foreign key to tagsTn - SourceId int // foreign key to sourcesTn -} - -// stored in sourcesTn -type sourceDb struct { - Id int - StreamId - SourceId -} - -// stored in clientdataUpdatesTn -// ClientData n:1 DataUpdate -type clientDataDb struct { - Id int - DataUpdatesId int // foreign key to dataUpdatesTn - ClientData -} - -// stored in dataUpdatesTn -// in DB, StatisticsData/DataUpdate is flattened compared to JSON DTOs -type dataUpdateDb struct { - Id int - SourceId int // foreign key to sourcesTn - StartTime int64 // time.Time - Duration int64 // time.Duration - ClientCount uint - BytesReceived uint - BytesSent uint -} - type sqliteStore struct { db *gorp.DbMap } @@ -169,7 +117,7 @@ func getFilteredDataUpdateSelect(filter *StatsFilter) (string, map[string]interf return dataUpdatesTn, nil } - query := "(select * from " + dataUpdatesTn + " where" + query := "(select * from " + dataUpdatesTn + " outer join " + sourcesTn + " on " + dataUpdatesTn + ".SourceId = " + sourcesTn + ".Id where" parameters := make(map[string]interface{}) needsAnd := false @@ -380,17 +328,20 @@ func (s sqliteStore) GetUpdatesAfter(id int) (res []dataUpdateDb, err error) { return } -func (s sqliteStore) GetUpdates(filter *StatsFilter) (res []dataUpdateDb, err error) { +func (s sqliteStore) GetUpdates(filter *StatsFilter) (res []StatisticsData, err error) { sourceSql, parameters := getFilteredDataUpdateSelect(filter) updates, err := s.db.Select( - dataUpdateDb{}, - "select Id, SourceId, StartTime, ClientCount, BytesReceived, BytesSent from "+sourceSql, + StatisticsData{}, + "select * from "+sourceSql, parameters) if err == nil { - res = make([]dataUpdateDb, len(updates)) + res = make([]StatisticsData, len(updates)) for i := range updates { - res[i] = *updates[i].(*dataUpdateDb) + res[i] = *updates[i].(*StatisticsData) } + + // TODO clients + // TODO tags } return } |