Open xiazemin opened 2 years ago
go 1.18.2
func (db *DB) ExecContext(ctx context.Context, query string, args ...any) (Result, error) {
lower version
func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error) {
Hey @xiazemin, I tried reproing your failure with the following two file, but wire ran successfully for me. Do you have a repro that I can follow?
==> main.go <==
package main
import "fmt"
func NewAny() any {
return 0
}
func NewTest(any) int {
return 0
}
func main() {
fmt.Printf("got %d\n", InitializeTest())
}
==> wire.go <==
//go:build wireinject
// +build wireinject
package main
import "github.com/google/wire"
func InitializeTest() int {
wire.Build(NewTest, NewAny)
return 0
}
I believe I have the same or similar error.
First the error message I see (note the file in question is not a wire.go file):
wire: /home/blah/blah/blah.go:290:31: cannot use params (variable of type []interface{}) as []invalid type value in argument to db.Query
The line in question:
params := make([]interface{}, 0)
...
< do stuff like adding items to params and query>
...
rows, err := db.Query(query, params...)`
db.Query is defined with '...any':
func (db *DB) Query(query string, args ...any) (*Rows, error) {
I FIXED it by uninstalling wire and reinstalling wire using go 1.18.4. I think the issue is that wire on my system was compiled long ago before Go 1.18 came out. 'any' was introduced in Go 1.18 so that old existing binary didn't know what 'any' was. It works just fine after cleaning out the old wire binary and reinstalling the same version, but compiled with Go 1.18
I believe I have the same or similar error.
First the error message I see (note the file in question is not a wire.go file):
wire: /home/blah/blah/blah.go:290:31: cannot use params (variable of type []interface{}) as []invalid type value in argument to db.Query
The line in question:
params := make([]interface{}, 0)
... < do stuff like adding items to params and query> ... rows, err := db.Query(query, params...)`db.Query is defined with '...any':
func (db *DB) Query(query string, args ...any) (*Rows, error) {
I FIXED it by uninstalling wire and reinstalling wire using go 1.18.4. I think the issue is that wire on my system was compiled long ago before Go 1.18 came out. 'any' was introduced in Go 1.18 so that old existing binary didn't know what 'any' was. It works just fine after cleaning out the old wire binary and reinstalling the same version, but compiled with Go 1.18
I agree and verify.
You can use
go bug
to have a cool, automatically filled out bug template, or fill out the template below.Describe the bug
cannot use (sql.DB)(db) (value of type sql.DB) as sqlc.DBTX value in argument to sqlc.New: wrong type for method ExecContext (have func(ctx context.Context, query string, args ...invalid type) (database/sql.Result, error), want func(context.Context, string, ...interface{}) (database/sql.Result, error))
A clear and concise description of what the bug is.
To Reproduce
Steps to reproduce the behavior.
Expected behavior
A clear and concise description of what you expected to happen.
Version
go1.18.2 Which version of Wire are you seeing the bug with?
Additional context
Add any other context about the problem here.