`
// This is not implemented yet
const PRIMARY_KEY string = ``
// Generate the tree based on the database tables and columns
func TableTree(tree map[string][]string) string {
html := TREE_OPEN
var body string
for _, table := range getSortedKeys(tree) {
body += fmt.Sprintf(TABLE_TEMPLATE, table)
body += FIELDS_LIST_OPEN + generateFields(tree[table]) + FIELDS_LIST_CLOSE
}
html += fmt.Sprintf(TREE_BODY_TEMPLATE, body)
return html + TREE_CLOSE
}
// Using a list of fields, generate the HTML for the fields
func generateFields(fields []string) string {
var html string
for _, field := range fields {
html += fmt.Sprintf(FIELD_TEMPLATE, field)
}
return html
}
// Return a list of the keys in a map, sorted alphabetically
func getSortedKeys(m map[string][]string) []string {
keys := make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}