MCPcopy Create free account
hub / github.com/cloudwan/gohan / MakeColumns

Function MakeColumns

db/sql/sql.go:765–794  ·  view source on GitHub ↗

MakeColumns generates an array that has Gohan style column names

(s *schema.Schema, tableName string, fields []string, join bool)

Source from the content-addressed store, hash-verified

763
764// MakeColumns generates an array that has Gohan style column names
765func MakeColumns(s *schema.Schema, tableName string, fields []string, join bool) []string {
766 manager := schema.GetManager()
767
768 var include map[string]bool
769 if fields != nil {
770 include = make(map[string]bool)
771 for _, f := range fields {
772 include[f] = true
773 }
774 }
775
776 var cols []string
777 for _, property := range s.Properties {
778 if property.RelationProperty != "" && join {
779 relatedSchema, ok := manager.Schema(property.Relation)
780 if !ok {
781 panic(fmt.Sprintf("missing schema %s", property.Relation))
782 }
783 aliasTableName := makeAliasTableName(tableName, property)
784 cols = append(cols, MakeColumns(relatedSchema, aliasTableName, fields, true)...)
785 }
786
787 if include != nil && !include[normField(property.ID, s.ID)] {
788 continue
789 }
790
791 cols = append(cols, makeColumn(tableName, property)+" as "+quote(makeColumnID(tableName, property)))
792 }
793 return cols
794}
795
796func makeStateColumns(s *schema.Schema) (cols []string) {
797 dbTableName := s.GetDbTableName()

Callers 3

buildSelectFunction · 0.85
sql_test.goFile · 0.85

Calls 6

makeAliasTableNameFunction · 0.85
makeColumnFunction · 0.85
makeColumnIDFunction · 0.85
normFieldFunction · 0.70
quoteFunction · 0.70
SchemaMethod · 0.65

Tested by

no test coverage detected