Open nsemikov opened 5 years ago
this is a bug,I hava same situation.
same here. has anyone a solution?
@stdatiks @zhl11b @gitmonster https://github.com/zhiqiangxu/gg can do such jobs with more accurate control:
cat source.go
:
package xmpl
import (
"github.com/jmoiron/sqlx"
)
type Type interface{}
type Types []Type
const Table = "table"
func GetTypes(db *sqlx.DB) (Types, error) {
result := Types{}
err := db.Select(&result, "SELECT * FROM " + Table + ";")
return result, err
}
Then gg -i source.go -t Type=Operation -c Table='"operation"' -d GetTypes=GetOperations
will output:
package xmpl
import (
"github.com/jmoiron/sqlx"
)
type Types []Operation
const Table = "operation"
func GetOperations(db *sqlx.DB) (Types, error) {
result := Types{}
err := db.Select(&result, "SELECT * FROM "+Table+";")
return result, err
}
@zhiqiangxu no, thanks
Running into the same issue. I tried something like this:
//go:generate genny -in=$GOFILE -out=gen-$GOFILE -tag=generate gen "Model=Student,Event,Location model=student,event,location"
but it made functions for every combination.
One workaround I can think of is having a generate tag for each type, for instance:
//go:generate genny -in=$GOFILE -out=student-gen.go -tag=generate gen "Model=Student model=student"
//go:generate genny -in=$GOFILE -out=event-gen.go -tag=generate gen "Model=Event model=event"
//go:generate genny -in=$GOFILE -out=location-gen.go -tag=generate gen "Model=Location model=location"
but something cleaner might be nice. Considering this project hasn't been updated in a while and go2 is coming soon, this is probably never going to be fixed :/
template
generated with
will replace
table
byOperation
, but notoperation
: