colValLists returns 2 lists, the column names and values. If withKeys is false, columns and values of fields designated as primary keys will not be included in those lists. Also, if withAutos is false, the returned lists will not include fields designated as auto-increment.
(withKeys, withAutos bool)
| 529 | // will not be included in those lists. Also, if withAutos is false, the returned |
| 530 | // lists will not include fields designated as auto-increment. |
| 531 | func (s *DbRecorder) colValLists(withKeys, withAutos bool) (columns []string, values []interface{}) { |
| 532 | ar := reflect.Indirect(reflect.ValueOf(s.record)) |
| 533 | |
| 534 | for _, field := range s.fields { |
| 535 | |
| 536 | switch { |
| 537 | case !withKeys && field.isKey: |
| 538 | continue |
| 539 | case !withAutos && field.isAuto: |
| 540 | continue |
| 541 | } |
| 542 | |
| 543 | // Get the value of the field we are going to store. |
| 544 | f := ar.FieldByName(field.name) |
| 545 | var v reflect.Value |
| 546 | if f.Kind() == reflect.Ptr { |
| 547 | if f.IsNil() { |
| 548 | // nothing to store |
| 549 | continue |
| 550 | } |
| 551 | // no indirection: the field is already a reference to its value |
| 552 | v = f |
| 553 | } else { |
| 554 | // get the value pointed to by the field |
| 555 | v = reflect.Indirect(f) |
| 556 | } |
| 557 | |
| 558 | values = append(values, v.Interface()) |
| 559 | columns = append(columns, field.column) |
| 560 | } |
| 561 | |
| 562 | return |
| 563 | } |
| 564 | |
| 565 | // whereIds gets a list of names and a list of values for all columns marked as primary |
| 566 | // keys. |