colList gets a list of column names. If withKeys is false, columns that are designated as primary keys will not be returned in this list. If omitNil is true, a column represented by pointer will be omitted if this pointer is nil in current record
(withKeys bool, omitNil bool)
| 470 | // If omitNil is true, a column represented by pointer will be omitted if this |
| 471 | // pointer is nil in current record |
| 472 | func (s *DbRecorder) colList(withKeys bool, omitNil bool) []string { |
| 473 | names := make([]string, 0, len(s.fields)) |
| 474 | |
| 475 | var ar reflect.Value |
| 476 | if omitNil { |
| 477 | ar = reflect.Indirect(reflect.ValueOf(s.record)) |
| 478 | } |
| 479 | |
| 480 | for _, field := range s.fields { |
| 481 | if !withKeys && field.isKey { |
| 482 | continue |
| 483 | } |
| 484 | if omitNil { |
| 485 | f := ar.FieldByName(field.name) |
| 486 | if f.Kind() == reflect.Ptr && f.IsNil() { |
| 487 | continue |
| 488 | } |
| 489 | } |
| 490 | names = append(names, field.column) |
| 491 | } |
| 492 | |
| 493 | return names |
| 494 | } |
| 495 | |
| 496 | // fieldReferences gets a list of references to the record values, so that the |
| 497 | // caller can modify them. If withKeys is false, columns that are designated as |