github.com/Azareal/Gosora@v0.0.0-20210729070923-553e66b59003/common/statistics.go (about) 1 package common 2 3 // EXPERIMENTAL 4 import ( 5 "errors" 6 ) 7 8 var StatStore StatStoreInt 9 10 type StatStoreInt interface { 11 LookupInt(name string, duration int, unit string) (int, error) 12 } 13 14 type DefaultStatStore struct { 15 } 16 17 func NewDefaultStatStore() *DefaultStatStore { 18 return &DefaultStatStore{} 19 } 20 21 func (s *DefaultStatStore) LookupInt(name string, duration int, unit string) (int, error) { 22 switch name { 23 case "postCount": 24 return s.countTable("replies", duration, unit) 25 } 26 return 0, errors.New("The requested stat doesn't exist") 27 } 28 29 func (s *DefaultStatStore) countTable(table string, duration int, unit string) (stat int, err error) { 30 /*counter := qgen.NewAcc().Count("replies").DateCutoff("createdAt", 1, "day").Prepare() 31 if acc.FirstError() != nil { 32 return 0, acc.FirstError() 33 } 34 err := counter.QueryRow().Scan(&stat)*/ 35 return stat, err 36 } 37 38 //stmts.todaysPostCount, err = db.Prepare("select count(*) from replies where createdAt BETWEEN (utc_timestamp() - interval 1 day) and utc_timestamp()")