pgxmock icon indicating copy to clipboard operation
pgxmock copied to clipboard

Get value of arg to use in subsequent query

Open manatarms opened this issue 2 years ago • 0 comments

I have code that generates UUIDs that are passed into a second query. How would it be possible to get the value of the arg passed into ExpectQuery and re-use it in subsequent Expect.

Here's a quick example

// AnyArg is a generated UUID
mockDB.ExpectExec("insert into table").
	WithArgs(AnyArg).
	WillReturnResult(pgxmock.NewResult("INSERT", 1))

	
mockDB.ExpectQuery("^select (.+) from table (.+)").
        // I'm trying to reuse the ID generated and passed into the 
        // previous query
	WithArgs(ARG_FROM_PREVIOUS).
	WillReturnRows(mockDB.NewRows(columns).
		AddRow(ARG_FROM_PREVIOUS))

Thanks for your work on this package!

manatarms avatar Sep 02 '22 05:09 manatarms