gen
gen copied to clipboard
feat: extended helper interface to support custom object method and i…
…nterface definitions.
- [x] Do only one thing
- [x] Non breaking API changes
- [x] Tested
What did this pull request do?
- Extend the object interface in the helper and add the mehtod method.
- Added Interface interface in helper for customizing query interface
User Case Description
In some scenarios, I need to dynamically build modules and queries through code instead of relying on the target code to compile and run (such as parsing go code files through ast or other methods). Here are my use cases:
g := gen.NewGenerator(cfg)
obj, err := sql.ParseFromStruct("./example/model_user.go", "TblUser")
if err != nil {
panic(err)
}
g.ApplyInterface(sql.Interface{
IfName: "query",
IfMethods: []sql.Method{{
MethodName: "GetUser",
Doc: "SELECT * FROM @@table WHERE xxx=1",
}}}, g.GenerateModelFrom(obj))
g.Execute()