From 77b8bdf218eae7daa997148f161ab102acfcc598 Mon Sep 17 00:00:00 2001 From: jake Date: Tue, 30 Sep 2025 17:48:22 -0400 Subject: [PATCH] removing driver, just generating mock struct args would need an order --- driver.go | 17 ----------------- lazy.go | 16 ---------------- 2 files changed, 33 deletions(-) delete mode 100644 driver.go diff --git a/driver.go b/driver.go deleted file mode 100644 index ff58d92..0000000 --- a/driver.go +++ /dev/null @@ -1,17 +0,0 @@ -package lazy - -//driver.Result does not play well when manually creating them, overriding it here so we can return the results without -//requiring sqlmock -type sqlResult struct { - insertID int64 - rowsAffected int64 - err error -} - -func (r *sqlResult) LastInsertId() (int64, error) { - return r.insertID, r.err -} - -func (r *sqlResult) RowsAffected() (int64, error) { - return r.rowsAffected, r.err -} diff --git a/lazy.go b/lazy.go index 525c23f..af9c75f 100644 --- a/lazy.go +++ b/lazy.go @@ -47,9 +47,7 @@ type StructConfig struct { type StructMock struct { Query string - Args []driver.Value MockStructs []any - Result driver.Result } // generates mock data based on configuration to be used for sqlmock @@ -142,18 +140,12 @@ func RandomStruct(c StructConfig) (*StructMock, error) { //create slice of example structs ft := reflect.SliceOf(retType) filled := reflect.MakeSlice(ft, 0, c.RowCount) - args := make([]driver.Value, 0) //args for sqlmock WithArgs for x := 0; x < c.RowCount; x++ { //add empty example struct filled = reflect.Append(filled, reflect.ValueOf(c.Example)) for y := 0; y < maxFieldCount; y++ { field := retType.Field(y) - dbTag := field.Tag.Get(DB_TAG) - // no db tag, we skip - if dbTag == "" { - continue - } //get random value nv := kindToRandom(field) @@ -161,9 +153,6 @@ func RandomStruct(c StructConfig) (*StructMock, error) { return nil, fmt.Errorf(ErrUnsupportedType.Error(), field.Type.Name()) } - //add to sqlmock args - args = append(args, nv) - if filled.Index(x).Field(y).CanSet() { filled.Index(x).Field(y).Set(reflect.ValueOf(nv)) } @@ -179,12 +168,7 @@ func RandomStruct(c StructConfig) (*StructMock, error) { return &StructMock{ Query: sqlx.Rebind(sqlx.AT, regexp.QuoteMeta(c.Query)), - Args: args, MockStructs: retStructs, - Result: &sqlResult{ - rowsAffected: int64(c.RowCount), - err: nil, - }, }, nil }