refactor(orm)!: rename table interfaces from Store -> Table in codegen (#11176)

## Description

I realize it's more intuitive to name the interfaces in codegen `FooTable` rather than `FooStore` for the type `Foo`.

Since we (and possibly others) are starting to build off of this, better to change now rather than later.

How does this change look?



---

### 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:
Aaron Craelius 2022-02-14 10:23:52 -05:00 committed by GitHub
parent 875378b231
commit 0d4cb92dad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 145 additions and 145 deletions

View File

@ -45,7 +45,7 @@ func (f fileGen) gen() error {
stores = append(stores, msg)
}
}
f.genStoreInterfaces(stores)
f.genStoreInterface(stores)
f.genStoreStruct(stores)
f.genStoreMethods(stores)
f.genStoreInterfaceGuard()
@ -53,10 +53,10 @@ func (f fileGen) gen() error {
return nil
}
func (f fileGen) genStoreInterfaces(stores []*protogen.Message) {
func (f fileGen) genStoreInterface(stores []*protogen.Message) {
f.P("type ", f.storeInterfaceName(), " interface {")
for _, store := range stores {
name := f.messageStoreInterfaceName(store)
name := f.messageTableInterfaceName(store)
f.P(name, "()", name)
}
f.P()
@ -69,7 +69,7 @@ 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(f.param(message.GoIdent.GoName), " ", f.messageTableInterfaceName(message))
}
f.P("}")
}
@ -96,8 +96,8 @@ func (f fileGen) fileShortName() string {
return strcase.ToCamel(shortName)
}
func (f fileGen) messageStoreInterfaceName(m *protogen.Message) string {
return m.GoIdent.GoName + "Store"
func (f fileGen) messageTableInterfaceName(m *protogen.Message) string {
return m.GoIdent.GoName + "Table"
}
func (f fileGen) messageReaderInterfaceName(m *protogen.Message) string {
@ -112,18 +112,18 @@ 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) messageTableReceiverName(m *protogen.Message) string {
return f.param(f.messageTableInterfaceName(m))
}
func (f fileGen) messageConstructorName(m *protogen.Message) string {
return "New" + f.messageStoreInterfaceName(m)
return "New" + f.messageTableInterfaceName(m)
}
func (f fileGen) genStoreMethods(stores []*protogen.Message) {
// getters
for _, msg := range stores {
name := f.messageStoreInterfaceName(msg)
name := f.messageTableInterfaceName(msg)
f.P("func(x ", f.storeStructName(), ") ", name, "() ", name, "{")
f.P("return x.", f.param(msg.GoIdent.GoName))
f.P("}")
@ -140,7 +140,7 @@ func (f fileGen) genStoreInterfaceGuard() {
func (f fileGen) genStoreConstructor(stores []*protogen.Message) {
f.P("func New", f.storeInterfaceName(), "(db ", ormTablePkg.Ident("Schema"), ") (", f.storeInterfaceName(), ", error) {")
for _, store := range stores {
f.P(f.messageStoreReceiverName(store), ", err := ", f.messageConstructorName(store), "(db)")
f.P(f.messageTableReceiverName(store), ", err := ", f.messageConstructorName(store), "(db)")
f.P("if err != nil {")
f.P("return nil, err")
f.P("}")
@ -149,7 +149,7 @@ func (f fileGen) genStoreConstructor(stores []*protogen.Message) {
f.P("return ", f.storeStructName(), "{")
for _, store := range stores {
f.P(f.messageStoreReceiverName(store), ",")
f.P(f.messageTableReceiverName(store), ",")
}
f.P("}, nil")
f.P("}")

View File

@ -37,7 +37,7 @@ func (s singletonGen) gen() {
func (s singletonGen) genInterface() {
s.P("// singleton store")
s.P("type ", s.messageStoreInterfaceName(s.msg), " interface {")
s.P("type ", s.messageTableInterfaceName(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("}")
@ -45,18 +45,18 @@ func (s singletonGen) genInterface() {
}
func (s singletonGen) genStruct() {
s.P("type ", s.messageStoreReceiverName(s.msg), " struct {")
s.P("type ", s.messageTableReceiverName(s.msg), " struct {")
s.P("table ", ormTablePkg.Ident("Table"))
s.P("}")
s.P()
}
func (s singletonGen) genInterfaceGuard() {
s.P("var _ ", s.messageStoreInterfaceName(s.msg), " = ", s.messageStoreReceiverName(s.msg), "{}")
s.P("var _ ", s.messageTableInterfaceName(s.msg), " = ", s.messageTableReceiverName(s.msg), "{}")
}
func (s singletonGen) genMethods() {
receiver := fmt.Sprintf("func (x %s) ", s.messageStoreReceiverName(s.msg))
receiver := fmt.Sprintf("func (x %s) ", s.messageTableReceiverName(s.msg))
varName := s.param(s.msg.GoIdent.GoName)
// Get
s.P(receiver, "Get(ctx ", contextPkg.Ident("Context"), ") (*", s.msg.GoIdent.GoName, ", error) {")
@ -74,12 +74,12 @@ func (s singletonGen) genMethods() {
}
func (s singletonGen) genConstructor() {
iface := s.messageStoreInterfaceName(s.msg)
iface := s.messageTableInterfaceName(s.msg)
s.P("func New", iface, "(db ", ormTablePkg.Ident("Schema"), ") (", 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("return &", s.messageTableReceiverName(s.msg), "{table}, nil")
s.P("}")
}

View File

@ -47,17 +47,17 @@ func newTableGen(fileGen fileGen, msg *protogen.Message, table *ormv1alpha1.Tabl
}
func (t tableGen) gen() {
t.genStoreInterface()
t.getTableInterface()
t.genIterator()
t.genIndexKeys()
t.genStruct()
t.genStoreImpl()
t.genStoreImplGuard()
t.genTableImpl()
t.genTableImplGuard()
t.genConstructor()
}
func (t tableGen) genStoreInterface() {
t.P("type ", t.messageStoreInterfaceName(t.msg), " interface {")
func (t tableGen) getTableInterface() {
t.P("type ", t.messageTableInterfaceName(t.msg), " interface {")
t.P("Insert(ctx ", contextPkg.Ident("Context"), ", ", t.param(t.msg.GoIdent.GoName), " *", t.QualifiedGoIdent(t.msg.GoIdent), ") error")
if t.table.PrimaryKey.AutoIncrement {
t.P("InsertReturningID(ctx ", contextPkg.Ident("Context"), ", ", t.param(t.msg.GoIdent.GoName), " *", t.QualifiedGoIdent(t.msg.GoIdent), ") (uint64, error)")
@ -153,7 +153,7 @@ func (t tableGen) fieldArg(name protoreflect.Name) string {
}
func (t tableGen) genStruct() {
t.P("type ", t.messageStoreReceiverName(t.msg), " struct {")
t.P("type ", t.messageTableReceiverName(t.msg), " struct {")
if t.table.PrimaryKey.AutoIncrement {
t.P("table ", ormTablePkg.Ident("AutoIncrementTable"))
} else {
@ -163,9 +163,9 @@ func (t tableGen) genStruct() {
t.storeStructName()
}
func (t tableGen) genStoreImpl() {
func (t tableGen) genTableImpl() {
receiverVar := "this"
receiver := fmt.Sprintf("func (%s %s) ", receiverVar, t.messageStoreReceiverName(t.msg))
receiver := fmt.Sprintf("func (%s %s) ", receiverVar, t.messageTableReceiverName(t.msg))
varName := t.param(t.msg.GoIdent.GoName)
varTypeName := t.QualifiedGoIdent(t.msg.GoIdent)
@ -210,7 +210,7 @@ func (t tableGen) genStoreImpl() {
hasName, getName, _ := t.uniqueIndexSig(idx.Fields)
// has
t.P("func (", receiverVar, " ", t.messageStoreReceiverName(t.msg), ") ", hasName, "{")
t.P("func (", receiverVar, " ", t.messageTableReceiverName(t.msg), ") ", hasName, "{")
t.P("return ", receiverVar, ".table.GetIndexByID(", idx.Id, ").(",
ormTablePkg.Ident("UniqueIndex"), ").Has(ctx,")
for _, field := range fields {
@ -223,7 +223,7 @@ func (t tableGen) genStoreImpl() {
// get
varName := t.param(t.msg.GoIdent.GoName)
varTypeName := t.msg.GoIdent.GoName
t.P("func (", receiverVar, " ", t.messageStoreReceiverName(t.msg), ") ", getName, "{")
t.P("func (", receiverVar, " ", t.messageTableReceiverName(t.msg), ") ", getName, "{")
t.P("var ", varName, " ", varTypeName)
t.P("found, err := ", receiverVar, ".table.GetIndexByID(", idx.Id, ").(",
ormTablePkg.Ident("UniqueIndex"), ").Get(ctx, &", varName, ",")
@ -274,12 +274,12 @@ func (t tableGen) genStoreImpl() {
t.P()
}
func (t tableGen) genStoreImplGuard() {
t.P("var _ ", t.messageStoreInterfaceName(t.msg), " = ", t.messageStoreReceiverName(t.msg), "{}")
func (t tableGen) genTableImplGuard() {
t.P("var _ ", t.messageTableInterfaceName(t.msg), " = ", t.messageTableReceiverName(t.msg), "{}")
}
func (t tableGen) genConstructor() {
iface := t.messageStoreInterfaceName(t.msg)
iface := t.messageTableInterfaceName(t.msg)
t.P("func New", iface, "(db ", ormTablePkg.Ident("Schema"), ") (", iface, ", error) {")
t.P("table := db.GetTable(&", t.msg.GoIdent.GoName, "{})")
t.P("if table == nil {")
@ -287,11 +287,11 @@ func (t tableGen) genConstructor() {
t.P("}")
if t.table.PrimaryKey.AutoIncrement {
t.P(
"return ", t.messageStoreReceiverName(t.msg), "{table.(",
"return ", t.messageTableReceiverName(t.msg), "{table.(",
ormTablePkg.Ident("AutoIncrementTable"), ")}, nil",
)
} else {
t.P("return ", t.messageStoreReceiverName(t.msg), "{table}, nil")
t.P("return ", t.messageTableReceiverName(t.msg), "{table}, nil")
}
t.P("}")
}

View File

@ -10,7 +10,7 @@ import (
ormerrors "github.com/cosmos/cosmos-sdk/orm/types/ormerrors"
)
type BalanceStore interface {
type BalanceTable interface {
Insert(ctx context.Context, balance *Balance) error
Update(ctx context.Context, balance *Balance) error
Save(ctx context.Context, balance *Balance) error
@ -76,31 +76,31 @@ func (this BalanceDenomIndexKey) WithDenom(denom string) BalanceDenomIndexKey {
return this
}
type balanceStore struct {
type balanceTable struct {
table ormtable.Table
}
func (this balanceStore) Insert(ctx context.Context, balance *Balance) error {
func (this balanceTable) Insert(ctx context.Context, balance *Balance) error {
return this.table.Insert(ctx, balance)
}
func (this balanceStore) Update(ctx context.Context, balance *Balance) error {
func (this balanceTable) Update(ctx context.Context, balance *Balance) error {
return this.table.Update(ctx, balance)
}
func (this balanceStore) Save(ctx context.Context, balance *Balance) error {
func (this balanceTable) Save(ctx context.Context, balance *Balance) error {
return this.table.Save(ctx, balance)
}
func (this balanceStore) Delete(ctx context.Context, balance *Balance) error {
func (this balanceTable) 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) {
func (this balanceTable) 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) {
func (this balanceTable) Get(ctx context.Context, address string, denom string) (*Balance, error) {
var balance Balance
found, err := this.table.PrimaryKey().Get(ctx, &balance, address, denom)
if err != nil {
@ -112,37 +112,37 @@ func (this balanceStore) Get(ctx context.Context, address string, denom string)
return &balance, nil
}
func (this balanceStore) List(ctx context.Context, prefixKey BalanceIndexKey, opts ...ormlist.Option) (BalanceIterator, error) {
func (this balanceTable) List(ctx context.Context, prefixKey BalanceIndexKey, opts ...ormlist.Option) (BalanceIterator, error) {
it, err := this.table.GetIndexByID(prefixKey.id()).List(ctx, prefixKey.values(), opts...)
return BalanceIterator{it}, err
}
func (this balanceStore) ListRange(ctx context.Context, from, to BalanceIndexKey, opts ...ormlist.Option) (BalanceIterator, error) {
func (this balanceTable) ListRange(ctx context.Context, from, to BalanceIndexKey, opts ...ormlist.Option) (BalanceIterator, error) {
it, err := this.table.GetIndexByID(from.id()).ListRange(ctx, from.values(), to.values(), opts...)
return BalanceIterator{it}, err
}
func (this balanceStore) DeleteBy(ctx context.Context, prefixKey BalanceIndexKey) error {
func (this balanceTable) DeleteBy(ctx context.Context, prefixKey BalanceIndexKey) error {
return this.table.GetIndexByID(prefixKey.id()).DeleteBy(ctx, prefixKey.values()...)
}
func (this balanceStore) DeleteRange(ctx context.Context, from, to BalanceIndexKey) error {
func (this balanceTable) DeleteRange(ctx context.Context, from, to BalanceIndexKey) error {
return this.table.GetIndexByID(from.id()).DeleteRange(ctx, from.values(), to.values())
}
func (this balanceStore) doNotImplement() {}
func (this balanceTable) doNotImplement() {}
var _ BalanceStore = balanceStore{}
var _ BalanceTable = balanceTable{}
func NewBalanceStore(db ormtable.Schema) (BalanceStore, error) {
func NewBalanceTable(db ormtable.Schema) (BalanceTable, error) {
table := db.GetTable(&Balance{})
if table == nil {
return nil, ormerrors.TableNotFound.Wrap(string((&Balance{}).ProtoReflect().Descriptor().FullName()))
}
return balanceStore{table}, nil
return balanceTable{table}, nil
}
type SupplyStore interface {
type SupplyTable interface {
Insert(ctx context.Context, supply *Supply) error
Update(ctx context.Context, supply *Supply) error
Save(ctx context.Context, supply *Supply) error
@ -190,31 +190,31 @@ func (this SupplyDenomIndexKey) WithDenom(denom string) SupplyDenomIndexKey {
return this
}
type supplyStore struct {
type supplyTable struct {
table ormtable.Table
}
func (this supplyStore) Insert(ctx context.Context, supply *Supply) error {
func (this supplyTable) Insert(ctx context.Context, supply *Supply) error {
return this.table.Insert(ctx, supply)
}
func (this supplyStore) Update(ctx context.Context, supply *Supply) error {
func (this supplyTable) Update(ctx context.Context, supply *Supply) error {
return this.table.Update(ctx, supply)
}
func (this supplyStore) Save(ctx context.Context, supply *Supply) error {
func (this supplyTable) Save(ctx context.Context, supply *Supply) error {
return this.table.Save(ctx, supply)
}
func (this supplyStore) Delete(ctx context.Context, supply *Supply) error {
func (this supplyTable) 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) {
func (this supplyTable) 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) {
func (this supplyTable) Get(ctx context.Context, denom string) (*Supply, error) {
var supply Supply
found, err := this.table.PrimaryKey().Get(ctx, &supply, denom)
if err != nil {
@ -226,53 +226,53 @@ func (this supplyStore) Get(ctx context.Context, denom string) (*Supply, error)
return &supply, nil
}
func (this supplyStore) List(ctx context.Context, prefixKey SupplyIndexKey, opts ...ormlist.Option) (SupplyIterator, error) {
func (this supplyTable) List(ctx context.Context, prefixKey SupplyIndexKey, opts ...ormlist.Option) (SupplyIterator, error) {
it, err := this.table.GetIndexByID(prefixKey.id()).List(ctx, prefixKey.values(), opts...)
return SupplyIterator{it}, err
}
func (this supplyStore) ListRange(ctx context.Context, from, to SupplyIndexKey, opts ...ormlist.Option) (SupplyIterator, error) {
func (this supplyTable) ListRange(ctx context.Context, from, to SupplyIndexKey, opts ...ormlist.Option) (SupplyIterator, error) {
it, err := this.table.GetIndexByID(from.id()).ListRange(ctx, from.values(), to.values(), opts...)
return SupplyIterator{it}, err
}
func (this supplyStore) DeleteBy(ctx context.Context, prefixKey SupplyIndexKey) error {
func (this supplyTable) DeleteBy(ctx context.Context, prefixKey SupplyIndexKey) error {
return this.table.GetIndexByID(prefixKey.id()).DeleteBy(ctx, prefixKey.values()...)
}
func (this supplyStore) DeleteRange(ctx context.Context, from, to SupplyIndexKey) error {
func (this supplyTable) DeleteRange(ctx context.Context, from, to SupplyIndexKey) error {
return this.table.GetIndexByID(from.id()).DeleteRange(ctx, from.values(), to.values())
}
func (this supplyStore) doNotImplement() {}
func (this supplyTable) doNotImplement() {}
var _ SupplyStore = supplyStore{}
var _ SupplyTable = supplyTable{}
func NewSupplyStore(db ormtable.Schema) (SupplyStore, error) {
func NewSupplyTable(db ormtable.Schema) (SupplyTable, error) {
table := db.GetTable(&Supply{})
if table == nil {
return nil, ormerrors.TableNotFound.Wrap(string((&Supply{}).ProtoReflect().Descriptor().FullName()))
}
return supplyStore{table}, nil
return supplyTable{table}, nil
}
type BankStore interface {
BalanceStore() BalanceStore
SupplyStore() SupplyStore
BalanceTable() BalanceTable
SupplyTable() SupplyTable
doNotImplement()
}
type bankStore struct {
balance BalanceStore
supply SupplyStore
balance BalanceTable
supply SupplyTable
}
func (x bankStore) BalanceStore() BalanceStore {
func (x bankStore) BalanceTable() BalanceTable {
return x.balance
}
func (x bankStore) SupplyStore() SupplyStore {
func (x bankStore) SupplyTable() SupplyTable {
return x.supply
}
@ -281,18 +281,18 @@ func (bankStore) doNotImplement() {}
var _ BankStore = bankStore{}
func NewBankStore(db ormtable.Schema) (BankStore, error) {
balanceStore, err := NewBalanceStore(db)
balanceTable, err := NewBalanceTable(db)
if err != nil {
return nil, err
}
supplyStore, err := NewSupplyStore(db)
supplyTable, err := NewSupplyTable(db)
if err != nil {
return nil, err
}
return bankStore{
balanceStore,
supplyStore,
balanceTable,
supplyTable,
}, nil
}

View File

@ -10,7 +10,7 @@ import (
ormerrors "github.com/cosmos/cosmos-sdk/orm/types/ormerrors"
)
type ExampleTableStore interface {
type ExampleTableTable interface {
Insert(ctx context.Context, exampleTable *ExampleTable) error
Update(ctx context.Context, exampleTable *ExampleTable) error
Save(ctx context.Context, exampleTable *ExampleTable) error
@ -125,31 +125,31 @@ func (this ExampleTableBzStrIndexKey) WithBzStr(bz []byte, str string) ExampleTa
return this
}
type exampleTableStore struct {
type exampleTableTable struct {
table ormtable.Table
}
func (this exampleTableStore) Insert(ctx context.Context, exampleTable *ExampleTable) error {
func (this exampleTableTable) Insert(ctx context.Context, exampleTable *ExampleTable) error {
return this.table.Insert(ctx, exampleTable)
}
func (this exampleTableStore) Update(ctx context.Context, exampleTable *ExampleTable) error {
func (this exampleTableTable) Update(ctx context.Context, exampleTable *ExampleTable) error {
return this.table.Update(ctx, exampleTable)
}
func (this exampleTableStore) Save(ctx context.Context, exampleTable *ExampleTable) error {
func (this exampleTableTable) Save(ctx context.Context, exampleTable *ExampleTable) error {
return this.table.Save(ctx, exampleTable)
}
func (this exampleTableStore) Delete(ctx context.Context, exampleTable *ExampleTable) error {
func (this exampleTableTable) 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) {
func (this exampleTableTable) 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) {
func (this exampleTableTable) 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 err != nil {
@ -161,14 +161,14 @@ func (this exampleTableStore) Get(ctx context.Context, u32 uint32, i64 int64, st
return &exampleTable, nil
}
func (this exampleTableStore) HasByU64Str(ctx context.Context, u64 uint64, str string) (found bool, err error) {
func (this exampleTableTable) HasByU64Str(ctx context.Context, u64 uint64, str string) (found bool, err error) {
return this.table.GetIndexByID(1).(ormtable.UniqueIndex).Has(ctx,
u64,
str,
)
}
func (this exampleTableStore) GetByU64Str(ctx context.Context, u64 uint64, str string) (*ExampleTable, error) {
func (this exampleTableTable) GetByU64Str(ctx context.Context, u64 uint64, str string) (*ExampleTable, error) {
var exampleTable ExampleTable
found, err := this.table.GetIndexByID(1).(ormtable.UniqueIndex).Get(ctx, &exampleTable,
u64,
@ -183,37 +183,37 @@ func (this exampleTableStore) GetByU64Str(ctx context.Context, u64 uint64, str s
return &exampleTable, nil
}
func (this exampleTableStore) List(ctx context.Context, prefixKey ExampleTableIndexKey, opts ...ormlist.Option) (ExampleTableIterator, error) {
func (this exampleTableTable) List(ctx context.Context, prefixKey ExampleTableIndexKey, opts ...ormlist.Option) (ExampleTableIterator, error) {
it, err := this.table.GetIndexByID(prefixKey.id()).List(ctx, prefixKey.values(), opts...)
return ExampleTableIterator{it}, err
}
func (this exampleTableStore) ListRange(ctx context.Context, from, to ExampleTableIndexKey, opts ...ormlist.Option) (ExampleTableIterator, error) {
func (this exampleTableTable) ListRange(ctx context.Context, from, to ExampleTableIndexKey, opts ...ormlist.Option) (ExampleTableIterator, error) {
it, err := this.table.GetIndexByID(from.id()).ListRange(ctx, from.values(), to.values(), opts...)
return ExampleTableIterator{it}, err
}
func (this exampleTableStore) DeleteBy(ctx context.Context, prefixKey ExampleTableIndexKey) error {
func (this exampleTableTable) DeleteBy(ctx context.Context, prefixKey ExampleTableIndexKey) error {
return this.table.GetIndexByID(prefixKey.id()).DeleteBy(ctx, prefixKey.values()...)
}
func (this exampleTableStore) DeleteRange(ctx context.Context, from, to ExampleTableIndexKey) error {
func (this exampleTableTable) DeleteRange(ctx context.Context, from, to ExampleTableIndexKey) error {
return this.table.GetIndexByID(from.id()).DeleteRange(ctx, from.values(), to.values())
}
func (this exampleTableStore) doNotImplement() {}
func (this exampleTableTable) doNotImplement() {}
var _ ExampleTableStore = exampleTableStore{}
var _ ExampleTableTable = exampleTableTable{}
func NewExampleTableStore(db ormtable.Schema) (ExampleTableStore, error) {
func NewExampleTableTable(db ormtable.Schema) (ExampleTableTable, error) {
table := db.GetTable(&ExampleTable{})
if table == nil {
return nil, ormerrors.TableNotFound.Wrap(string((&ExampleTable{}).ProtoReflect().Descriptor().FullName()))
}
return exampleTableStore{table}, nil
return exampleTableTable{table}, nil
}
type ExampleAutoIncrementTableStore interface {
type ExampleAutoIncrementTableTable interface {
Insert(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error
InsertReturningID(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) (uint64, error)
Update(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error
@ -278,35 +278,35 @@ func (this ExampleAutoIncrementTableXIndexKey) WithX(x string) ExampleAutoIncrem
return this
}
type exampleAutoIncrementTableStore struct {
type exampleAutoIncrementTableTable struct {
table ormtable.AutoIncrementTable
}
func (this exampleAutoIncrementTableStore) Insert(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error {
func (this exampleAutoIncrementTableTable) Insert(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error {
return this.table.Insert(ctx, exampleAutoIncrementTable)
}
func (this exampleAutoIncrementTableStore) Update(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error {
func (this exampleAutoIncrementTableTable) Update(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error {
return this.table.Update(ctx, exampleAutoIncrementTable)
}
func (this exampleAutoIncrementTableStore) Save(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error {
func (this exampleAutoIncrementTableTable) Save(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error {
return this.table.Save(ctx, exampleAutoIncrementTable)
}
func (this exampleAutoIncrementTableStore) Delete(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error {
func (this exampleAutoIncrementTableTable) Delete(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error {
return this.table.Delete(ctx, exampleAutoIncrementTable)
}
func (this exampleAutoIncrementTableStore) InsertReturningID(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) (uint64, error) {
func (this exampleAutoIncrementTableTable) InsertReturningID(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) (uint64, error) {
return this.table.InsertReturningID(ctx, exampleAutoIncrementTable)
}
func (this exampleAutoIncrementTableStore) Has(ctx context.Context, id uint64) (found bool, err error) {
func (this exampleAutoIncrementTableTable) 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) {
func (this exampleAutoIncrementTableTable) Get(ctx context.Context, id uint64) (*ExampleAutoIncrementTable, error) {
var exampleAutoIncrementTable ExampleAutoIncrementTable
found, err := this.table.PrimaryKey().Get(ctx, &exampleAutoIncrementTable, id)
if err != nil {
@ -318,13 +318,13 @@ func (this exampleAutoIncrementTableStore) Get(ctx context.Context, id uint64) (
return &exampleAutoIncrementTable, nil
}
func (this exampleAutoIncrementTableStore) HasByX(ctx context.Context, x string) (found bool, err error) {
func (this exampleAutoIncrementTableTable) HasByX(ctx context.Context, x string) (found bool, err error) {
return this.table.GetIndexByID(1).(ormtable.UniqueIndex).Has(ctx,
x,
)
}
func (this exampleAutoIncrementTableStore) GetByX(ctx context.Context, x string) (*ExampleAutoIncrementTable, error) {
func (this exampleAutoIncrementTableTable) GetByX(ctx context.Context, x string) (*ExampleAutoIncrementTable, error) {
var exampleAutoIncrementTable ExampleAutoIncrementTable
found, err := this.table.GetIndexByID(1).(ormtable.UniqueIndex).Get(ctx, &exampleAutoIncrementTable,
x,
@ -338,89 +338,89 @@ func (this exampleAutoIncrementTableStore) GetByX(ctx context.Context, x string)
return &exampleAutoIncrementTable, nil
}
func (this exampleAutoIncrementTableStore) List(ctx context.Context, prefixKey ExampleAutoIncrementTableIndexKey, opts ...ormlist.Option) (ExampleAutoIncrementTableIterator, error) {
func (this exampleAutoIncrementTableTable) List(ctx context.Context, prefixKey ExampleAutoIncrementTableIndexKey, opts ...ormlist.Option) (ExampleAutoIncrementTableIterator, error) {
it, err := this.table.GetIndexByID(prefixKey.id()).List(ctx, prefixKey.values(), opts...)
return ExampleAutoIncrementTableIterator{it}, err
}
func (this exampleAutoIncrementTableStore) ListRange(ctx context.Context, from, to ExampleAutoIncrementTableIndexKey, opts ...ormlist.Option) (ExampleAutoIncrementTableIterator, error) {
func (this exampleAutoIncrementTableTable) ListRange(ctx context.Context, from, to ExampleAutoIncrementTableIndexKey, opts ...ormlist.Option) (ExampleAutoIncrementTableIterator, error) {
it, err := this.table.GetIndexByID(from.id()).ListRange(ctx, from.values(), to.values(), opts...)
return ExampleAutoIncrementTableIterator{it}, err
}
func (this exampleAutoIncrementTableStore) DeleteBy(ctx context.Context, prefixKey ExampleAutoIncrementTableIndexKey) error {
func (this exampleAutoIncrementTableTable) DeleteBy(ctx context.Context, prefixKey ExampleAutoIncrementTableIndexKey) error {
return this.table.GetIndexByID(prefixKey.id()).DeleteBy(ctx, prefixKey.values()...)
}
func (this exampleAutoIncrementTableStore) DeleteRange(ctx context.Context, from, to ExampleAutoIncrementTableIndexKey) error {
func (this exampleAutoIncrementTableTable) DeleteRange(ctx context.Context, from, to ExampleAutoIncrementTableIndexKey) error {
return this.table.GetIndexByID(from.id()).DeleteRange(ctx, from.values(), to.values())
}
func (this exampleAutoIncrementTableStore) doNotImplement() {}
func (this exampleAutoIncrementTableTable) doNotImplement() {}
var _ ExampleAutoIncrementTableStore = exampleAutoIncrementTableStore{}
var _ ExampleAutoIncrementTableTable = exampleAutoIncrementTableTable{}
func NewExampleAutoIncrementTableStore(db ormtable.Schema) (ExampleAutoIncrementTableStore, error) {
func NewExampleAutoIncrementTableTable(db ormtable.Schema) (ExampleAutoIncrementTableTable, error) {
table := db.GetTable(&ExampleAutoIncrementTable{})
if table == nil {
return nil, ormerrors.TableNotFound.Wrap(string((&ExampleAutoIncrementTable{}).ProtoReflect().Descriptor().FullName()))
}
return exampleAutoIncrementTableStore{table.(ormtable.AutoIncrementTable)}, nil
return exampleAutoIncrementTableTable{table.(ormtable.AutoIncrementTable)}, nil
}
// singleton store
type ExampleSingletonStore interface {
type ExampleSingletonTable interface {
Get(ctx context.Context) (*ExampleSingleton, error)
Save(ctx context.Context, exampleSingleton *ExampleSingleton) error
}
type exampleSingletonStore struct {
type exampleSingletonTable struct {
table ormtable.Table
}
var _ ExampleSingletonStore = exampleSingletonStore{}
var _ ExampleSingletonTable = exampleSingletonTable{}
func (x exampleSingletonStore) Get(ctx context.Context) (*ExampleSingleton, error) {
func (x exampleSingletonTable) Get(ctx context.Context) (*ExampleSingleton, error) {
exampleSingleton := &ExampleSingleton{}
_, err := x.table.Get(ctx, exampleSingleton)
return exampleSingleton, err
}
func (x exampleSingletonStore) Save(ctx context.Context, exampleSingleton *ExampleSingleton) error {
func (x exampleSingletonTable) Save(ctx context.Context, exampleSingleton *ExampleSingleton) error {
return x.table.Save(ctx, exampleSingleton)
}
func NewExampleSingletonStore(db ormtable.Schema) (ExampleSingletonStore, error) {
func NewExampleSingletonTable(db ormtable.Schema) (ExampleSingletonTable, error) {
table := db.GetTable(&ExampleSingleton{})
if table == nil {
return nil, ormerrors.TableNotFound.Wrap(string((&ExampleSingleton{}).ProtoReflect().Descriptor().FullName()))
}
return &exampleSingletonStore{table}, nil
return &exampleSingletonTable{table}, nil
}
type TestSchemaStore interface {
ExampleTableStore() ExampleTableStore
ExampleAutoIncrementTableStore() ExampleAutoIncrementTableStore
ExampleSingletonStore() ExampleSingletonStore
ExampleTableTable() ExampleTableTable
ExampleAutoIncrementTableTable() ExampleAutoIncrementTableTable
ExampleSingletonTable() ExampleSingletonTable
doNotImplement()
}
type testSchemaStore struct {
exampleTable ExampleTableStore
exampleAutoIncrementTable ExampleAutoIncrementTableStore
exampleSingleton ExampleSingletonStore
exampleTable ExampleTableTable
exampleAutoIncrementTable ExampleAutoIncrementTableTable
exampleSingleton ExampleSingletonTable
}
func (x testSchemaStore) ExampleTableStore() ExampleTableStore {
func (x testSchemaStore) ExampleTableTable() ExampleTableTable {
return x.exampleTable
}
func (x testSchemaStore) ExampleAutoIncrementTableStore() ExampleAutoIncrementTableStore {
func (x testSchemaStore) ExampleAutoIncrementTableTable() ExampleAutoIncrementTableTable {
return x.exampleAutoIncrementTable
}
func (x testSchemaStore) ExampleSingletonStore() ExampleSingletonStore {
func (x testSchemaStore) ExampleSingletonTable() ExampleSingletonTable {
return x.exampleSingleton
}
@ -429,24 +429,24 @@ func (testSchemaStore) doNotImplement() {}
var _ TestSchemaStore = testSchemaStore{}
func NewTestSchemaStore(db ormtable.Schema) (TestSchemaStore, error) {
exampleTableStore, err := NewExampleTableStore(db)
exampleTableTable, err := NewExampleTableTable(db)
if err != nil {
return nil, err
}
exampleAutoIncrementTableStore, err := NewExampleAutoIncrementTableStore(db)
exampleAutoIncrementTableTable, err := NewExampleAutoIncrementTableTable(db)
if err != nil {
return nil, err
}
exampleSingletonStore, err := NewExampleSingletonStore(db)
exampleSingletonTable, err := NewExampleSingletonTable(db)
if err != nil {
return nil, err
}
return testSchemaStore{
exampleTableStore,
exampleAutoIncrementTableStore,
exampleSingletonStore,
exampleTableTable,
exampleAutoIncrementTableTable,
exampleSingletonTable,
}, nil
}

View File

@ -61,7 +61,7 @@ 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, err := k.store.SupplyStore().Get(ctx, denom)
supply, err := k.store.SupplyTable().Get(ctx, denom)
if err != nil && !ormerrors.IsNotFound(err) {
return err
}
@ -72,7 +72,7 @@ func (k keeper) Mint(ctx context.Context, acct, denom string, amount uint64) err
supply.Amount = supply.Amount + amount
}
err = k.store.SupplyStore().Save(ctx, supply)
err = k.store.SupplyTable().Save(ctx, supply)
if err != nil {
return err
}
@ -81,7 +81,7 @@ 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 {
supplyStore := k.store.SupplyStore()
supplyStore := k.store.SupplyTable()
supply, err := supplyStore.Get(ctx, denom)
if err != nil {
return err
@ -106,7 +106,7 @@ 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, err := k.store.BalanceStore().Get(ctx, acct, denom)
balance, err := k.store.BalanceTable().Get(ctx, acct, denom)
if err != nil {
if ormerrors.IsNotFound(err) {
return 0, nil
@ -118,7 +118,7 @@ func (k keeper) Balance(ctx context.Context, acct, denom string) (uint64, error)
}
func (k keeper) Supply(ctx context.Context, denom string) (uint64, error) {
supply, err := k.store.SupplyStore().Get(ctx, denom)
supply, err := k.store.SupplyTable().Get(ctx, denom)
if supply == nil {
if ormerrors.IsNotFound(err) {
return 0, nil
@ -130,7 +130,7 @@ func (k keeper) Supply(ctx context.Context, denom string) (uint64, error) {
}
func (k keeper) addBalance(ctx context.Context, acct, denom string, amount uint64) error {
balance, err := k.store.BalanceStore().Get(ctx, acct, denom)
balance, err := k.store.BalanceTable().Get(ctx, acct, denom)
if err != nil && !ormerrors.IsNotFound(err) {
return err
}
@ -145,11 +145,11 @@ func (k keeper) addBalance(ctx context.Context, acct, denom string, amount uint6
balance.Amount = balance.Amount + amount
}
return k.store.BalanceStore().Save(ctx, balance)
return k.store.BalanceTable().Save(ctx, balance)
}
func (k keeper) safeSubBalance(ctx context.Context, acct, denom string, amount uint64) error {
balanceStore := k.store.BalanceStore()
balanceStore := k.store.BalanceTable()
balance, err := balanceStore.Get(ctx, acct, denom)
if err != nil {
return err

View File

@ -43,7 +43,7 @@ func TestAutoIncrementScenario(t *testing.T) {
}
func runAutoIncrementScenario(t *testing.T, table ormtable.AutoIncrementTable, ctx context.Context) {
store, err := testpb.NewExampleAutoIncrementTableStore(table)
store, err := testpb.NewExampleAutoIncrementTableTable(table)
assert.NilError(t, err)
err = store.Save(ctx, &testpb.ExampleAutoIncrementTable{Id: 5})

View File

@ -21,7 +21,7 @@ func TestSingleton(t *testing.T) {
assert.NilError(t, err)
ctx := ormtable.WrapContextDefault(testkv.NewSplitMemBackend())
store, err := testpb.NewExampleSingletonStore(table)
store, err := testpb.NewExampleSingletonTable(table)
assert.NilError(t, err)
val, err := store.Get(ctx)

View File

@ -81,7 +81,7 @@ func checkEncodeDecodeEntries(t *testing.T, table ormtable.Table, store kv.Reado
func runTestScenario(t *testing.T, table ormtable.Table, backend ormtable.Backend) {
ctx := ormtable.WrapContextDefault(backend)
store, err := testpb.NewExampleTableStore(table)
store, err := testpb.NewExampleTableTable(table)
// let's create 10 data items we'll use later and give them indexes
data := []*testpb.ExampleTable{