Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
propersam committed Mar 25, 2020
1 parent ebbaaa7 commit 17da1c7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ pool, _ := sql.Open("mysql", "user:password@tcp(localhost:3306)/db")
dbq.Tx(ctx, pool, func(tx interface{}, Q dbq.QFn, E dbq.EFn, txCommit dbq.TxCommit) {

stmt := dbq.INSERT("table", []string{"name", "age", "created_at"}, 1)
res, err := E(ctx, stmt, nil, "test name", 34, time.Now())
res, err := E(ctx, pool, stmt, nil, "test name", 34, time.Now())
if err != nil {
return // Automatic rollback
}
Expand Down
2 changes: 1 addition & 1 deletion v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ pool, _ := sql.Open("mysql", "user:password@tcp(localhost:3306)/db")
dbq.Tx(ctx, pool, func(tx interface{}, Q dbq.QFn, E dbq.EFn, txCommit dbq.TxCommit) {

stmt := dbq.INSERT("table", []string{"name", "age", "created_at"}, 1)
res, err := E(ctx, stmt, nil, "test name", 34, time.Now())
res, err := E(ctx, pool, stmt, nil, "test name", 34, time.Now())

This comment has been minimized.

Copy link
@pjebs

pjebs Mar 25, 2020

Collaborator

This is not correct

This comment has been minimized.

Copy link
@propersam

propersam Mar 25, 2020

Author Collaborator

my implementation

// Testing Transaction
	dbq.Tx(ctx, db, func(tx interface{}, Q dbq.QFn, E dbq.EFn, txCommit dbq.TxCommit) {

		newStore := []interface{}{
			[]interface{}{"420", "Bicycles", "372", "984646746.46", "1", time.Now()},
		}

		stmt := dbq.INSERT(tbName, []string{"Id", "product", "quantity", "price", "available", "timing"}, len(newStore), dbType)

		_, err := dbq.E(ctx, stmt, nil, newStore)
		if err != nil {
			fmt.Println("Error encountered, instant rollback will be effected")
			return // Automatic rollback
		}
		txCommit() // Commit
		fmt.Println("commit successful")
	})

./main.go:70:18: cannot use stmt (type string) as type dbq.ExecContexter in argument to dbq.E:
string does not implement dbq.ExecContexter (missing ExecContext method)
./main.go:70:18: cannot use nil as type string in argument to dbq.E
./main.go:70:18: cannot use newStore (type []interface {}) as type *dbq.Options in argument to dbq.E

This comment has been minimized.

Copy link
@propersam

propersam Mar 25, 2020

Author Collaborator

adding db param before stmt removed all the above error...and code ran fine.

This comment has been minimized.

Copy link
@pjebs

pjebs Mar 25, 2020

Collaborator

No need for dbq.E. just E

This comment has been minimized.

Copy link
@propersam

propersam Mar 25, 2020

Author Collaborator

wow...it works..update reverted

if err != nil {
return // Automatic rollback
}
Expand Down

0 comments on commit 17da1c7

Please sign in to comment.