feat(orm): codegen (#11033)

## Description

adds orm code generation

Closes: #10737 



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
This commit is contained in:
Tyler 2022-01-28 10:43:24 -08:00 committed by GitHub
parent 03dcc4f26e
commit 20b2605d79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 1648 additions and 226 deletions

3
orm/Makefile Normal file
View File

@ -0,0 +1,3 @@
codegen:
go install ./cmd/protoc-gen-go-cosmos-orm
(cd internal; buf generate)

View File

@ -0,0 +1,11 @@
package main
import (
"google.golang.org/protobuf/compiler/protogen"
"github.com/cosmos/cosmos-sdk/orm/internal/codegen"
)
func main() {
protogen.Options{}.Run(codegen.PluginRunner)
}

View File

@ -6,6 +6,7 @@ require (
github.com/cosmos/cosmos-proto v1.0.0-alpha6
github.com/cosmos/cosmos-sdk/api v0.1.0-alpha3
github.com/cosmos/cosmos-sdk/errors v1.0.0-beta.2
github.com/iancoleman/strcase v0.2.0
github.com/stretchr/testify v1.7.0
github.com/tendermint/tm-db v0.6.6
google.golang.org/protobuf v1.27.1

View File

@ -94,6 +94,8 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U=
github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ=

View File

@ -9,3 +9,6 @@ plugins:
- name: go-pulsar
out: .
opt: paths=source_relative
- name: go-cosmos-orm
out: .
opt: paths=source_relative

View File

@ -0,0 +1,62 @@
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")
protoreflectPackage = protogen.GoImportPath("google.golang.org/protobuf/reflect/protoreflect")
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")
fmtPkg = protogen.GoImportPath("fmt")
)
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
}

View File

@ -0,0 +1,162 @@
package codegen
import (
"path/filepath"
"strings"
"github.com/cosmos/cosmos-proto/generator"
"github.com/iancoleman/strcase"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/proto"
v1alpha1 "github.com/cosmos/cosmos-sdk/api/cosmos/orm/v1alpha1"
)
var (
tablePkg = protogen.GoImportPath("github.com/cosmos/cosmos-sdk/orm/model/ormtable")
)
type fileGen struct {
*generator.GeneratedFile
file *protogen.File
}
func (f fileGen) gen() error {
f.P("// Code generated by protoc-gen-go-cosmos-orm. DO NOT EDIT.")
f.P()
f.P("package ", f.file.GoPackageName)
stores := make([]*protogen.Message, 0)
for _, msg := range f.file.Messages {
tableDesc := proto.GetExtension(msg.Desc.Options(), v1alpha1.E_Table).(*v1alpha1.TableDescriptor)
if tableDesc != nil {
newTableGen(f, msg, tableDesc).gen()
}
singletonDesc := proto.GetExtension(msg.Desc.Options(), v1alpha1.E_Singleton).(*v1alpha1.SingletonDescriptor)
if singletonDesc != nil {
// do some singleton magic
newSingletonGen(f, msg, singletonDesc).gen()
}
if tableDesc != nil || singletonDesc != nil { // message is one of the tables,
stores = append(stores, msg)
}
}
f.genStoreInterfaces(stores)
f.genStoreStruct(stores)
f.genStoreMethods(stores)
f.genStoreInterfaceGuard()
f.genStoreConstructor(stores)
return nil
}
func (f fileGen) genStoreInterfaces(stores []*protogen.Message) {
f.P("type ", f.storeInterfaceName(), " interface {")
for _, store := range stores {
name := f.messageStoreInterfaceName(store)
f.P(name, "()", name)
}
f.P()
f.P("doNotImplement()")
f.P("}")
f.P()
}
func (f fileGen) genStoreStruct(stores []*protogen.Message) {
// struct
f.P("type ", f.storeStructName(), " struct {")
for _, message := range stores {
f.P(f.param(message.GoIdent.GoName), " ", f.messageStoreInterfaceName(message))
}
f.P("}")
}
func (f fileGen) storeAccessorName() string {
return f.storeInterfaceName()
}
func (f fileGen) storeInterfaceName() string {
return strcase.ToCamel(f.fileShortName()) + "Store"
}
func (f fileGen) storeStructName() string {
return strcase.ToLowerCamel(f.fileShortName()) + "Store"
}
func (f fileGen) fileShortName() string {
filename := f.file.Proto.GetName()
shortName := filepath.Base(filename)
i := strings.Index(shortName, ".")
if i > 0 {
return shortName[:i]
}
return strcase.ToCamel(shortName)
}
func (f fileGen) messageStoreInterfaceName(m *protogen.Message) string {
return m.GoIdent.GoName + "Store"
}
func (f fileGen) messageReaderInterfaceName(m *protogen.Message) string {
return m.GoIdent.GoName + "Reader"
}
func (f fileGen) messageTableVar(m *protogen.Message) string {
return f.param(m.GoIdent.GoName + "Table")
}
func (f fileGen) param(name string) string {
return strcase.ToLowerCamel(name)
}
func (f fileGen) messageStoreReceiverName(m *protogen.Message) string {
return f.param(f.messageStoreInterfaceName(m))
}
func (f fileGen) messageConstructorName(m *protogen.Message) string {
return "New" + f.messageStoreInterfaceName(m)
}
func (f fileGen) genStoreMethods(stores []*protogen.Message) {
// getters
for _, msg := range stores {
name := f.messageStoreInterfaceName(msg)
f.P("func(x ", f.storeStructName(), ") ", name, "() ", name, "{")
f.P("return x.", f.param(msg.GoIdent.GoName))
f.P("}")
f.P()
}
f.P("func(", f.storeStructName(), ") doNotImplement() {}")
f.P()
}
func (f fileGen) genStoreInterfaceGuard() {
f.P("var _ ", f.storeInterfaceName(), " = ", f.storeStructName(), "{}")
}
func (f fileGen) genStoreConstructor(stores []*protogen.Message) {
f.P("func New", f.storeInterfaceName(), "(db ", ormdbPkg.Ident("ModuleDB"), ") (", f.storeInterfaceName(), ", error) {")
for _, store := range stores {
f.P(f.messageStoreReceiverName(store), ", err := ", f.messageConstructorName(store), "(db)")
f.P("if err != nil {")
f.P("return nil, err")
f.P("}")
f.P()
}
f.P("return ", f.storeStructName(), "{")
for _, store := range stores {
f.P(f.messageStoreReceiverName(store), ",")
}
f.P("}, nil")
f.P("}")
}
func (f fileGen) fieldsToCamelCase(fields string) string {
splitFields := strings.Split(fields, ",")
camelFields := make([]string, len(splitFields))
for i, field := range splitFields {
camelFields[i] = strcase.ToCamel(field)
}
return strings.Join(camelFields, "")
}

View File

@ -0,0 +1,133 @@
package codegen
import (
"fmt"
"strings"
"github.com/iancoleman/strcase"
"google.golang.org/protobuf/reflect/protoreflect"
)
func (t tableGen) genIndexKeys() {
// interface that all keys must adhere to
t.P("type ", t.indexKeyInterfaceName(), " interface {")
t.P("id() uint32")
t.P("values() []interface{}")
t.P(t.param(t.indexKeyInterfaceName()), "()")
t.P("}")
t.P()
// start with primary key..
t.P("// primary key starting index..")
t.genIndex(t.table.PrimaryKey.Fields, t.ormTable.ID())
for _, idx := range t.table.Index {
t.genIndex(idx.Fields, idx.Id)
}
}
func (t tableGen) genIterator() {
t.P("type ", t.iteratorName(), " struct {")
t.P(tablePkg.Ident("Iterator"))
t.P("}")
t.P()
t.genValueFunc()
t.P()
}
func (t tableGen) genValueFunc() {
varName := t.param(t.msg.GoIdent.GoName)
t.P("func (i ", t.iteratorName(), ") Value() (*", t.QualifiedGoIdent(t.msg.GoIdent), ", error) {")
t.P("var ", varName, " ", t.QualifiedGoIdent(t.msg.GoIdent))
t.P("err := i.UnmarshalMessage(&", varName, ")")
t.P("return &", varName, ", err")
t.P("}")
}
func (t tableGen) genIndexMethods(idxKeyName string) {
receiverFunc := fmt.Sprintf("func (x %s) ", idxKeyName)
t.P(receiverFunc, "id() uint32 { return ", t.table.Id, " /* primary key */ }")
t.P(receiverFunc, "values() []interface{} { return x.vs }")
t.P(receiverFunc, t.param(t.indexKeyInterfaceName()), "() {}")
t.P()
}
func (t tableGen) genIndexInterfaceGuard(idxKeyName string) {
t.P("var _ ", t.indexKeyInterfaceName(), " = ", idxKeyName, "{}")
t.P()
}
func (t tableGen) indexKeyInterfaceName() string {
return t.msg.GoIdent.GoName + "IndexKey"
}
func (t tableGen) genIndexKey(idxKeyName string) {
t.P("type ", idxKeyName, " struct {")
t.P("vs []interface{}")
t.P("}")
t.P()
}
func (t tableGen) indexKeyParts(names []protoreflect.Name) string {
cnames := make([]string, len(names))
for i, name := range names {
cnames[i] = strcase.ToCamel(string(name))
}
return strings.Join(cnames, "")
}
func (t tableGen) indexKeyName(names []protoreflect.Name) string {
cnames := make([]string, len(names))
for i, name := range names {
cnames[i] = strcase.ToCamel(string(name))
}
joinedNames := strings.Join(cnames, "")
return t.msg.GoIdent.GoName + joinedNames + "IndexKey"
}
func (t tableGen) indexStructName(fields []string) string {
names := make([]string, len(fields))
for i, field := range fields {
names[i] = strcase.ToCamel(field)
}
joinedNames := strings.Join(names, "")
return t.msg.GoIdent.GoName + joinedNames + "IndexKey"
}
func (t tableGen) genIndex(fields string, id uint32) {
fieldsSlc := strings.Split(fields, ",")
idxKeyName := t.indexStructName(fieldsSlc)
t.P("type ", idxKeyName, " struct {")
t.P("vs []interface{}")
t.P("}")
t.genIndexInterfaceMethods(id, idxKeyName)
for i := 1; i < len(fieldsSlc)+1; i++ {
t.genWithMethods(idxKeyName, fieldsSlc[:i])
}
}
func (t tableGen) genIndexInterfaceMethods(id uint32, indexStructName string) {
funPrefix := fmt.Sprintf("func (x %s) ", indexStructName)
t.P(funPrefix, "id() uint32 {return ", id, "}")
t.P(funPrefix, "values() []interface{} {return x.vs}")
t.P(funPrefix, t.param(t.indexKeyInterfaceName()), "() {}")
t.P()
}
func (t tableGen) genWithMethods(indexStructName string, parts []string) {
funcPrefix := fmt.Sprintf("func (this %s) ", indexStructName)
camelParts := make([]string, len(parts))
for i, part := range parts {
camelParts[i] = strcase.ToCamel(part)
}
funcName := "With" + strings.Join(camelParts, "")
t.P(funcPrefix, funcName, "(", t.fieldArgsFromStringSlice(parts), ") ", indexStructName, "{")
t.P("this.vs = []interface{}{", strings.Join(parts, ","), "}")
t.P("return this")
t.P("}")
t.P()
}

View File

@ -0,0 +1,89 @@
package codegen
import (
"fmt"
ormv1alpha1 "github.com/cosmos/cosmos-sdk/api/cosmos/orm/v1alpha1"
"github.com/cosmos/cosmos-sdk/orm/model/ormtable"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/types/dynamicpb"
)
type singletonGen struct {
fileGen
msg *protogen.Message
table *ormv1alpha1.SingletonDescriptor
ormTable ormtable.Table
}
func newSingletonGen(fileGen fileGen, msg *protogen.Message, table *ormv1alpha1.SingletonDescriptor) *singletonGen {
s := &singletonGen{fileGen: fileGen, msg: msg, table: table}
ot, err := ormtable.Build(ormtable.Options{
MessageType: dynamicpb.NewMessageType(msg.Desc),
SingletonDescriptor: table,
})
if err != nil {
panic(err)
}
s.ormTable = ot
return s
}
func (s singletonGen) gen() {
s.genInterface()
s.genStruct()
s.genInterfaceGuard()
s.genMethods()
s.genConstructor()
}
func (s singletonGen) genInterface() {
s.P("// singleton store")
s.P("type ", s.messageStoreInterfaceName(s.msg), " interface {")
s.P("Get(ctx ", contextPkg.Ident("Context"), ") (*", s.msg.GoIdent.GoName, ", error)")
s.P("Save(ctx ", contextPkg.Ident("Context"), ", ", s.param(s.msg.GoIdent.GoName), "*", s.msg.GoIdent.GoName, ") error")
s.P("}")
s.P()
}
func (s singletonGen) genStruct() {
s.P("type ", s.messageStoreReceiverName(s.msg), " struct {")
s.P("table ", tablePkg.Ident("Table"))
s.P("}")
s.P()
}
func (s singletonGen) genInterfaceGuard() {
s.P("var _ ", s.messageStoreInterfaceName(s.msg), " = ", s.messageStoreReceiverName(s.msg), "{}")
}
func (s singletonGen) genMethods() {
receiver := fmt.Sprintf("func (x %s) ", s.messageStoreReceiverName(s.msg))
varName := s.param(s.msg.GoIdent.GoName)
// Get
s.P(receiver, "Get(ctx ", contextPkg.Ident("Context"), ") (*", s.msg.GoIdent.GoName, ", error) {")
s.P("var ", varName, " ", s.msg.GoIdent.GoName)
s.P("found, err := x.table.Get(ctx, &", varName, ")")
s.P("if !found {")
s.P("return nil, err")
s.P("}")
s.P("return &", varName, ", err")
s.P("}")
s.P()
// Save
s.P(receiver, "Save(ctx ", contextPkg.Ident("Context"), ", ", varName, " *", s.msg.GoIdent.GoName, ") error {")
s.P("return x.table.Save(ctx, ", varName, ")")
s.P("}")
s.P()
}
func (s singletonGen) genConstructor() {
iface := s.messageStoreInterfaceName(s.msg)
s.P("func New", iface, "(db ", ormdbPkg.Ident("ModuleDB"), ") (", iface, ", error) {")
s.P("table := db.GetTable(&", s.msg.GoIdent.GoName, "{})")
s.P("if table == nil {")
s.P("return nil, ", ormErrPkg.Ident("TableNotFound.Wrap"), "(string((&", s.msg.GoIdent.GoName, "{}).ProtoReflect().Descriptor().FullName()))")
s.P("}")
s.P("return &", s.messageStoreReceiverName(s.msg), "{table}, nil")
s.P("}")
}

View File

@ -0,0 +1,254 @@
package codegen
import (
"fmt"
"strings"
"github.com/iancoleman/strcase"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/types/dynamicpb"
ormv1alpha1 "github.com/cosmos/cosmos-sdk/api/cosmos/orm/v1alpha1"
"github.com/cosmos/cosmos-sdk/orm/internal/fieldnames"
"github.com/cosmos/cosmos-sdk/orm/model/ormtable"
)
type tableGen struct {
fileGen
msg *protogen.Message
table *ormv1alpha1.TableDescriptor
primaryKeyFields fieldnames.FieldNames
fields map[protoreflect.Name]*protogen.Field
uniqueIndexes []*ormv1alpha1.SecondaryIndexDescriptor
ormTable ormtable.Table
}
func newTableGen(fileGen fileGen, msg *protogen.Message, table *ormv1alpha1.TableDescriptor) *tableGen {
t := &tableGen{fileGen: fileGen, msg: msg, table: table, fields: map[protoreflect.Name]*protogen.Field{}}
t.primaryKeyFields = fieldnames.CommaSeparatedFieldNames(table.PrimaryKey.Fields)
for _, field := range msg.Fields {
t.fields[field.Desc.Name()] = field
}
uniqIndexes := make([]*ormv1alpha1.SecondaryIndexDescriptor, 0)
for _, idx := range t.table.Index {
if idx.Unique {
uniqIndexes = append(uniqIndexes, idx)
}
}
t.uniqueIndexes = uniqIndexes
var err error
t.ormTable, err = ormtable.Build(ormtable.Options{
MessageType: dynamicpb.NewMessageType(msg.Desc),
TableDescriptor: table,
})
if err != nil {
panic(err)
}
return t
}
func (t tableGen) gen() {
t.genStoreInterface()
t.genIterator()
t.genIndexKeys()
t.genStruct()
t.genStoreImpl()
t.genStoreImplGuard()
t.genConstructor()
}
func (t tableGen) genStoreInterface() {
t.P("type ", t.messageStoreInterfaceName(t.msg), " interface {")
t.P("Insert(ctx ", contextPkg.Ident("Context"), ", ", t.param(t.msg.GoIdent.GoName), " *", t.QualifiedGoIdent(t.msg.GoIdent), ") error")
t.P("Update(ctx ", contextPkg.Ident("Context"), ", ", t.param(t.msg.GoIdent.GoName), " *", t.QualifiedGoIdent(t.msg.GoIdent), ") error")
t.P("Save(ctx ", contextPkg.Ident("Context"), ", ", t.param(t.msg.GoIdent.GoName), " *", t.QualifiedGoIdent(t.msg.GoIdent), ") error")
t.P("Delete(ctx ", contextPkg.Ident("Context"), ", ", t.param(t.msg.GoIdent.GoName), " *", t.QualifiedGoIdent(t.msg.GoIdent), ") error")
t.P("Has(ctx ", contextPkg.Ident("Context"), ", ", t.fieldsArgs(t.primaryKeyFields.Names()), ") (found bool, err error)")
t.P("Get(ctx ", contextPkg.Ident("Context"), ", ", t.fieldsArgs(t.primaryKeyFields.Names()), ") (*", t.QualifiedGoIdent(t.msg.GoIdent), ", error)")
for _, idx := range t.uniqueIndexes {
t.genUniqueIndexSig(idx)
}
t.P("List(ctx ", contextPkg.Ident("Context"), ", prefixKey ", t.indexKeyInterfaceName(), ", opts ...", ormListPkg.Ident("Option"), ") ", "(", t.iteratorName(), ", error)")
t.P("ListRange(ctx ", contextPkg.Ident("Context"), ", from, to ", t.indexKeyInterfaceName(), ", opts ...", ormListPkg.Ident("Option"), ") ", "(", t.iteratorName(), ", error)")
t.P()
t.P("doNotImplement()")
t.P("}")
t.P()
}
// returns the has and get (in that order) function signature for unique indexes.
func (t tableGen) uniqueIndexSig(idx *ormv1alpha1.SecondaryIndexDescriptor) (string, string) {
fieldsSlc := strings.Split(idx.Fields, ",")
camelFields := t.fieldsToCamelCase(idx.Fields)
hasFuncName := "HasBy" + camelFields
getFuncName := "GetBy" + camelFields
args := t.fieldArgsFromStringSlice(fieldsSlc)
hasFuncSig := fmt.Sprintf("%s (ctx context.Context, %s) (found bool, err error)", hasFuncName, args)
getFuncSig := fmt.Sprintf("%s (ctx context.Context, %s) (*%s, error)", getFuncName, args, t.msg.GoIdent.GoName)
return hasFuncSig, getFuncSig
}
func (t tableGen) genUniqueIndexSig(idx *ormv1alpha1.SecondaryIndexDescriptor) {
hasSig, getSig := t.uniqueIndexSig(idx)
t.P(hasSig)
t.P(getSig)
}
func (t tableGen) iteratorName() string {
return t.msg.GoIdent.GoName + "Iterator"
}
func (t tableGen) getSig() string {
res := "Get" + t.msg.GoIdent.GoName + "("
res += t.fieldsArgs(t.primaryKeyFields.Names())
res += ") (*" + t.QualifiedGoIdent(t.msg.GoIdent) + ", error)"
return res
}
func (t tableGen) hasSig() string {
t.P("Has(ctx ", contextPkg.Ident("Context"), ", ", t.fieldsArgs(t.primaryKeyFields.Names()), ") (found bool, err error)")
return ""
}
func (t tableGen) listSig() string {
res := "List" + t.msg.GoIdent.GoName + "("
res += t.indexKeyInterfaceName()
res += ") ("
res += t.iteratorName()
res += ", error)"
return res
}
func (t tableGen) fieldArgsFromStringSlice(names []string) string {
args := make([]string, len(names))
for i, name := range names {
args[i] = t.fieldArg(protoreflect.Name(name))
}
return strings.Join(args, ",")
}
func (t tableGen) fieldsArgs(names []protoreflect.Name) string {
var params []string
for _, name := range names {
params = append(params, t.fieldArg(name))
}
return strings.Join(params, ",")
}
func (t tableGen) fieldArg(name protoreflect.Name) string {
typ, pointer := t.GeneratedFile.FieldGoType(t.fields[name])
if pointer {
typ = "*" + typ
}
return string(name) + " " + typ
}
func (t tableGen) genStruct() {
t.P("type ", t.messageStoreReceiverName(t.msg), " struct {")
t.P("table ", tablePkg.Ident("Table"))
t.P("}")
t.storeStructName()
}
func (t tableGen) genStoreImpl() {
receiverVar := "this"
receiver := fmt.Sprintf("func (%s %s) ", receiverVar, t.messageStoreReceiverName(t.msg))
varName := t.param(t.msg.GoIdent.GoName)
varTypeName := t.QualifiedGoIdent(t.msg.GoIdent)
// these methods all have the same impl sans their names. so we can just loop and replace.
methods := []string{"Insert", "Update", "Save", "Delete"}
for _, method := range methods {
t.P(receiver, method, "(ctx ", contextPkg.Ident("Context"), ", ", varName, " *", varTypeName, ") error {")
t.P("return ", receiverVar, ".table.", method, "(ctx, ", varName, ")")
t.P("}")
t.P()
}
// Has
t.P(receiver, "Has(ctx ", contextPkg.Ident("Context"), ", ", t.fieldsArgs(t.primaryKeyFields.Names()), ") (found bool, err error) {")
t.P("return ", receiverVar, ".table.PrimaryKey().Has(ctx, ", t.primaryKeyFields.String(), ")")
t.P("}")
t.P()
// Get
t.P(receiver, "Get(ctx ", contextPkg.Ident("Context"), ", ", t.fieldsArgs(t.primaryKeyFields.Names()), ") (*", varTypeName, ", error) {")
t.P("var ", varName, " ", varTypeName)
t.P("found, err := ", receiverVar, ".table.PrimaryKey().Get(ctx, &", varName, ", ", t.primaryKeyFields.String(), ")")
t.P("if !found {")
t.P("return nil, err")
t.P("}")
t.P("return &", varName, ", err")
t.P("}")
t.P()
for _, idx := range t.uniqueIndexes {
fields := strings.Split(idx.Fields, ",")
hasName, getName := t.uniqueIndexSig(idx)
// has
t.P("func (", receiverVar, " ", t.messageStoreReceiverName(t.msg), ") ", hasName, "{")
t.P("return ", receiverVar, ".table.Has(ctx, &", t.msg.GoIdent.GoName, "{")
for _, field := range fields {
t.P(strcase.ToCamel(field), ": ", field, ",")
}
t.P("})")
t.P("}")
t.P()
// get
varName := t.param(t.msg.GoIdent.GoName)
varTypeName := t.msg.GoIdent.GoName
t.P("func (", receiverVar, " ", t.messageStoreReceiverName(t.msg), ") ", getName, "{")
t.P(varName, " := &", varTypeName, "{")
for _, field := range fields {
t.P(strcase.ToCamel(field), ": ", field, ",")
}
t.P("}")
t.P("found, err := ", receiverVar, ".table.Get(ctx, ", varName, ")")
t.P("if !found {")
t.P("return nil, err")
t.P("}")
t.P("return ", varName, ", nil")
t.P("}")
t.P()
}
// List
t.P(receiver, "List(ctx ", contextPkg.Ident("Context"), ", prefixKey ", t.indexKeyInterfaceName(), ", opts ...", ormListPkg.Ident("Option"), ") (", t.iteratorName(), ", error) {")
t.P("opts = append(opts, ", ormListPkg.Ident("Prefix"), "(prefixKey.values()))")
t.P("it, err := ", receiverVar, ".table.GetIndexByID(prefixKey.id()).Iterator(ctx, opts...)")
t.P("return ", t.iteratorName(), "{it}, err")
t.P("}")
t.P()
// ListRange
t.P(receiver, "ListRange(ctx ", contextPkg.Ident("Context"), ", from, to ", t.indexKeyInterfaceName(), ", opts ...", ormListPkg.Ident("Option"), ") (", t.iteratorName(), ", error) {")
t.P("opts = append(opts, ", ormListPkg.Ident("Start"), "(from.values()), ", ormListPkg.Ident("End"), "(to))")
t.P("it, err := ", receiverVar, ".table.GetIndexByID(from.id()).Iterator(ctx, opts...)")
t.P("return ", t.iteratorName(), "{it}, err")
t.P("}")
t.P()
t.P(receiver, "doNotImplement() {}")
t.P()
}
func (t tableGen) genStoreImplGuard() {
t.P("var _ ", t.messageStoreInterfaceName(t.msg), " = ", t.messageStoreReceiverName(t.msg), "{}")
}
func (t tableGen) genConstructor() {
iface := t.messageStoreInterfaceName(t.msg)
t.P("func New", iface, "(db ", ormdbPkg.Ident("ModuleDB"), ") (", iface, ", error) {")
t.P("table := db.GetTable(&", t.msg.GoIdent.GoName, "{})")
t.P("if table == nil {")
t.P("return nil,", ormErrPkg.Ident("TableNotFound.Wrap"), "(string((&", t.msg.GoIdent.GoName, "{}).ProtoReflect().Descriptor().FullName()))")
t.P("}")
t.P("return ", t.messageStoreReceiverName(t.msg), "{table}, nil")
t.P("}")
}

View File

@ -1,4 +1,4 @@
package ormtable
package fieldnames
import (
"strings"
@ -6,15 +6,15 @@ import (
"google.golang.org/protobuf/reflect/protoreflect"
)
// fieldNames abstractly represents a list of fields with a comparable type which
// FieldNames abstractly represents a list of fields with a comparable type which
// can be used as a map key. It is used primarily to lookup indexes.
type fieldNames struct {
type FieldNames struct {
fields string
}
// commaSeparatedFieldNames creates a fieldNames instance from a list of comma-separated
// CommaSeparatedFieldNames creates a FieldNames instance from a list of comma-separated
// fields.
func commaSeparatedFieldNames(fields string) fieldNames {
func CommaSeparatedFieldNames(fields string) FieldNames {
// normalize cases where there are spaces
if strings.IndexByte(fields, ' ') >= 0 {
parts := strings.Split(fields, ",")
@ -23,21 +23,21 @@ func commaSeparatedFieldNames(fields string) fieldNames {
}
fields = strings.Join(parts, ",")
}
return fieldNames{fields: fields}
return FieldNames{fields: fields}
}
// fieldsFromNames creates a fieldNames instance from an array of field
// FieldsFromNames creates a FieldNames instance from an array of field
// names.
func fieldsFromNames(fnames []protoreflect.Name) fieldNames {
func FieldsFromNames(fnames []protoreflect.Name) FieldNames {
var names []string
for _, name := range fnames {
names = append(names, string(name))
}
return fieldNames{fields: strings.Join(names, ",")}
return FieldNames{fields: strings.Join(names, ",")}
}
// Names returns the array of names this fieldNames instance represents.
func (f fieldNames) Names() []protoreflect.Name {
// Names returns the array of names this FieldNames instance represents.
func (f FieldNames) Names() []protoreflect.Name {
if f.fields == "" {
return nil
}
@ -50,6 +50,6 @@ func (f fieldNames) Names() []protoreflect.Name {
return names
}
func (f fieldNames) String() string {
func (f FieldNames) String() string {
return f.fields
}

View File

@ -1,4 +1,4 @@
package ormtable
package fieldnames
import (
"testing"
@ -12,32 +12,32 @@ func TestFieldNames(t *testing.T) {
names := []protoreflect.Name{"a", "b", "c"}
abc := "a,b,c"
f := commaSeparatedFieldNames(abc)
assert.Equal(t, fieldNames{abc}, f)
f := CommaSeparatedFieldNames(abc)
assert.Equal(t, FieldNames{abc}, f)
assert.DeepEqual(t, names, f.Names())
assert.Equal(t, abc, f.String())
f = commaSeparatedFieldNames("a, b ,c")
assert.Equal(t, fieldNames{abc}, f)
f = CommaSeparatedFieldNames("a, b ,c")
assert.Equal(t, FieldNames{abc}, f)
assert.DeepEqual(t, names, f.Names())
assert.Equal(t, abc, f.String())
// empty okay
f = commaSeparatedFieldNames("")
assert.Equal(t, fieldNames{""}, f)
f = CommaSeparatedFieldNames("")
assert.Equal(t, FieldNames{""}, f)
assert.Equal(t, 0, len(f.Names()))
assert.Equal(t, "", f.String())
f = fieldsFromNames(names)
assert.Equal(t, fieldNames{abc}, f)
f = FieldsFromNames(names)
assert.Equal(t, FieldNames{abc}, f)
assert.DeepEqual(t, names, f.Names())
assert.Equal(t, abc, f.String())
// empty okay
f = fieldsFromNames([]protoreflect.Name{})
assert.Equal(t, fieldNames{""}, f)
f = fieldsFromNames(nil)
assert.Equal(t, fieldNames{""}, f)
f = FieldsFromNames([]protoreflect.Name{})
assert.Equal(t, FieldNames{""}, f)
f = FieldsFromNames(nil)
assert.Equal(t, FieldNames{""}, f)
assert.Equal(t, 0, len(f.Names()))
assert.Equal(t, "", f.String())
}

View File

@ -0,0 +1,270 @@
// Code generated by protoc-gen-go-cosmos-orm. DO NOT EDIT.
package testpb
import (
context "context"
ormdb "github.com/cosmos/cosmos-sdk/orm/model/ormdb"
ormlist "github.com/cosmos/cosmos-sdk/orm/model/ormlist"
ormtable "github.com/cosmos/cosmos-sdk/orm/model/ormtable"
ormerrors "github.com/cosmos/cosmos-sdk/orm/types/ormerrors"
)
type BalanceStore interface {
Insert(ctx context.Context, balance *Balance) error
Update(ctx context.Context, balance *Balance) error
Save(ctx context.Context, balance *Balance) error
Delete(ctx context.Context, balance *Balance) error
Has(ctx context.Context, address string, denom string) (found bool, err error)
Get(ctx context.Context, address string, denom string) (*Balance, error)
List(ctx context.Context, prefixKey BalanceIndexKey, opts ...ormlist.Option) (BalanceIterator, error)
ListRange(ctx context.Context, from, to BalanceIndexKey, opts ...ormlist.Option) (BalanceIterator, error)
doNotImplement()
}
type BalanceIterator struct {
ormtable.Iterator
}
func (i BalanceIterator) Value() (*Balance, error) {
var balance Balance
err := i.UnmarshalMessage(&balance)
return &balance, err
}
type BalanceIndexKey interface {
id() uint32
values() []interface{}
balanceIndexKey()
}
// primary key starting index..
type BalanceAddressDenomIndexKey struct {
vs []interface{}
}
func (x BalanceAddressDenomIndexKey) id() uint32 { return 1 }
func (x BalanceAddressDenomIndexKey) values() []interface{} { return x.vs }
func (x BalanceAddressDenomIndexKey) balanceIndexKey() {}
func (this BalanceAddressDenomIndexKey) WithAddress(address string) BalanceAddressDenomIndexKey {
this.vs = []interface{}{address}
return this
}
func (this BalanceAddressDenomIndexKey) WithAddressDenom(address string, denom string) BalanceAddressDenomIndexKey {
this.vs = []interface{}{address, denom}
return this
}
type BalanceDenomIndexKey struct {
vs []interface{}
}
func (x BalanceDenomIndexKey) id() uint32 { return 1 }
func (x BalanceDenomIndexKey) values() []interface{} { return x.vs }
func (x BalanceDenomIndexKey) balanceIndexKey() {}
func (this BalanceDenomIndexKey) WithDenom(denom string) BalanceDenomIndexKey {
this.vs = []interface{}{denom}
return this
}
type balanceStore struct {
table ormtable.Table
}
func (this balanceStore) Insert(ctx context.Context, balance *Balance) error {
return this.table.Insert(ctx, balance)
}
func (this balanceStore) Update(ctx context.Context, balance *Balance) error {
return this.table.Update(ctx, balance)
}
func (this balanceStore) Save(ctx context.Context, balance *Balance) error {
return this.table.Save(ctx, balance)
}
func (this balanceStore) Delete(ctx context.Context, balance *Balance) error {
return this.table.Delete(ctx, balance)
}
func (this balanceStore) Has(ctx context.Context, address string, denom string) (found bool, err error) {
return this.table.PrimaryKey().Has(ctx, address, denom)
}
func (this balanceStore) Get(ctx context.Context, address string, denom string) (*Balance, error) {
var balance Balance
found, err := this.table.PrimaryKey().Get(ctx, &balance, address, denom)
if !found {
return nil, err
}
return &balance, err
}
func (this balanceStore) List(ctx context.Context, prefixKey BalanceIndexKey, opts ...ormlist.Option) (BalanceIterator, error) {
opts = append(opts, ormlist.Prefix(prefixKey.values()))
it, err := this.table.GetIndexByID(prefixKey.id()).Iterator(ctx, opts...)
return BalanceIterator{it}, err
}
func (this balanceStore) ListRange(ctx context.Context, from, to BalanceIndexKey, opts ...ormlist.Option) (BalanceIterator, error) {
opts = append(opts, ormlist.Start(from.values()), ormlist.End(to))
it, err := this.table.GetIndexByID(from.id()).Iterator(ctx, opts...)
return BalanceIterator{it}, err
}
func (this balanceStore) doNotImplement() {}
var _ BalanceStore = balanceStore{}
func NewBalanceStore(db ormdb.ModuleDB) (BalanceStore, error) {
table := db.GetTable(&Balance{})
if table == nil {
return nil, ormerrors.TableNotFound.Wrap(string((&Balance{}).ProtoReflect().Descriptor().FullName()))
}
return balanceStore{table}, nil
}
type SupplyStore interface {
Insert(ctx context.Context, supply *Supply) error
Update(ctx context.Context, supply *Supply) error
Save(ctx context.Context, supply *Supply) error
Delete(ctx context.Context, supply *Supply) error
Has(ctx context.Context, denom string) (found bool, err error)
Get(ctx context.Context, denom string) (*Supply, error)
List(ctx context.Context, prefixKey SupplyIndexKey, opts ...ormlist.Option) (SupplyIterator, error)
ListRange(ctx context.Context, from, to SupplyIndexKey, opts ...ormlist.Option) (SupplyIterator, error)
doNotImplement()
}
type SupplyIterator struct {
ormtable.Iterator
}
func (i SupplyIterator) Value() (*Supply, error) {
var supply Supply
err := i.UnmarshalMessage(&supply)
return &supply, err
}
type SupplyIndexKey interface {
id() uint32
values() []interface{}
supplyIndexKey()
}
// primary key starting index..
type SupplyDenomIndexKey struct {
vs []interface{}
}
func (x SupplyDenomIndexKey) id() uint32 { return 2 }
func (x SupplyDenomIndexKey) values() []interface{} { return x.vs }
func (x SupplyDenomIndexKey) supplyIndexKey() {}
func (this SupplyDenomIndexKey) WithDenom(denom string) SupplyDenomIndexKey {
this.vs = []interface{}{denom}
return this
}
type supplyStore struct {
table ormtable.Table
}
func (this supplyStore) Insert(ctx context.Context, supply *Supply) error {
return this.table.Insert(ctx, supply)
}
func (this supplyStore) Update(ctx context.Context, supply *Supply) error {
return this.table.Update(ctx, supply)
}
func (this supplyStore) Save(ctx context.Context, supply *Supply) error {
return this.table.Save(ctx, supply)
}
func (this supplyStore) Delete(ctx context.Context, supply *Supply) error {
return this.table.Delete(ctx, supply)
}
func (this supplyStore) Has(ctx context.Context, denom string) (found bool, err error) {
return this.table.PrimaryKey().Has(ctx, denom)
}
func (this supplyStore) Get(ctx context.Context, denom string) (*Supply, error) {
var supply Supply
found, err := this.table.PrimaryKey().Get(ctx, &supply, denom)
if !found {
return nil, err
}
return &supply, err
}
func (this supplyStore) List(ctx context.Context, prefixKey SupplyIndexKey, opts ...ormlist.Option) (SupplyIterator, error) {
opts = append(opts, ormlist.Prefix(prefixKey.values()))
it, err := this.table.GetIndexByID(prefixKey.id()).Iterator(ctx, opts...)
return SupplyIterator{it}, err
}
func (this supplyStore) ListRange(ctx context.Context, from, to SupplyIndexKey, opts ...ormlist.Option) (SupplyIterator, error) {
opts = append(opts, ormlist.Start(from.values()), ormlist.End(to))
it, err := this.table.GetIndexByID(from.id()).Iterator(ctx, opts...)
return SupplyIterator{it}, err
}
func (this supplyStore) doNotImplement() {}
var _ SupplyStore = supplyStore{}
func NewSupplyStore(db ormdb.ModuleDB) (SupplyStore, error) {
table := db.GetTable(&Supply{})
if table == nil {
return nil, ormerrors.TableNotFound.Wrap(string((&Supply{}).ProtoReflect().Descriptor().FullName()))
}
return supplyStore{table}, nil
}
type BankStore interface {
BalanceStore() BalanceStore
SupplyStore() SupplyStore
doNotImplement()
}
type bankStore struct {
balance BalanceStore
supply SupplyStore
}
func (x bankStore) BalanceStore() BalanceStore {
return x.balance
}
func (x bankStore) SupplyStore() SupplyStore {
return x.supply
}
func (bankStore) doNotImplement() {}
var _ BankStore = bankStore{}
func NewBankStore(db ormdb.ModuleDB) (BankStore, error) {
balanceStore, err := NewBalanceStore(db)
if err != nil {
return nil, err
}
supplyStore, err := NewSupplyStore(db)
if err != nil {
return nil, err
}
return bankStore{
balanceStore,
supplyStore,
}, nil
}

View File

@ -4,8 +4,6 @@ package testpb;
import "cosmos/orm/v1alpha1/orm.proto";
option go_package = "github.com/cosmos/cosmos-sdk/orm/internal/testpb";
// This is a simulated bank schema used for testing.
message Balance {

View File

@ -0,0 +1,414 @@
// Code generated by protoc-gen-go-cosmos-orm. DO NOT EDIT.
package testpb
import (
context "context"
ormdb "github.com/cosmos/cosmos-sdk/orm/model/ormdb"
ormlist "github.com/cosmos/cosmos-sdk/orm/model/ormlist"
ormtable "github.com/cosmos/cosmos-sdk/orm/model/ormtable"
ormerrors "github.com/cosmos/cosmos-sdk/orm/types/ormerrors"
)
type ExampleTableStore interface {
Insert(ctx context.Context, exampleTable *ExampleTable) error
Update(ctx context.Context, exampleTable *ExampleTable) error
Save(ctx context.Context, exampleTable *ExampleTable) error
Delete(ctx context.Context, exampleTable *ExampleTable) error
Has(ctx context.Context, u32 uint32, i64 int64, str string) (found bool, err error)
Get(ctx context.Context, u32 uint32, i64 int64, str string) (*ExampleTable, error)
HasByU64Str(ctx context.Context, u64 uint64, str string) (found bool, err error)
GetByU64Str(ctx context.Context, u64 uint64, str string) (*ExampleTable, error)
List(ctx context.Context, prefixKey ExampleTableIndexKey, opts ...ormlist.Option) (ExampleTableIterator, error)
ListRange(ctx context.Context, from, to ExampleTableIndexKey, opts ...ormlist.Option) (ExampleTableIterator, error)
doNotImplement()
}
type ExampleTableIterator struct {
ormtable.Iterator
}
func (i ExampleTableIterator) Value() (*ExampleTable, error) {
var exampleTable ExampleTable
err := i.UnmarshalMessage(&exampleTable)
return &exampleTable, err
}
type ExampleTableIndexKey interface {
id() uint32
values() []interface{}
exampleTableIndexKey()
}
// primary key starting index..
type ExampleTableU32I64StrIndexKey struct {
vs []interface{}
}
func (x ExampleTableU32I64StrIndexKey) id() uint32 { return 1 }
func (x ExampleTableU32I64StrIndexKey) values() []interface{} { return x.vs }
func (x ExampleTableU32I64StrIndexKey) exampleTableIndexKey() {}
func (this ExampleTableU32I64StrIndexKey) WithU32(u32 uint32) ExampleTableU32I64StrIndexKey {
this.vs = []interface{}{u32}
return this
}
func (this ExampleTableU32I64StrIndexKey) WithU32I64(u32 uint32, i64 int64) ExampleTableU32I64StrIndexKey {
this.vs = []interface{}{u32, i64}
return this
}
func (this ExampleTableU32I64StrIndexKey) WithU32I64Str(u32 uint32, i64 int64, str string) ExampleTableU32I64StrIndexKey {
this.vs = []interface{}{u32, i64, str}
return this
}
type ExampleTableU64StrIndexKey struct {
vs []interface{}
}
func (x ExampleTableU64StrIndexKey) id() uint32 { return 1 }
func (x ExampleTableU64StrIndexKey) values() []interface{} { return x.vs }
func (x ExampleTableU64StrIndexKey) exampleTableIndexKey() {}
func (this ExampleTableU64StrIndexKey) WithU64(u64 uint64) ExampleTableU64StrIndexKey {
this.vs = []interface{}{u64}
return this
}
func (this ExampleTableU64StrIndexKey) WithU64Str(u64 uint64, str string) ExampleTableU64StrIndexKey {
this.vs = []interface{}{u64, str}
return this
}
type ExampleTableStrU32IndexKey struct {
vs []interface{}
}
func (x ExampleTableStrU32IndexKey) id() uint32 { return 2 }
func (x ExampleTableStrU32IndexKey) values() []interface{} { return x.vs }
func (x ExampleTableStrU32IndexKey) exampleTableIndexKey() {}
func (this ExampleTableStrU32IndexKey) WithStr(str string) ExampleTableStrU32IndexKey {
this.vs = []interface{}{str}
return this
}
func (this ExampleTableStrU32IndexKey) WithStrU32(str string, u32 uint32) ExampleTableStrU32IndexKey {
this.vs = []interface{}{str, u32}
return this
}
type ExampleTableBzStrIndexKey struct {
vs []interface{}
}
func (x ExampleTableBzStrIndexKey) id() uint32 { return 3 }
func (x ExampleTableBzStrIndexKey) values() []interface{} { return x.vs }
func (x ExampleTableBzStrIndexKey) exampleTableIndexKey() {}
func (this ExampleTableBzStrIndexKey) WithBz(bz []byte) ExampleTableBzStrIndexKey {
this.vs = []interface{}{bz}
return this
}
func (this ExampleTableBzStrIndexKey) WithBzStr(bz []byte, str string) ExampleTableBzStrIndexKey {
this.vs = []interface{}{bz, str}
return this
}
type exampleTableStore struct {
table ormtable.Table
}
func (this exampleTableStore) Insert(ctx context.Context, exampleTable *ExampleTable) error {
return this.table.Insert(ctx, exampleTable)
}
func (this exampleTableStore) Update(ctx context.Context, exampleTable *ExampleTable) error {
return this.table.Update(ctx, exampleTable)
}
func (this exampleTableStore) Save(ctx context.Context, exampleTable *ExampleTable) error {
return this.table.Save(ctx, exampleTable)
}
func (this exampleTableStore) Delete(ctx context.Context, exampleTable *ExampleTable) error {
return this.table.Delete(ctx, exampleTable)
}
func (this exampleTableStore) Has(ctx context.Context, u32 uint32, i64 int64, str string) (found bool, err error) {
return this.table.PrimaryKey().Has(ctx, u32, i64, str)
}
func (this exampleTableStore) Get(ctx context.Context, u32 uint32, i64 int64, str string) (*ExampleTable, error) {
var exampleTable ExampleTable
found, err := this.table.PrimaryKey().Get(ctx, &exampleTable, u32, i64, str)
if !found {
return nil, err
}
return &exampleTable, err
}
func (this exampleTableStore) HasByU64Str(ctx context.Context, u64 uint64, str string) (found bool, err error) {
return this.table.Has(ctx, &ExampleTable{
U64: u64,
Str: str,
})
}
func (this exampleTableStore) GetByU64Str(ctx context.Context, u64 uint64, str string) (*ExampleTable, error) {
exampleTable := &ExampleTable{
U64: u64,
Str: str,
}
found, err := this.table.Get(ctx, exampleTable)
if !found {
return nil, err
}
return exampleTable, nil
}
func (this exampleTableStore) List(ctx context.Context, prefixKey ExampleTableIndexKey, opts ...ormlist.Option) (ExampleTableIterator, error) {
opts = append(opts, ormlist.Prefix(prefixKey.values()))
it, err := this.table.GetIndexByID(prefixKey.id()).Iterator(ctx, opts...)
return ExampleTableIterator{it}, err
}
func (this exampleTableStore) ListRange(ctx context.Context, from, to ExampleTableIndexKey, opts ...ormlist.Option) (ExampleTableIterator, error) {
opts = append(opts, ormlist.Start(from.values()), ormlist.End(to))
it, err := this.table.GetIndexByID(from.id()).Iterator(ctx, opts...)
return ExampleTableIterator{it}, err
}
func (this exampleTableStore) doNotImplement() {}
var _ ExampleTableStore = exampleTableStore{}
func NewExampleTableStore(db ormdb.ModuleDB) (ExampleTableStore, error) {
table := db.GetTable(&ExampleTable{})
if table == nil {
return nil, ormerrors.TableNotFound.Wrap(string((&ExampleTable{}).ProtoReflect().Descriptor().FullName()))
}
return exampleTableStore{table}, nil
}
type ExampleAutoIncrementTableStore interface {
Insert(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error
Update(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error
Save(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error
Delete(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error
Has(ctx context.Context, id uint64) (found bool, err error)
Get(ctx context.Context, id uint64) (*ExampleAutoIncrementTable, error)
HasByX(ctx context.Context, x string) (found bool, err error)
GetByX(ctx context.Context, x string) (*ExampleAutoIncrementTable, error)
List(ctx context.Context, prefixKey ExampleAutoIncrementTableIndexKey, opts ...ormlist.Option) (ExampleAutoIncrementTableIterator, error)
ListRange(ctx context.Context, from, to ExampleAutoIncrementTableIndexKey, opts ...ormlist.Option) (ExampleAutoIncrementTableIterator, error)
doNotImplement()
}
type ExampleAutoIncrementTableIterator struct {
ormtable.Iterator
}
func (i ExampleAutoIncrementTableIterator) Value() (*ExampleAutoIncrementTable, error) {
var exampleAutoIncrementTable ExampleAutoIncrementTable
err := i.UnmarshalMessage(&exampleAutoIncrementTable)
return &exampleAutoIncrementTable, err
}
type ExampleAutoIncrementTableIndexKey interface {
id() uint32
values() []interface{}
exampleAutoIncrementTableIndexKey()
}
// primary key starting index..
type ExampleAutoIncrementTableIdIndexKey struct {
vs []interface{}
}
func (x ExampleAutoIncrementTableIdIndexKey) id() uint32 { return 3 }
func (x ExampleAutoIncrementTableIdIndexKey) values() []interface{} { return x.vs }
func (x ExampleAutoIncrementTableIdIndexKey) exampleAutoIncrementTableIndexKey() {}
func (this ExampleAutoIncrementTableIdIndexKey) WithId(id uint64) ExampleAutoIncrementTableIdIndexKey {
this.vs = []interface{}{id}
return this
}
type ExampleAutoIncrementTableXIndexKey struct {
vs []interface{}
}
func (x ExampleAutoIncrementTableXIndexKey) id() uint32 { return 1 }
func (x ExampleAutoIncrementTableXIndexKey) values() []interface{} { return x.vs }
func (x ExampleAutoIncrementTableXIndexKey) exampleAutoIncrementTableIndexKey() {}
func (this ExampleAutoIncrementTableXIndexKey) WithX(x string) ExampleAutoIncrementTableXIndexKey {
this.vs = []interface{}{x}
return this
}
type exampleAutoIncrementTableStore struct {
table ormtable.Table
}
func (this exampleAutoIncrementTableStore) Insert(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error {
return this.table.Insert(ctx, exampleAutoIncrementTable)
}
func (this exampleAutoIncrementTableStore) Update(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error {
return this.table.Update(ctx, exampleAutoIncrementTable)
}
func (this exampleAutoIncrementTableStore) Save(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error {
return this.table.Save(ctx, exampleAutoIncrementTable)
}
func (this exampleAutoIncrementTableStore) Delete(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error {
return this.table.Delete(ctx, exampleAutoIncrementTable)
}
func (this exampleAutoIncrementTableStore) Has(ctx context.Context, id uint64) (found bool, err error) {
return this.table.PrimaryKey().Has(ctx, id)
}
func (this exampleAutoIncrementTableStore) Get(ctx context.Context, id uint64) (*ExampleAutoIncrementTable, error) {
var exampleAutoIncrementTable ExampleAutoIncrementTable
found, err := this.table.PrimaryKey().Get(ctx, &exampleAutoIncrementTable, id)
if !found {
return nil, err
}
return &exampleAutoIncrementTable, err
}
func (this exampleAutoIncrementTableStore) HasByX(ctx context.Context, x string) (found bool, err error) {
return this.table.Has(ctx, &ExampleAutoIncrementTable{
X: x,
})
}
func (this exampleAutoIncrementTableStore) GetByX(ctx context.Context, x string) (*ExampleAutoIncrementTable, error) {
exampleAutoIncrementTable := &ExampleAutoIncrementTable{
X: x,
}
found, err := this.table.Get(ctx, exampleAutoIncrementTable)
if !found {
return nil, err
}
return exampleAutoIncrementTable, nil
}
func (this exampleAutoIncrementTableStore) List(ctx context.Context, prefixKey ExampleAutoIncrementTableIndexKey, opts ...ormlist.Option) (ExampleAutoIncrementTableIterator, error) {
opts = append(opts, ormlist.Prefix(prefixKey.values()))
it, err := this.table.GetIndexByID(prefixKey.id()).Iterator(ctx, opts...)
return ExampleAutoIncrementTableIterator{it}, err
}
func (this exampleAutoIncrementTableStore) ListRange(ctx context.Context, from, to ExampleAutoIncrementTableIndexKey, opts ...ormlist.Option) (ExampleAutoIncrementTableIterator, error) {
opts = append(opts, ormlist.Start(from.values()), ormlist.End(to))
it, err := this.table.GetIndexByID(from.id()).Iterator(ctx, opts...)
return ExampleAutoIncrementTableIterator{it}, err
}
func (this exampleAutoIncrementTableStore) doNotImplement() {}
var _ ExampleAutoIncrementTableStore = exampleAutoIncrementTableStore{}
func NewExampleAutoIncrementTableStore(db ormdb.ModuleDB) (ExampleAutoIncrementTableStore, error) {
table := db.GetTable(&ExampleAutoIncrementTable{})
if table == nil {
return nil, ormerrors.TableNotFound.Wrap(string((&ExampleAutoIncrementTable{}).ProtoReflect().Descriptor().FullName()))
}
return exampleAutoIncrementTableStore{table}, nil
}
// singleton store
type ExampleSingletonStore interface {
Get(ctx context.Context) (*ExampleSingleton, error)
Save(ctx context.Context, exampleSingleton *ExampleSingleton) error
}
type exampleSingletonStore struct {
table ormtable.Table
}
var _ ExampleSingletonStore = exampleSingletonStore{}
func (x exampleSingletonStore) Get(ctx context.Context) (*ExampleSingleton, error) {
var exampleSingleton ExampleSingleton
found, err := x.table.Get(ctx, &exampleSingleton)
if !found {
return nil, err
}
return &exampleSingleton, err
}
func (x exampleSingletonStore) Save(ctx context.Context, exampleSingleton *ExampleSingleton) error {
return x.table.Save(ctx, exampleSingleton)
}
func NewExampleSingletonStore(db ormdb.ModuleDB) (ExampleSingletonStore, error) {
table := db.GetTable(&ExampleSingleton{})
if table == nil {
return nil, ormerrors.TableNotFound.Wrap(string((&ExampleSingleton{}).ProtoReflect().Descriptor().FullName()))
}
return &exampleSingletonStore{table}, nil
}
type TestSchemaStore interface {
ExampleTableStore() ExampleTableStore
ExampleAutoIncrementTableStore() ExampleAutoIncrementTableStore
ExampleSingletonStore() ExampleSingletonStore
doNotImplement()
}
type testSchemaStore struct {
exampleTable ExampleTableStore
exampleAutoIncrementTable ExampleAutoIncrementTableStore
exampleSingleton ExampleSingletonStore
}
func (x testSchemaStore) ExampleTableStore() ExampleTableStore {
return x.exampleTable
}
func (x testSchemaStore) ExampleAutoIncrementTableStore() ExampleAutoIncrementTableStore {
return x.exampleAutoIncrementTable
}
func (x testSchemaStore) ExampleSingletonStore() ExampleSingletonStore {
return x.exampleSingleton
}
func (testSchemaStore) doNotImplement() {}
var _ TestSchemaStore = testSchemaStore{}
func NewTestSchemaStore(db ormdb.ModuleDB) (TestSchemaStore, error) {
exampleTableStore, err := NewExampleTableStore(db)
if err != nil {
return nil, err
}
exampleAutoIncrementTableStore, err := NewExampleAutoIncrementTableStore(db)
if err != nil {
return nil, err
}
exampleSingletonStore, err := NewExampleSingletonStore(db)
if err != nil {
return nil, err
}
return testSchemaStore{
exampleTableStore,
exampleAutoIncrementTableStore,
exampleSingletonStore,
}, nil
}

View File

@ -6,8 +6,6 @@ import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto";
import "cosmos/orm/v1alpha1/orm.proto";
option go_package = "github.com/cosmos/cosmos-sdk/orm/internal/testpb";
message ExampleTable {
option (cosmos.orm.v1alpha1.table) = {
id: 1;

View File

@ -169,8 +169,8 @@ var (
)
func init() {
file_testpb_testschema_proto_init()
md_ExampleTable = File_testpb_testschema_proto.Messages().ByName("ExampleTable")
file_testpb_test_schema_proto_init()
md_ExampleTable = File_testpb_test_schema_proto.Messages().ByName("ExampleTable")
fd_ExampleTable_u32 = md_ExampleTable.Fields().ByName("u32")
fd_ExampleTable_u64 = md_ExampleTable.Fields().ByName("u64")
fd_ExampleTable_str = md_ExampleTable.Fields().ByName("str")
@ -202,7 +202,7 @@ func (x *ExampleTable) ProtoReflect() protoreflect.Message {
}
func (x *ExampleTable) slowProtoReflect() protoreflect.Message {
mi := &file_testpb_testschema_proto_msgTypes[0]
mi := &file_testpb_test_schema_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -1856,8 +1856,8 @@ var (
)
func init() {
file_testpb_testschema_proto_init()
md_ExampleTable_ExampleMessage = File_testpb_testschema_proto.Messages().ByName("ExampleTable").Messages().ByName("ExampleMessage")
file_testpb_test_schema_proto_init()
md_ExampleTable_ExampleMessage = File_testpb_test_schema_proto.Messages().ByName("ExampleTable").Messages().ByName("ExampleMessage")
fd_ExampleTable_ExampleMessage_foo = md_ExampleTable_ExampleMessage.Fields().ByName("foo")
fd_ExampleTable_ExampleMessage_bar = md_ExampleTable_ExampleMessage.Fields().ByName("bar")
}
@ -1871,7 +1871,7 @@ func (x *ExampleTable_ExampleMessage) ProtoReflect() protoreflect.Message {
}
func (x *ExampleTable_ExampleMessage) slowProtoReflect() protoreflect.Message {
mi := &file_testpb_testschema_proto_msgTypes[4]
mi := &file_testpb_test_schema_proto_msgTypes[4]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -2325,8 +2325,8 @@ var (
)
func init() {
file_testpb_testschema_proto_init()
md_ExampleAutoIncrementTable = File_testpb_testschema_proto.Messages().ByName("ExampleAutoIncrementTable")
file_testpb_test_schema_proto_init()
md_ExampleAutoIncrementTable = File_testpb_test_schema_proto.Messages().ByName("ExampleAutoIncrementTable")
fd_ExampleAutoIncrementTable_id = md_ExampleAutoIncrementTable.Fields().ByName("id")
fd_ExampleAutoIncrementTable_x = md_ExampleAutoIncrementTable.Fields().ByName("x")
fd_ExampleAutoIncrementTable_y = md_ExampleAutoIncrementTable.Fields().ByName("y")
@ -2341,7 +2341,7 @@ func (x *ExampleAutoIncrementTable) ProtoReflect() protoreflect.Message {
}
func (x *ExampleAutoIncrementTable) slowProtoReflect() protoreflect.Message {
mi := &file_testpb_testschema_proto_msgTypes[1]
mi := &file_testpb_test_schema_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -2840,8 +2840,8 @@ var (
)
func init() {
file_testpb_testschema_proto_init()
md_ExampleSingleton = File_testpb_testschema_proto.Messages().ByName("ExampleSingleton")
file_testpb_test_schema_proto_init()
md_ExampleSingleton = File_testpb_test_schema_proto.Messages().ByName("ExampleSingleton")
fd_ExampleSingleton_foo = md_ExampleSingleton.Fields().ByName("foo")
fd_ExampleSingleton_bar = md_ExampleSingleton.Fields().ByName("bar")
}
@ -2855,7 +2855,7 @@ func (x *ExampleSingleton) ProtoReflect() protoreflect.Message {
}
func (x *ExampleSingleton) slowProtoReflect() protoreflect.Message {
mi := &file_testpb_testschema_proto_msgTypes[2]
mi := &file_testpb_test_schema_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -3305,7 +3305,7 @@ func (x *fastReflection_ExampleSingleton) ProtoMethods() *protoiface.Methods {
// versions:
// protoc-gen-go v1.27.0
// protoc (unknown)
// source: testpb/testschema.proto
// source: testpb/test_schema.proto
const (
// Verify that this generated code is sufficiently up-to-date.
@ -3353,11 +3353,11 @@ func (x Enum) String() string {
}
func (Enum) Descriptor() protoreflect.EnumDescriptor {
return file_testpb_testschema_proto_enumTypes[0].Descriptor()
return file_testpb_test_schema_proto_enumTypes[0].Descriptor()
}
func (Enum) Type() protoreflect.EnumType {
return &file_testpb_testschema_proto_enumTypes[0]
return &file_testpb_test_schema_proto_enumTypes[0]
}
func (x Enum) Number() protoreflect.EnumNumber {
@ -3366,7 +3366,7 @@ func (x Enum) Number() protoreflect.EnumNumber {
// Deprecated: Use Enum.Descriptor instead.
func (Enum) EnumDescriptor() ([]byte, []int) {
return file_testpb_testschema_proto_rawDescGZIP(), []int{0}
return file_testpb_test_schema_proto_rawDescGZIP(), []int{0}
}
type ExampleTable struct {
@ -3403,7 +3403,7 @@ type ExampleTable struct {
func (x *ExampleTable) Reset() {
*x = ExampleTable{}
if protoimpl.UnsafeEnabled {
mi := &file_testpb_testschema_proto_msgTypes[0]
mi := &file_testpb_test_schema_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -3417,7 +3417,7 @@ func (*ExampleTable) ProtoMessage() {}
// Deprecated: Use ExampleTable.ProtoReflect.Descriptor instead.
func (*ExampleTable) Descriptor() ([]byte, []int) {
return file_testpb_testschema_proto_rawDescGZIP(), []int{0}
return file_testpb_test_schema_proto_rawDescGZIP(), []int{0}
}
func (x *ExampleTable) GetU32() uint32 {
@ -3590,7 +3590,7 @@ type ExampleAutoIncrementTable struct {
func (x *ExampleAutoIncrementTable) Reset() {
*x = ExampleAutoIncrementTable{}
if protoimpl.UnsafeEnabled {
mi := &file_testpb_testschema_proto_msgTypes[1]
mi := &file_testpb_test_schema_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -3604,7 +3604,7 @@ func (*ExampleAutoIncrementTable) ProtoMessage() {}
// Deprecated: Use ExampleAutoIncrementTable.ProtoReflect.Descriptor instead.
func (*ExampleAutoIncrementTable) Descriptor() ([]byte, []int) {
return file_testpb_testschema_proto_rawDescGZIP(), []int{1}
return file_testpb_test_schema_proto_rawDescGZIP(), []int{1}
}
func (x *ExampleAutoIncrementTable) GetId() uint64 {
@ -3640,7 +3640,7 @@ type ExampleSingleton struct {
func (x *ExampleSingleton) Reset() {
*x = ExampleSingleton{}
if protoimpl.UnsafeEnabled {
mi := &file_testpb_testschema_proto_msgTypes[2]
mi := &file_testpb_test_schema_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -3654,7 +3654,7 @@ func (*ExampleSingleton) ProtoMessage() {}
// Deprecated: Use ExampleSingleton.ProtoReflect.Descriptor instead.
func (*ExampleSingleton) Descriptor() ([]byte, []int) {
return file_testpb_testschema_proto_rawDescGZIP(), []int{2}
return file_testpb_test_schema_proto_rawDescGZIP(), []int{2}
}
func (x *ExampleSingleton) GetFoo() string {
@ -3683,7 +3683,7 @@ type ExampleTable_ExampleMessage struct {
func (x *ExampleTable_ExampleMessage) Reset() {
*x = ExampleTable_ExampleMessage{}
if protoimpl.UnsafeEnabled {
mi := &file_testpb_testschema_proto_msgTypes[4]
mi := &file_testpb_test_schema_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -3697,7 +3697,7 @@ func (*ExampleTable_ExampleMessage) ProtoMessage() {}
// Deprecated: Use ExampleTable_ExampleMessage.ProtoReflect.Descriptor instead.
func (*ExampleTable_ExampleMessage) Descriptor() ([]byte, []int) {
return file_testpb_testschema_proto_rawDescGZIP(), []int{0, 1}
return file_testpb_test_schema_proto_rawDescGZIP(), []int{0, 1}
}
func (x *ExampleTable_ExampleMessage) GetFoo() string {
@ -3714,104 +3714,104 @@ func (x *ExampleTable_ExampleMessage) GetBar() int32 {
return 0
}
var File_testpb_testschema_proto protoreflect.FileDescriptor
var File_testpb_test_schema_proto protoreflect.FileDescriptor
var file_testpb_testschema_proto_rawDesc = []byte{
0x0a, 0x17, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x73, 0x63, 0x68,
0x65, 0x6d, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x74, 0x65, 0x73, 0x74, 0x70,
0x62, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62,
0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x62, 0x75, 0x66, 0x2f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x1a, 0x1d, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x6f, 0x72, 0x6d, 0x2f, 0x76,
0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x6f, 0x72, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x22, 0xbd, 0x05, 0x0a, 0x0c, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x54, 0x61, 0x62,
0x6c, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x33, 0x32, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52,
0x03, 0x75, 0x33, 0x32, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x36, 0x34, 0x18, 0x02, 0x20, 0x01, 0x28,
0x04, 0x52, 0x03, 0x75, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x74, 0x72, 0x18, 0x03, 0x20,
0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x74, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x62, 0x7a, 0x18, 0x04,
0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, 0x62, 0x7a, 0x12, 0x2a, 0x0a, 0x02, 0x74, 0x73, 0x18, 0x05,
0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70,
0x52, 0x02, 0x74, 0x73, 0x12, 0x2b, 0x0a, 0x03, 0x64, 0x75, 0x72, 0x18, 0x06, 0x20, 0x01, 0x28,
0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x03, 0x64, 0x75,
0x72, 0x12, 0x10, 0x0a, 0x03, 0x69, 0x33, 0x32, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03,
0x69, 0x33, 0x32, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x33, 0x32, 0x18, 0x08, 0x20, 0x01, 0x28, 0x11,
0x52, 0x03, 0x73, 0x33, 0x32, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x66, 0x33, 0x32, 0x18, 0x09, 0x20,
0x01, 0x28, 0x0f, 0x52, 0x04, 0x73, 0x66, 0x33, 0x32, 0x12, 0x10, 0x0a, 0x03, 0x69, 0x36, 0x34,
0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x69, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03, 0x73,
0x36, 0x34, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x12, 0x52, 0x03, 0x73, 0x36, 0x34, 0x12, 0x12, 0x0a,
0x04, 0x73, 0x66, 0x36, 0x34, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x10, 0x52, 0x04, 0x73, 0x66, 0x36,
0x34, 0x12, 0x10, 0x0a, 0x03, 0x66, 0x33, 0x32, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x07, 0x52, 0x03,
0x66, 0x33, 0x32, 0x12, 0x10, 0x0a, 0x03, 0x66, 0x36, 0x34, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x06,
0x52, 0x03, 0x66, 0x36, 0x34, 0x12, 0x0c, 0x0a, 0x01, 0x62, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x08,
0x52, 0x01, 0x62, 0x12, 0x1a, 0x0a, 0x01, 0x65, 0x18, 0x10, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c,
0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x52, 0x01, 0x65, 0x12,
0x1a, 0x0a, 0x08, 0x72, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x18, 0x11, 0x20, 0x03, 0x28,
0x0d, 0x52, 0x08, 0x72, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x2f, 0x0a, 0x03, 0x6d,
0x61, 0x70, 0x18, 0x12, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70,
0x62, 0x2e, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x4d,
0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x03, 0x6d, 0x61, 0x70, 0x12, 0x35, 0x0a, 0x03,
0x6d, 0x73, 0x67, 0x18, 0x13, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x74, 0x65, 0x73, 0x74,
var file_testpb_test_schema_proto_rawDesc = []byte{
0x0a, 0x18, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x73, 0x63,
0x68, 0x65, 0x6d, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x74, 0x65, 0x73, 0x74,
0x70, 0x62, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x1a, 0x1d, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x6f, 0x72, 0x6d, 0x2f,
0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x6f, 0x72, 0x6d, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x22, 0xbd, 0x05, 0x0a, 0x0c, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x54, 0x61,
0x62, 0x6c, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x33, 0x32, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d,
0x52, 0x03, 0x75, 0x33, 0x32, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x36, 0x34, 0x18, 0x02, 0x20, 0x01,
0x28, 0x04, 0x52, 0x03, 0x75, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x74, 0x72, 0x18, 0x03,
0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x74, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x62, 0x7a, 0x18,
0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, 0x62, 0x7a, 0x12, 0x2a, 0x0a, 0x02, 0x74, 0x73, 0x18,
0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d,
0x70, 0x52, 0x02, 0x74, 0x73, 0x12, 0x2b, 0x0a, 0x03, 0x64, 0x75, 0x72, 0x18, 0x06, 0x20, 0x01,
0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x03, 0x64,
0x75, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x69, 0x33, 0x32, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52,
0x03, 0x69, 0x33, 0x32, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x33, 0x32, 0x18, 0x08, 0x20, 0x01, 0x28,
0x11, 0x52, 0x03, 0x73, 0x33, 0x32, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x66, 0x33, 0x32, 0x18, 0x09,
0x20, 0x01, 0x28, 0x0f, 0x52, 0x04, 0x73, 0x66, 0x33, 0x32, 0x12, 0x10, 0x0a, 0x03, 0x69, 0x36,
0x34, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x69, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03,
0x73, 0x36, 0x34, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x12, 0x52, 0x03, 0x73, 0x36, 0x34, 0x12, 0x12,
0x0a, 0x04, 0x73, 0x66, 0x36, 0x34, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x10, 0x52, 0x04, 0x73, 0x66,
0x36, 0x34, 0x12, 0x10, 0x0a, 0x03, 0x66, 0x33, 0x32, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x07, 0x52,
0x03, 0x66, 0x33, 0x32, 0x12, 0x10, 0x0a, 0x03, 0x66, 0x36, 0x34, 0x18, 0x0e, 0x20, 0x01, 0x28,
0x06, 0x52, 0x03, 0x66, 0x36, 0x34, 0x12, 0x0c, 0x0a, 0x01, 0x62, 0x18, 0x0f, 0x20, 0x01, 0x28,
0x08, 0x52, 0x01, 0x62, 0x12, 0x1a, 0x0a, 0x01, 0x65, 0x18, 0x10, 0x20, 0x01, 0x28, 0x0e, 0x32,
0x0c, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x52, 0x01, 0x65,
0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x18, 0x11, 0x20, 0x03,
0x28, 0x0d, 0x52, 0x08, 0x72, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x2f, 0x0a, 0x03,
0x6d, 0x61, 0x70, 0x18, 0x12, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x74, 0x65, 0x73, 0x74,
0x70, 0x62, 0x2e, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x2e,
0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x03,
0x6d, 0x73, 0x67, 0x12, 0x16, 0x0a, 0x05, 0x6f, 0x6e, 0x65, 0x6f, 0x66, 0x18, 0x14, 0x20, 0x01,
0x28, 0x0d, 0x48, 0x00, 0x52, 0x05, 0x6f, 0x6e, 0x65, 0x6f, 0x66, 0x1a, 0x36, 0x0a, 0x08, 0x4d,
0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c,
0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a,
0x02, 0x38, 0x01, 0x1a, 0x34, 0x0a, 0x0e, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x4d, 0x65,
0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x66, 0x6f, 0x6f, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x61, 0x72, 0x18, 0x02,
0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x62, 0x61, 0x72, 0x3a, 0x3f, 0xf2, 0x9e, 0xd3, 0x8e, 0x03,
0x39, 0x0a, 0x0d, 0x0a, 0x0b, 0x75, 0x33, 0x32, 0x2c, 0x69, 0x36, 0x34, 0x2c, 0x73, 0x74, 0x72,
0x12, 0x0d, 0x0a, 0x07, 0x75, 0x36, 0x34, 0x2c, 0x73, 0x74, 0x72, 0x10, 0x01, 0x18, 0x01, 0x12,
0x0b, 0x0a, 0x07, 0x73, 0x74, 0x72, 0x2c, 0x75, 0x33, 0x32, 0x10, 0x02, 0x12, 0x0a, 0x0a, 0x06,
0x62, 0x7a, 0x2c, 0x73, 0x74, 0x72, 0x10, 0x03, 0x18, 0x01, 0x42, 0x05, 0x0a, 0x03, 0x73, 0x75,
0x6d, 0x22, 0x62, 0x0a, 0x19, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x41, 0x75, 0x74, 0x6f,
0x49, 0x6e, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x0e,
0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x02, 0x69, 0x64, 0x12, 0x0c,
0x0a, 0x01, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x01, 0x78, 0x12, 0x0c, 0x0a, 0x01,
0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x01, 0x79, 0x3a, 0x19, 0xf2, 0x9e, 0xd3, 0x8e,
0x03, 0x13, 0x0a, 0x06, 0x0a, 0x02, 0x69, 0x64, 0x10, 0x01, 0x12, 0x07, 0x0a, 0x01, 0x78, 0x10,
0x01, 0x18, 0x01, 0x18, 0x03, 0x22, 0x40, 0x0a, 0x10, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65,
0x53, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x74, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x66, 0x6f, 0x6f,
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x62,
0x61, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x62, 0x61, 0x72, 0x3a, 0x08, 0xfa,
0x9e, 0xd3, 0x8e, 0x03, 0x02, 0x08, 0x02, 0x2a, 0x64, 0x0a, 0x04, 0x45, 0x6e, 0x75, 0x6d, 0x12,
0x14, 0x0a, 0x10, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46,
0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x4f, 0x4e,
0x45, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x54, 0x57, 0x4f, 0x10,
0x02, 0x12, 0x0d, 0x0a, 0x09, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x46, 0x49, 0x56, 0x45, 0x10, 0x05,
0x12, 0x1b, 0x0a, 0x0e, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x4e, 0x45, 0x47, 0x5f, 0x54, 0x48, 0x52,
0x45, 0x45, 0x10, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x42, 0x87, 0x01,
0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x42, 0x0f, 0x54, 0x65,
0x73, 0x74, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a,
0x30, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d,
0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x6f, 0x72,
0x6d, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70,
0x62, 0xa2, 0x02, 0x03, 0x54, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62,
0xca, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xe2, 0x02, 0x12, 0x54, 0x65, 0x73, 0x74,
0x70, 0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02,
0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x03, 0x6d, 0x61, 0x70, 0x12, 0x35, 0x0a,
0x03, 0x6d, 0x73, 0x67, 0x18, 0x13, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x74, 0x65, 0x73,
0x74, 0x70, 0x62, 0x2e, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65,
0x2e, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52,
0x03, 0x6d, 0x73, 0x67, 0x12, 0x16, 0x0a, 0x05, 0x6f, 0x6e, 0x65, 0x6f, 0x66, 0x18, 0x14, 0x20,
0x01, 0x28, 0x0d, 0x48, 0x00, 0x52, 0x05, 0x6f, 0x6e, 0x65, 0x6f, 0x66, 0x1a, 0x36, 0x0a, 0x08,
0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61,
0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65,
0x3a, 0x02, 0x38, 0x01, 0x1a, 0x34, 0x0a, 0x0e, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x4d,
0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x66, 0x6f, 0x6f, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x61, 0x72, 0x18,
0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x62, 0x61, 0x72, 0x3a, 0x3f, 0xf2, 0x9e, 0xd3, 0x8e,
0x03, 0x39, 0x0a, 0x0d, 0x0a, 0x0b, 0x75, 0x33, 0x32, 0x2c, 0x69, 0x36, 0x34, 0x2c, 0x73, 0x74,
0x72, 0x12, 0x0d, 0x0a, 0x07, 0x75, 0x36, 0x34, 0x2c, 0x73, 0x74, 0x72, 0x10, 0x01, 0x18, 0x01,
0x12, 0x0b, 0x0a, 0x07, 0x73, 0x74, 0x72, 0x2c, 0x75, 0x33, 0x32, 0x10, 0x02, 0x12, 0x0a, 0x0a,
0x06, 0x62, 0x7a, 0x2c, 0x73, 0x74, 0x72, 0x10, 0x03, 0x18, 0x01, 0x42, 0x05, 0x0a, 0x03, 0x73,
0x75, 0x6d, 0x22, 0x62, 0x0a, 0x19, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x41, 0x75, 0x74,
0x6f, 0x49, 0x6e, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x12,
0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x02, 0x69, 0x64, 0x12,
0x0c, 0x0a, 0x01, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x01, 0x78, 0x12, 0x0c, 0x0a,
0x01, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x01, 0x79, 0x3a, 0x19, 0xf2, 0x9e, 0xd3,
0x8e, 0x03, 0x13, 0x0a, 0x06, 0x0a, 0x02, 0x69, 0x64, 0x10, 0x01, 0x12, 0x07, 0x0a, 0x01, 0x78,
0x10, 0x01, 0x18, 0x01, 0x18, 0x03, 0x22, 0x40, 0x0a, 0x10, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c,
0x65, 0x53, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x74, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x66, 0x6f,
0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x12, 0x10, 0x0a, 0x03,
0x62, 0x61, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x62, 0x61, 0x72, 0x3a, 0x08,
0xfa, 0x9e, 0xd3, 0x8e, 0x03, 0x02, 0x08, 0x02, 0x2a, 0x64, 0x0a, 0x04, 0x45, 0x6e, 0x75, 0x6d,
0x12, 0x14, 0x0a, 0x10, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49,
0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x4f,
0x4e, 0x45, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x54, 0x57, 0x4f,
0x10, 0x02, 0x12, 0x0d, 0x0a, 0x09, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x46, 0x49, 0x56, 0x45, 0x10,
0x05, 0x12, 0x1b, 0x0a, 0x0e, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x4e, 0x45, 0x47, 0x5f, 0x54, 0x48,
0x52, 0x45, 0x45, 0x10, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x42, 0x87,
0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x42, 0x0f, 0x54,
0x65, 0x73, 0x74, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01,
0x5a, 0x30, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73,
0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x6f,
0x72, 0x6d, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74,
0x70, 0x62, 0xa2, 0x02, 0x03, 0x54, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70,
0x62, 0xca, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xe2, 0x02, 0x12, 0x54, 0x65, 0x73,
0x74, 0x70, 0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea,
0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_testpb_testschema_proto_rawDescOnce sync.Once
file_testpb_testschema_proto_rawDescData = file_testpb_testschema_proto_rawDesc
file_testpb_test_schema_proto_rawDescOnce sync.Once
file_testpb_test_schema_proto_rawDescData = file_testpb_test_schema_proto_rawDesc
)
func file_testpb_testschema_proto_rawDescGZIP() []byte {
file_testpb_testschema_proto_rawDescOnce.Do(func() {
file_testpb_testschema_proto_rawDescData = protoimpl.X.CompressGZIP(file_testpb_testschema_proto_rawDescData)
func file_testpb_test_schema_proto_rawDescGZIP() []byte {
file_testpb_test_schema_proto_rawDescOnce.Do(func() {
file_testpb_test_schema_proto_rawDescData = protoimpl.X.CompressGZIP(file_testpb_test_schema_proto_rawDescData)
})
return file_testpb_testschema_proto_rawDescData
return file_testpb_test_schema_proto_rawDescData
}
var file_testpb_testschema_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_testpb_testschema_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
var file_testpb_testschema_proto_goTypes = []interface{}{
var file_testpb_test_schema_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_testpb_test_schema_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
var file_testpb_test_schema_proto_goTypes = []interface{}{
(Enum)(0), // 0: testpb.Enum
(*ExampleTable)(nil), // 1: testpb.ExampleTable
(*ExampleAutoIncrementTable)(nil), // 2: testpb.ExampleAutoIncrementTable
@ -3821,7 +3821,7 @@ var file_testpb_testschema_proto_goTypes = []interface{}{
(*timestamppb.Timestamp)(nil), // 6: google.protobuf.Timestamp
(*durationpb.Duration)(nil), // 7: google.protobuf.Duration
}
var file_testpb_testschema_proto_depIdxs = []int32{
var file_testpb_test_schema_proto_depIdxs = []int32{
6, // 0: testpb.ExampleTable.ts:type_name -> google.protobuf.Timestamp
7, // 1: testpb.ExampleTable.dur:type_name -> google.protobuf.Duration
0, // 2: testpb.ExampleTable.e:type_name -> testpb.Enum
@ -3834,13 +3834,13 @@ var file_testpb_testschema_proto_depIdxs = []int32{
0, // [0:5] is the sub-list for field type_name
}
func init() { file_testpb_testschema_proto_init() }
func file_testpb_testschema_proto_init() {
if File_testpb_testschema_proto != nil {
func init() { file_testpb_test_schema_proto_init() }
func file_testpb_test_schema_proto_init() {
if File_testpb_test_schema_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_testpb_testschema_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
file_testpb_test_schema_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ExampleTable); i {
case 0:
return &v.state
@ -3852,7 +3852,7 @@ func file_testpb_testschema_proto_init() {
return nil
}
}
file_testpb_testschema_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
file_testpb_test_schema_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ExampleAutoIncrementTable); i {
case 0:
return &v.state
@ -3864,7 +3864,7 @@ func file_testpb_testschema_proto_init() {
return nil
}
}
file_testpb_testschema_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
file_testpb_test_schema_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ExampleSingleton); i {
case 0:
return &v.state
@ -3876,7 +3876,7 @@ func file_testpb_testschema_proto_init() {
return nil
}
}
file_testpb_testschema_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
file_testpb_test_schema_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ExampleTable_ExampleMessage); i {
case 0:
return &v.state
@ -3889,26 +3889,26 @@ func file_testpb_testschema_proto_init() {
}
}
}
file_testpb_testschema_proto_msgTypes[0].OneofWrappers = []interface{}{
file_testpb_test_schema_proto_msgTypes[0].OneofWrappers = []interface{}{
(*ExampleTable_Oneof)(nil),
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_testpb_testschema_proto_rawDesc,
RawDescriptor: file_testpb_test_schema_proto_rawDesc,
NumEnums: 1,
NumMessages: 5,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_testpb_testschema_proto_goTypes,
DependencyIndexes: file_testpb_testschema_proto_depIdxs,
EnumInfos: file_testpb_testschema_proto_enumTypes,
MessageInfos: file_testpb_testschema_proto_msgTypes,
GoTypes: file_testpb_test_schema_proto_goTypes,
DependencyIndexes: file_testpb_test_schema_proto_depIdxs,
EnumInfos: file_testpb_test_schema_proto_enumTypes,
MessageInfos: file_testpb_test_schema_proto_msgTypes,
}.Build()
File_testpb_testschema_proto = out.File
file_testpb_testschema_proto_rawDesc = nil
file_testpb_testschema_proto_goTypes = nil
file_testpb_testschema_proto_depIdxs = nil
File_testpb_test_schema_proto = out.File
file_testpb_test_schema_proto_rawDesc = nil
file_testpb_test_schema_proto_goTypes = nil
file_testpb_test_schema_proto_depIdxs = nil
}

View File

@ -27,12 +27,7 @@ var TestBankSchema = ormdb.ModuleSchema{
}
type keeper struct {
balanceTable ormtable.Table
balanceAddressDenomIndex ormtable.UniqueIndex
balanceDenomIndex ormtable.Index
supplyTable ormtable.Table
supplyDenomIndex ormtable.UniqueIndex
store testpb.BankStore
}
func (k keeper) Send(ctx context.Context, from, to, denom string, amount uint64) error {
@ -45,14 +40,18 @@ func (k keeper) Send(ctx context.Context, from, to, denom string, amount uint64)
}
func (k keeper) Mint(ctx context.Context, acct, denom string, amount uint64) error {
supply := &testpb.Supply{Denom: denom}
_, err := k.supplyTable.Get(ctx, supply)
supply, err := k.store.SupplyStore().Get(ctx, denom)
if err != nil {
return err
}
supply.Amount = supply.Amount + amount
err = k.supplyTable.Save(ctx, supply)
if supply == nil {
supply = &testpb.Supply{Denom: denom, Amount: amount}
} else {
supply.Amount = supply.Amount + amount
}
err = k.store.SupplyStore().Save(ctx, supply)
if err != nil {
return err
}
@ -61,13 +60,13 @@ func (k keeper) Mint(ctx context.Context, acct, denom string, amount uint64) err
}
func (k keeper) Burn(ctx context.Context, acct, denom string, amount uint64) error {
supply := &testpb.Supply{Denom: denom}
found, err := k.supplyTable.Get(ctx, supply)
supplyStore := k.store.SupplyStore()
supply, err := supplyStore.Get(ctx, denom)
if err != nil {
return err
}
if !found {
if supply == nil {
return fmt.Errorf("no supply for %s", denom)
}
@ -78,9 +77,9 @@ func (k keeper) Burn(ctx context.Context, acct, denom string, amount uint64) err
supply.Amount = supply.Amount - amount
if supply.Amount == 0 {
err = k.supplyTable.Delete(ctx, supply)
err = supplyStore.Delete(ctx, supply)
} else {
err = k.supplyTable.Save(ctx, supply)
err = supplyStore.Save(ctx, supply)
}
if err != nil {
return err
@ -90,36 +89,48 @@ func (k keeper) Burn(ctx context.Context, acct, denom string, amount uint64) err
}
func (k keeper) Balance(ctx context.Context, acct, denom string) (uint64, error) {
balance := &testpb.Balance{Address: acct, Denom: denom}
_, err := k.balanceTable.Get(ctx, balance)
balance, err := k.store.BalanceStore().Get(ctx, acct, denom)
if balance == nil {
return 0, err
}
return balance.Amount, err
}
func (k keeper) Supply(ctx context.Context, denom string) (uint64, error) {
supply := &testpb.Supply{Denom: denom}
_, err := k.supplyTable.Get(ctx, supply)
supply, err := k.store.SupplyStore().Get(ctx, denom)
if supply == nil {
return 0, err
}
return supply.Amount, err
}
func (k keeper) addBalance(ctx context.Context, acct, denom string, amount uint64) error {
balance := &testpb.Balance{Address: acct, Denom: denom}
_, err := k.balanceTable.Get(ctx, balance)
balance, err := k.store.BalanceStore().Get(ctx, acct, denom)
if err != nil {
return err
}
balance.Amount = balance.Amount + amount
return k.balanceTable.Save(ctx, balance)
if balance == nil {
balance = &testpb.Balance{
Address: acct,
Denom: denom,
Amount: amount,
}
} else {
balance.Amount = balance.Amount + amount
}
return k.store.BalanceStore().Save(ctx, balance)
}
func (k keeper) safeSubBalance(ctx context.Context, acct, denom string, amount uint64) error {
balance := &testpb.Balance{Address: acct, Denom: denom}
found, err := k.balanceTable.Get(ctx, balance)
balanceStore := k.store.BalanceStore()
balance, err := balanceStore.Get(ctx, acct, denom)
if err != nil {
return err
}
if !found {
if balance == nil {
return fmt.Errorf("acct %x has no balance for %s", acct, denom)
}
@ -130,23 +141,15 @@ func (k keeper) safeSubBalance(ctx context.Context, acct, denom string, amount u
balance.Amount = balance.Amount - amount
if balance.Amount == 0 {
return k.balanceTable.Delete(ctx, balance)
return balanceStore.Delete(ctx, balance)
} else {
return k.balanceTable.Save(ctx, balance)
return balanceStore.Save(ctx, balance)
}
}
func newKeeper(db ormdb.ModuleDB) keeper {
k := keeper{
balanceTable: db.GetTable(&testpb.Balance{}),
supplyTable: db.GetTable(&testpb.Supply{}),
}
k.balanceAddressDenomIndex = k.balanceTable.GetUniqueIndex("address,denom")
k.balanceDenomIndex = k.balanceTable.GetIndex("denom")
k.supplyDenomIndex = k.supplyTable.GetUniqueIndex("denom")
return k
func newKeeper(db ormdb.ModuleDB) (keeper, error) {
store, err := testpb.NewBankStore(db)
return keeper{store}, err
}
func TestModuleDB(t *testing.T) {
@ -164,12 +167,8 @@ func TestModuleDB(t *testing.T) {
ctx := ormtable.WrapContextDefault(store)
// create keeper
k := newKeeper(db)
assert.Assert(t, k.balanceTable != nil)
assert.Assert(t, k.balanceAddressDenomIndex != nil)
assert.Assert(t, k.balanceDenomIndex != nil)
assert.Assert(t, k.supplyTable != nil)
assert.Assert(t, k.supplyDenomIndex != nil)
k, err := newKeeper(db)
assert.NilError(t, err)
// mint coins
denom := "foo"

View File

@ -49,8 +49,6 @@ func runAutoIncrementScenario(t *testing.T, table ormtable.Table, context contex
buf := &bytes.Buffer{}
assert.NilError(t, table.ExportJSON(context, buf))
golden.Assert(t, string(buf.Bytes()), "auto_inc_json.golden")
assert.NilError(t, table.ValidateJSON(bytes.NewReader(buf.Bytes())))
store2 := ormtable.WrapContextDefault(testkv.NewSplitMemBackend())
assert.NilError(t, table.ImportJSON(store2, bytes.NewReader(buf.Bytes())))

View File

@ -4,6 +4,8 @@ import (
"context"
"fmt"
"github.com/cosmos/cosmos-sdk/orm/internal/fieldnames"
"github.com/cosmos/cosmos-sdk/orm/encoding/encodeutil"
"google.golang.org/protobuf/reflect/protoregistry"
@ -91,9 +93,10 @@ func Build(options Options) (Table, error) {
getReadBackend: getReadBackend,
},
indexes: []Index{},
indexesByFields: map[fieldNames]concreteIndex{},
uniqueIndexesByFields: map[fieldNames]UniqueIndex{},
indexesByFields: map[fieldnames.FieldNames]concreteIndex{},
uniqueIndexesByFields: map[fieldnames.FieldNames]UniqueIndex{},
entryCodecsById: map[uint32]ormkv.EntryCodec{},
indexesById: map[uint32]Index{},
typeResolver: options.TypeResolver,
customJSONValidator: options.JSONValidator,
}
@ -154,7 +157,7 @@ func Build(options Options) (Table, error) {
return nil, ormerrors.MissingPrimaryKey.Wrap(string(messageDescriptor.FullName()))
}
pkFields := commaSeparatedFieldNames(tableDesc.PrimaryKey.Fields)
pkFields := fieldnames.CommaSeparatedFieldNames(tableDesc.PrimaryKey.Fields)
table.primaryKeyIndex.fields = pkFields
pkFieldNames := pkFields.Names()
if len(pkFieldNames) == 0 {
@ -176,6 +179,7 @@ func Build(options Options) (Table, error) {
table.indexesByFields[pkFields] = pkIndex
table.uniqueIndexesByFields[pkFields] = pkIndex
table.entryCodecsById[primaryKeyId] = pkIndex
table.indexesById[primaryKeyId] = pkIndex
table.indexes = append(table.indexes, pkIndex)
for _, idxDesc := range tableDesc.Index {
@ -188,12 +192,12 @@ func Build(options Options) (Table, error) {
return nil, ormerrors.DuplicateIndexId.Wrapf("id %d on table %s", id, messageDescriptor.FullName())
}
idxFields := commaSeparatedFieldNames(idxDesc.Fields)
idxFields := fieldnames.CommaSeparatedFieldNames(idxDesc.Fields)
idxPrefix := encodeutil.AppendVarUInt32(prefix, id)
var index concreteIndex
// altNames contains all the alternative "names" of this index
altNames := map[fieldNames]bool{idxFields: true}
altNames := map[fieldnames.FieldNames]bool{idxFields: true}
if idxDesc.Unique && isNonTrivialUniqueKey(idxFields.Names(), pkFieldNames) {
uniqCdc, err := ormkv.NewUniqueKeyCodec(
@ -237,10 +241,10 @@ func Build(options Options) (Table, error) {
// is actually stored as "c,a,b". So this index can be referred to
// by the fields "c", "c,a", or "c,a,b".
allFields := index.GetFieldNames()
allFieldNames := fieldsFromNames(allFields)
allFieldNames := fieldnames.FieldsFromNames(allFields)
altNames[allFieldNames] = true
for i := 1; i < len(allFields); i++ {
altName := fieldsFromNames(allFields[:i])
altName := fieldnames.FieldsFromNames(allFields[:i])
if altNames[altName] {
continue
}
@ -257,7 +261,7 @@ func Build(options Options) (Table, error) {
return nil, err
}
if fieldsFromNames(altIdxCdc.GetFieldNames()) == allFieldNames {
if fieldnames.FieldsFromNames(altIdxCdc.GetFieldNames()) == allFieldNames {
altNames[altName] = true
}
}
@ -272,6 +276,7 @@ func Build(options Options) (Table, error) {
}
table.entryCodecsById[id] = index
table.indexesById[id] = index
table.indexes = append(table.indexes, index)
table.indexers = append(table.indexers, index.(indexer))
}

View File

@ -3,6 +3,8 @@ package ormtable
import (
"context"
"github.com/cosmos/cosmos-sdk/orm/internal/fieldnames"
"github.com/cosmos/cosmos-sdk/orm/model/kv"
"github.com/cosmos/cosmos-sdk/orm/model/ormlist"
@ -17,7 +19,7 @@ import (
// indexKeyIndex implements Index for a regular IndexKey.
type indexKeyIndex struct {
*ormkv.IndexKeyCodec
fields fieldNames
fields fieldnames.FieldNames
primaryKey *primaryKeyIndex
getReadBackend func(context.Context) (ReadBackend, error)
}

View File

@ -3,6 +3,8 @@ package ormtable
import (
"context"
"github.com/cosmos/cosmos-sdk/orm/internal/fieldnames"
"github.com/cosmos/cosmos-sdk/orm/model/ormlist"
"github.com/cosmos/cosmos-sdk/orm/encoding/encodeutil"
@ -16,7 +18,7 @@ import (
// primaryKeyIndex defines an UniqueIndex for the primary key.
type primaryKeyIndex struct {
*ormkv.PrimaryKeyCodec
fields fieldNames
fields fieldnames.FieldNames
indexers []indexer
getBackend func(context.Context) (Backend, error)
getReadBackend func(context.Context) (ReadBackend, error)

View File

@ -41,6 +41,12 @@ type View interface {
// Indexes returns all the concrete indexes for the table.
Indexes() []Index
// GetIndexByID returns the index with the provided ID or nil.
GetIndexByID(id uint32) Index
// PrimaryKey returns the primary key unique index.
PrimaryKey() UniqueIndex
}
// Table is an abstract interface around a concrete table. Table instances

View File

@ -8,6 +8,8 @@ import (
"io"
"math"
"github.com/cosmos/cosmos-sdk/orm/internal/fieldnames"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
@ -20,8 +22,9 @@ import (
type tableImpl struct {
*primaryKeyIndex
indexes []Index
indexesByFields map[fieldNames]concreteIndex
uniqueIndexesByFields map[fieldNames]UniqueIndex
indexesByFields map[fieldnames.FieldNames]concreteIndex
uniqueIndexesByFields map[fieldnames.FieldNames]UniqueIndex
indexesById map[uint32]Index
entryCodecsById map[uint32]ormkv.EntryCodec
tablePrefix []byte
tableId uint32
@ -29,6 +32,14 @@ type tableImpl struct {
customJSONValidator func(message proto.Message) error
}
func (t tableImpl) PrimaryKey() UniqueIndex {
return t.primaryKeyIndex
}
func (t tableImpl) GetIndexByID(id uint32) Index {
return t.indexesById[id]
}
func (t tableImpl) Save(ctx context.Context, message proto.Message) error {
backend, err := t.getBackend(ctx)
if err != nil {
@ -141,11 +152,11 @@ func (t tableImpl) Delete(context context.Context, message proto.Message) error
}
func (t tableImpl) GetIndex(fields string) Index {
return t.indexesByFields[commaSeparatedFieldNames(fields)]
return t.indexesByFields[fieldnames.CommaSeparatedFieldNames(fields)]
}
func (t tableImpl) GetUniqueIndex(fields string) UniqueIndex {
return t.uniqueIndexesByFields[commaSeparatedFieldNames(fields)]
return t.uniqueIndexesByFields[fieldnames.CommaSeparatedFieldNames(fields)]
}
func (t tableImpl) Indexes() []Index {
@ -349,7 +360,7 @@ func (t tableImpl) EncodeEntry(entry ormkv.Entry) (k, v []byte, err error) {
case *ormkv.PrimaryKeyEntry:
return t.PrimaryKeyCodec.EncodeEntry(entry)
case *ormkv.IndexKeyEntry:
idx, ok := t.indexesByFields[fieldsFromNames(entry.Fields)]
idx, ok := t.indexesByFields[fieldnames.FieldsFromNames(entry.Fields)]
if !ok {
return nil, nil, ormerrors.BadDecodeEntry.Wrapf("can't find index with fields %s", entry.Fields)
}

View File

@ -1,2 +0,0 @@
[1,
{"id":"1","x":"foo","y":5}]

View File

@ -3,6 +3,8 @@ package ormtable
import (
"context"
"github.com/cosmos/cosmos-sdk/orm/internal/fieldnames"
"github.com/cosmos/cosmos-sdk/orm/model/kv"
"github.com/cosmos/cosmos-sdk/orm/model/ormlist"
@ -17,7 +19,7 @@ import (
type uniqueKeyIndex struct {
*ormkv.UniqueKeyCodec
fields fieldNames
fields fieldnames.FieldNames
primaryKey *primaryKeyIndex
getReadBackend func(context.Context) (ReadBackend, error)
}

View File

@ -31,4 +31,5 @@ var (
UniqueKeyViolation = errors.New(codespace, 24, "unique key violation")
InvalidTableDefinition = errors.New(codespace, 25, "invalid table definition")
InvalidFileDescriptorID = errors.New(codespace, 26, "invalid file descriptor ID")
TableNotFound = errors.New(codespace, 27, "table not found")
)

View File

@ -13,5 +13,3 @@ protoc_gen_gopulsar
echo "Generating API module"
(cd proto; buf generate --template buf.gen.pulsar.yaml)
(cd orm/internal; buf generate .)