MCPcopy Create free account
hub / github.com/apache/devlake / GetFields

Method GetFields

backend/plugins/customize/service/service.go:49–88  ·  view source on GitHub ↗

GetFields returns all the fields of the table

(table string)

Source from the content-addressed store, hash-verified

47
48// GetFields returns all the fields of the table
49func (s *Service) GetFields(table string) ([]customizeModels.CustomizedField, errors.Error) {
50 // the customized fields created before v0.16.0 were not recorded in the table `_tool_customized_field`, we should take care of them
51 columns, err := s.dal.GetColumns(&customizeModels.Table{Name: table}, func(columnMeta dal.ColumnMeta) bool {
52 return true
53 })
54 if err != nil {
55 return nil, errors.Default.Wrap(err, "GetColumns error")
56 }
57 ff, err := s.getCustomizedFields(table)
58 if err != nil {
59 return nil, err
60 }
61 fieldMap := make(map[string]customizeModels.CustomizedField)
62 for _, f := range ff {
63 fieldMap[f.ColumnName] = f
64 }
65 var result []customizeModels.CustomizedField
66 for _, col := range columns {
67 // original fields
68 if !strings.HasPrefix(col.Name(), "x_") {
69 dataType, _ := col.ColumnType()
70 result = append(result, customizeModels.CustomizedField{
71 TbName: table,
72 ColumnName: col.Name(),
73 DataType: dal.ColumnType(dataType),
74 })
75 // customized fields
76 } else {
77 if field, ok := fieldMap[col.Name()]; ok {
78 result = append(result, field)
79 } else {
80 result = append(result, customizeModels.CustomizedField{
81 ColumnName: col.Name(),
82 DataType: dal.Varchar,
83 })
84 }
85 }
86 }
87 return result, nil
88}
89
90// checkField checks if the field exist in table
91func (s *Service) checkField(table, field string) (bool, errors.Error) {

Callers 3

checkFieldMethod · 0.95
ListFieldsMethod · 0.80

Calls 5

getCustomizedFieldsMethod · 0.95
WrapMethod · 0.80
ColumnTypeMethod · 0.80
GetColumnsMethod · 0.65
NameMethod · 0.65

Tested by 1