2016-02-23 09:27:32 +01:00
|
|
|
package cmds
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
2016-02-23 13:38:24 +01:00
|
|
|
|
|
|
|
"github.com/pobri19/sqlboiler/dbdrivers"
|
2016-02-23 09:27:32 +01:00
|
|
|
)
|
|
|
|
|
2016-02-23 13:38:24 +01:00
|
|
|
type tplData struct {
|
|
|
|
TableName string
|
|
|
|
TableData []dbdrivers.DBTable
|
|
|
|
}
|
|
|
|
|
2016-02-23 09:27:32 +01:00
|
|
|
func errorQuit(err error) {
|
|
|
|
fmt.Println(fmt.Sprintf("Error: %s\n---\n", err))
|
|
|
|
structCmd.Help()
|
|
|
|
os.Exit(-1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeGoColName(name string) string {
|
|
|
|
s := strings.Split(name, "_")
|
|
|
|
|
|
|
|
for i := 0; i < len(s); i++ {
|
|
|
|
if s[i] == "id" {
|
|
|
|
s[i] = "ID"
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
s[i] = strings.Title(s[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings.Join(s, "")
|
|
|
|
}
|
|
|
|
|
2016-02-23 13:38:24 +01:00
|
|
|
func makeGoVarName(name string) string {
|
|
|
|
s := strings.Split(name, "_")
|
|
|
|
|
|
|
|
for i := 0; i < len(s); i++ {
|
|
|
|
if s[i] == "id" {
|
|
|
|
s[i] = "ID"
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip first word Title for variable names
|
|
|
|
if i == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
s[i] = strings.Title(s[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings.Join(s, "")
|
|
|
|
}
|
|
|
|
|
2016-02-23 09:27:32 +01:00
|
|
|
func makeDBColName(tableName, colName string) string {
|
|
|
|
return tableName + "_" + colName
|
|
|
|
}
|