Не удалось получить запрашиваемые результаты в структурах Go orm? - PullRequest
0 голосов
/ 25 сентября 2019

Я пытаюсь извлечь SQLQ-запрос MySQL в структуры golang, используя библиотеку goorm от jinzhu.

SELECT * FROM abc where id=23  and WEEK>=DATE(NOW())-INTERVAL 7 WEEK  ```

SELECT col1,col2,col3 FROM abc where id=23  and WEEK>=DATE(NOW())-INTERVAL 7 WEEK
type Data struct {
    Col1  sql.NullInt64
    Col2          int `gorm:"primary_key" sql:"COL2" json:"col2`
    Col3            sql.NullString `json:"col3" sql:"COL3"`
    Col4     time.Time `json:"col4" sql:"COL4"`
    Col5      int `json:"col5" sql:"COL5"`
    INCOME          float64 `json:"col6" sql:"COL6"`
    INCOMPLETE      sql.NullInt64 `json:"col7" sql:"COL7"`
    NUMBEROFDRIVERS sql.NullInt64 `json:"col8" sql:"COL8"`
    PARTNERTYPE     sql.NullString `json:"col9" sql:"COL9"`
    PRESENTSTATUS   sql.NullString `json:"col10" sql:"COL10"`
    RATING          sql.NullFloat64 `json:"col11" sql:"COL11"`
    TIER            sql.NullString `json:"col12" sql:"COL12"`
    TOTALVEHICLES   sql.NullInt64 `json:"col13" sql:"COL13"`
    TRIPS           sql.NullInt64 `json:"col14" sql:"COL14"`
    WEEK            time.Time `json:"col15"" sql:"COL15"`
```}

query tried either from above

I am trying to get data into the go orm structs.

var d [] * Данные

result: = db.Table("mw_data"). Debug (). Raw (запрос) .Scan (& d) Результат говорит [затронуто или возвращено 5 строк]


But I am unable to put those data into struct.
all the values into fields of struct contains default value.

I tried normal struct as well i tried creating struct using 
<https://github.com/Shelnutt2/db2struct>

using "github.com/jinzhu/gorm" for scanning data into structs
...