Skip to content

Commit

Permalink
inline parseColumns function
Browse files Browse the repository at this point in the history
  • Loading branch information
tmus committed May 22, 2019
1 parent 8abaa12 commit 348a93d
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions Migration.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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))
}
Expand All @@ -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
}

0 comments on commit 348a93d

Please sign in to comment.