I have error when use sqlx with postgresql : "missing destination name rec_created_by"
type Client struct {
ClientID string `json:"client_id" db:"id"`
Name string `json:"name" db:"name"`
Version int16 `json:"version" db:"version"`
IsActivated bool `json:"is_activated" db:"is_activated"`
RecCreatedBy string `json:"rec_created_by" db:"rec_created_by"`
RecCreatedByUser *User `json:"rec_created_by_user" db:"-"`
RecCreated *time.Time `json:"rec_created" db:"rec_created"`
RecModifiedBy string `json:"rec_modified_by" db:"rec_modified_by"`
RecModifiedByUser *User `json:"rec_modified_by_user" db:"-"`
RecModified *time.Time `json:"rec_modified" db:"rec_modified"`
CultureID string `json:"culture_id" db:"culture_id"`
...
}
func (c *Client) Get(id string) error {
db, err := sqlx.Connect(settings.Settings.Database.DriverName, settings.Settings.GetDbConn())
if err != nil {
log.Fatal(err)
}
defer db.Close()
_client := Client{}
err = db.QueryRowx("SELECT id, name, version, is_activated, rec_created_by, rec_created, rec_modified_by, rec_modified, culture_id, amount_decimal_places, amount_rounding_precision, \"unit-amount_decimal_places\", \"unit-amount_rounding_precision\", currency_lcy_id FROM client WHERE id=$1", id).StructScan(&_client)
if err == sql.ErrNoRows {
return ErrClientNotFound
} else if err != nil {
return err
}
return nil
}
I have db:"rec_created_by"
in my Client type but why error occurred.
*Client
why do you make a_client := &Client{}
in the body of the method... which then it appears you do nothing with. – Nidify