Hi,
It seems it is pretty convinient for SELECT but how about the usage of UPDATE statement?
I am thinking that something like loop over the colnames and set it but not sure how to map inverse , that is from the col name back to the struct field and extract the data from that field for update.
Something liek this
type Project struct {
ID uint `sql:"id"`
XX
...
}
func (p *Project) Update(dbc *sql.DB) {
tx, _ := dbc.Begin()
for colname := range sqlstruct.Columns(Project{}){
sql := fmt.Sprintf(`UPDATE project SET %s = ? WHERE id = ?`, colname)
stmt, _ := tx.Prepare(sql)
stmt.Exec( p.XXX, p.ID )
}
tx.Commit()
}
how to extract the field quickly wihtout having to create a map[string]interface{} and with more work to assert type
Hi,
It seems it is pretty convinient for SELECT but how about the usage of UPDATE statement?
I am thinking that something like loop over the colnames and set it but not sure how to map inverse , that is from the col name back to the struct field and extract the data from that field for update.
Something liek this
how to extract the field quickly wihtout having to create a map[string]interface{} and with more work to assert type