diff --git a/db.go b/db.go index 48f2868..c0f4e85 100755 --- a/db.go +++ b/db.go @@ -130,7 +130,7 @@ func (db *Db) QueryAssociativeArray(query string) (Rows, error) { return nil, err } m[colName] = i - case "UNSIGNED BIGINT": + case "UNSIGNED BIGINT", "UNSIGNED INT": u, err := strconv.ParseUint(fmt.Sprintf("%s", *val), 10, 64) if err != nil { return nil, err @@ -615,7 +615,8 @@ func buildLinks(schema []TableInfo) []Link { return links } -func (db *Db) GenerateTemplate(templateFilename string, generatedFilename string) error { +// Generate templates from a schema +func (db *Db) GenerateSchemaTemplate(templateFilename string, generatedFilename string) error { schema, err := db.GetSchema() if err != nil { log.Println(err) @@ -648,6 +649,7 @@ func (db *Db) GenerateTemplate(templateFilename string, generatedFilename string return nil } +// Generate tables func (db *Db) GenerateTableTemplates(templateFilename string, outputFolder string, extension string) error { schema, err := db.GetSchema() if err != nil { @@ -683,7 +685,7 @@ func FormatForSQL(datatype string, value interface{}) string { if !strings.Contains(datatype, "char") && len(strval) == 0 { return "NULL" } - if strings.Contains(datatype, "char") || strings.Contains(datatype, "date") || strings.Contains(datatype, "timestamp") { + if strings.Contains(datatype, "char") || strings.Contains(datatype, "text") || strings.Contains(datatype, "date") || strings.Contains(datatype, "timestamp") { return fmt.Sprint(pq.QuoteLiteral(strval)) } return fmt.Sprint(strval) diff --git a/my_test.go b/my_test.go index acb969b..a1fe5a0 100755 --- a/my_test.go +++ b/my_test.go @@ -217,7 +217,7 @@ func TestMySaveSchema(t *testing.T) { func TestMyGenerateTemplate(t *testing.T) { db := Open("mysql", "test:test@tcp(127.0.0.1:3306)/test?parseTime=true") defer db.Close() - err := db.GenerateTemplate("plantuml.tmpl", "schema.puml") + err := db.GenerateSchemaTemplate("plantuml.tmpl", "schema.puml") if err != nil { fmt.Println(err.Error()) } diff --git a/pg_test.go b/pg_test.go index a60269d..97a7887 100755 --- a/pg_test.go +++ b/pg_test.go @@ -217,7 +217,7 @@ func TestPgSaveSchema(t *testing.T) { func TestPgGenerateTemplate(t *testing.T) { db := Open("postgres", "host=127.0.0.1 port=5432 user=test password=test dbname=test sslmode=disable") defer db.Close() - err := db.GenerateTemplate("plantuml.tmpl", "schema.puml") + err := db.GenerateSchemaTemplate("plantuml.tmpl", "schema.puml") if err != nil { fmt.Println(err.Error()) }