fieldReferences gets a list of references to the record values, so that the caller can modify them. If withKeys is false, columns that are designated as primary keys will not be returned in this list.
(withKeys bool)
| 497 | // caller can modify them. If withKeys is false, columns that are designated as |
| 498 | // primary keys will not be returned in this list. |
| 499 | func (s *DbRecorder) fieldReferences(withKeys bool) []interface{} { |
| 500 | refs := make([]interface{}, 0, len(s.fields)) |
| 501 | |
| 502 | ar := reflect.Indirect(reflect.ValueOf(s.record)) |
| 503 | for _, field := range s.fields { |
| 504 | if !withKeys && field.isKey { |
| 505 | continue |
| 506 | } |
| 507 | |
| 508 | fv := ar.FieldByName(field.name) |
| 509 | var ref reflect.Value |
| 510 | if fv.Kind() != reflect.Ptr { |
| 511 | // we want the address of field |
| 512 | ref = fv.Addr() |
| 513 | } else { |
| 514 | // we already have an address |
| 515 | ref = fv |
| 516 | if fv.IsNil() { |
| 517 | // allocate a new element of same type |
| 518 | fv.Set(reflect.New(fv.Type().Elem())) |
| 519 | } |
| 520 | } |
| 521 | refs = append(refs, ref.Interface()) |
| 522 | } |
| 523 | |
| 524 | return refs |
| 525 | } |
| 526 | |
| 527 | // colValLists returns 2 lists, the column names and values. |
| 528 | // If withKeys is false, columns and values of fields designated as primary keys |