More func
This commit is contained in:
36
get_top.go
Normal file
36
get_top.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
//go:embed sql/get_top.sql
|
||||
var get_top string
|
||||
|
||||
type GetTopResult struct {
|
||||
Description string `db:"description,omitempty"`
|
||||
Sku string `db:"sku,omitempty"`
|
||||
Level2 string `db:"level2,omitempty"`
|
||||
Level3 string `db:"level3,omitempty"`
|
||||
Rev float64 `db:"rev,omitempty"`
|
||||
Qty int64 `db:"qty,omitempty"`
|
||||
Trend sql.NullFloat64 `db:"trend,omitempty"`
|
||||
}
|
||||
|
||||
func (r *Runner) GetTop() []GetTopResult {
|
||||
//Get Current Days
|
||||
current_day := time.Now()
|
||||
year := current_day.Format("2006")
|
||||
previous_month := current_day.AddDate(0, -1, 0).Format("01")
|
||||
two_previous_month := current_day.AddDate(0, -2, 0).Format("01")
|
||||
four_previous_month := current_day.AddDate(0, -4, 0).Format("01")
|
||||
|
||||
query_string := fmt.Sprintf(get_top, year, previous_month, four_previous_month, two_previous_month)
|
||||
var top []GetTopResult
|
||||
err := r.db.Select(&top, query_string)
|
||||
checkErr(err)
|
||||
return top
|
||||
}
|
||||
Reference in New Issue
Block a user