From 0aabdc15efbc8151d4c3931fb758a5e186f6822a Mon Sep 17 00:00:00 2001 From: Peter Georgas Date: Wed, 6 Apr 2022 17:02:37 -0400 Subject: [PATCH] Add autoincrement --- sql.go | 14 +++++++++----- sql_test.go | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/sql.go b/sql.go index 2f472cb3..2d5cc92e 100644 --- a/sql.go +++ b/sql.go @@ -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) } @@ -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 } diff --git a/sql_test.go b/sql_test.go index ec379dd9..8a75a68d 100644 --- a/sql_test.go +++ b/sql_test.go @@ -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{