From 348a93d391a73491a7918105bf9867d0d3f65b8a Mon Sep 17 00:00:00 2001 From: Tom Smith Date: Wed, 22 May 2019 17:04:36 +0100 Subject: [PATCH] inline parseColumns function --- Migration.go | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/Migration.go b/Migration.go index 47f7ae7..3c79e08 100644 --- a/Migration.go +++ b/Migration.go @@ -1,6 +1,9 @@ package exodus -import "fmt" +import ( + "fmt" + "strings" +) // Migration is a fully-formed SQL command that can be ran against // a database connection. @@ -15,7 +18,7 @@ type MigrationInterface interface { // Create generates an SQL command to create a table using the // schema provided. func Create(table string, schema Schema) Migration { - sql := parseColumns(loadColumnSQL(schema)) + sql := strings.Join(loadColumnSQL(schema), ", ") return Migration(fmt.Sprintf("CREATE TABLE %s ( %s );", table, sql)) } @@ -36,18 +39,3 @@ func loadColumnSQL(schema Schema) (commands []string) { return } - -// parseColumns implodes the slice of SQL commands into a -// single string containing all the column definitions. -func parseColumns(sql []string) (formatted string) { - for i, command := range sql { - formatted = formatted + command - // If it is not the last column, add ", " after the - // formatted string. - if i != len(sql)-1 { - formatted = formatted + ", " - } - } - - return -}