Skip to content

Commit

Permalink
Add autoincrement
Browse files Browse the repository at this point in the history
  • Loading branch information
petergeorgas committed Apr 6, 2022
1 parent e9aa388 commit 0aabdc1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions sql.go
Expand Up @@ -8,9 +8,9 @@ import (
)

type SQLOptions struct {
Table string `json:"table" xml:"table"`
EntryCount int `json:"entry_count" xml:"entry_count"`
Fields []Field `json:"fields" xml:"fields"`
Table string `json:"table" xml:"table"` // Table name we are inserting into
EntryCount int `json:"entry_count" xml:"entry_count"` // How many entries (tuples) we're generating
Fields []Field `json:"fields" xml:"fields"` // The fields to be generated
}

func SQLInsert(so *SQLOptions) ([]byte, error) { return sqlInsertFunc(globalFaker.Rand, so) }
Expand All @@ -36,8 +36,12 @@ func sqlInsertFunc(r *rand.Rand, so *SQLOptions) ([]byte, error) {
// Now, we need to add all of our fields
for ii, field := range so.Fields {
if field.Function == "autoincrement" { // One
// TODO: We need to do something here still...

autoIncNum := fmt.Sprintf("%v", i+1)
if ii == len(so.Fields)-1 { // Last field
sb.WriteString(autoIncNum)
} else {
sb.WriteString(autoIncNum + ", ")
}
continue
}

Expand Down
2 changes: 1 addition & 1 deletion sql_test.go
Expand Up @@ -75,7 +75,7 @@ func TestSQLInsertNilFields(t *testing.T) {
// must pass fields in order to generate SQL queries
}

func TestSQLInsertNoTable(t *testing.T) {
func TestSQLInsertNilTable(t *testing.T) {
Seed(11)

_, err := SQLInsert(&SQLOptions{
Expand Down

0 comments on commit 0aabdc1

Please sign in to comment.