Ompluscator / dynamic-struct

Golang package for editing struct's fields during runtime and mapping structs to other structs.
MIT License
672 stars 83 forks source link

use with sqlx and mysql #28

Closed Petricevic closed 1 year ago

Petricevic commented 1 year ago

I tried like this, but it doesn't return the rows

definition := dynamicstruct.NewStruct(). AddField("A", 0, ```db:"a" json:"a"```). AddField("R", 0, ```db:"r" json:"r"```). AddField("D", "", ```db:"d" json:"d"```). AddField("G", 0, ```db:"g" json:"g"```). Build() a := definition.NewSliceOfStructs() db.Select(&a, "SELECT a, r, d, g FROM articoli;")

while with the real struct it works

type dati struct { A uint64 ```db:"a" json:"a"``` R uint64 db:"r" json:"r" D string ```db:"d" json:"d"``` G uint64 db:"g" json:"g" } var a []dati db.Select(&a, "SELECT a, r, d, g FROM articoli;") `` Am I doing something wrong?

Petricevic commented 1 year ago

I just realized now, it's already a pointer. Just remove the &