* WIP on fixing issues and expanding tests with codegen * fixes * fix tests * feat(orm)!: pagination codegen and API cleanup * WIP on refactoring list/paginate * fixes * fixes * tests pass * codegen * codegen * Update orm/model/ormtable/index.go Co-authored-by: Marko <marbar3778@yahoo.com> * codegen * Update orm/model/ormtable/filter.go Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com> * revert Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com>
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package codegen
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
v1alpha1 "github.com/cosmos/cosmos-sdk/api/cosmos/orm/v1alpha1"
|
|
|
|
"github.com/cosmos/cosmos-proto/generator"
|
|
|
|
"google.golang.org/protobuf/compiler/protogen"
|
|
)
|
|
|
|
const (
|
|
contextPkg = protogen.GoImportPath("context")
|
|
ormListPkg = protogen.GoImportPath("github.com/cosmos/cosmos-sdk/orm/model/ormlist")
|
|
ormdbPkg = protogen.GoImportPath("github.com/cosmos/cosmos-sdk/orm/model/ormdb")
|
|
ormErrPkg = protogen.GoImportPath("github.com/cosmos/cosmos-sdk/orm/types/ormerrors")
|
|
ormTablePkg = protogen.GoImportPath("github.com/cosmos/cosmos-sdk/orm/model/ormtable")
|
|
)
|
|
|
|
func PluginRunner(p *protogen.Plugin) error {
|
|
for _, f := range p.Files {
|
|
if !f.Generate {
|
|
continue
|
|
}
|
|
|
|
if !hasTables(f) {
|
|
continue
|
|
}
|
|
|
|
gen := p.NewGeneratedFile(fmt.Sprintf("%s.cosmos_orm.go", f.GeneratedFilenamePrefix), f.GoImportPath)
|
|
cgen := &generator.GeneratedFile{
|
|
GeneratedFile: gen,
|
|
LocalPackages: map[string]bool{},
|
|
}
|
|
f := fileGen{GeneratedFile: cgen, file: f}
|
|
err := f.gen()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func hasTables(file *protogen.File) bool {
|
|
for _, message := range file.Messages {
|
|
if proto.GetExtension(message.Desc.Options(), v1alpha1.E_Table).(*v1alpha1.TableDescriptor) != nil {
|
|
return true
|
|
}
|
|
|
|
if proto.GetExtension(message.Desc.Options(), v1alpha1.E_Singleton).(*v1alpha1.SingletonDescriptor) != nil {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|