MCPcopy Index your code
hub / github.com/Masterminds/structable / scanFields

Method scanFields

structable.go:580–614  ·  view source on GitHub ↗

scanFields extracts the tags from all of the fields on a struct.

(ar Record)

Source from the content-addressed store, hash-verified

578
579// scanFields extracts the tags from all of the fields on a struct.
580func (s *DbRecorder) scanFields(ar Record) {
581 v := reflect.Indirect(reflect.ValueOf(ar))
582 t := v.Type()
583 count := t.NumField()
584 keys := make([]*field, 0, 2)
585
586 for i := 0; i < count; i++ {
587 f := t.Field(i)
588 // Skip fields with no tag.
589 if len(f.Tag) == 0 {
590 continue
591 }
592 sqtag := f.Tag.Get("stbl")
593 if len(sqtag) == 0 {
594 continue
595 }
596
597 parts := s.parseTag(f.Name, sqtag)
598 field := new(field)
599 field.name = f.Name
600 field.column = parts[0]
601 for _, part := range parts[1:] {
602 part = strings.TrimSpace(part)
603 switch part {
604 case "PRIMARY_KEY", "PRIMARY KEY":
605 field.isKey = true
606 keys = append(keys, field)
607 case "AUTO_INCREMENT", "SERIAL", "AUTO INCREMENT":
608 field.isAuto = true
609 }
610 }
611 s.fields = append(s.fields, field)
612 s.key = keys
613 }
614}
615
616// parseTag parses the contents of a stbl tag.
617func (s *DbRecorder) parseTag(fieldName, tag string) []string {

Callers 1

BindMethod · 0.95

Calls 1

parseTagMethod · 0.95

Tested by

no test coverage detected