feat: Add Table-Store (aka ORM) package - AutoUInt64Table and PrimaryKeyTable (#10415)

<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->

## Description

ref: #9237, #9156

This PR is a follow-up of #9751.
It introduces 2 new public table types: `AutoUInt64Table` and `PrimaryKeyTable` based on the parent `table` struct introduced by #9751.

Upcoming work will include:
- multi-key secondary indexes
- iterator and pagination
- import/export genesis

---

### 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...

- [x] 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
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] 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)
- [x] 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`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [x] updated the relevant documentation or specification
- [x] 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:
Marie Gauthier
2021-10-27 12:49:37 +00:00
committed by GitHub
parent 33737f4d8a
commit d8196920aa
20 changed files with 1089 additions and 68 deletions
+4
View File
@@ -6,6 +6,10 @@ var (
ErrTest = errors.Register("table_testdata", 2, "test")
)
func (g TableModel) PrimaryKeyFields() []interface{} {
return []interface{}{g.Id}
}
func (g TableModel) ValidateBasic() error {
if g.Name == "" {
return errors.Wrap(ErrTest, "name")
+118 -28
View File
@@ -323,8 +323,10 @@ func (m *BadMultiSignature) GetMaliciousField() []byte {
}
type TableModel struct {
Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Number uint64 `protobuf:"varint,3,opt,name=number,proto3" json:"number,omitempty"`
Metadata []byte `protobuf:"bytes,4,opt,name=metadata,proto3" json:"metadata,omitempty"`
}
func (m *TableModel) Reset() { *m = TableModel{} }
@@ -374,6 +376,20 @@ func (m *TableModel) GetName() string {
return ""
}
func (m *TableModel) GetNumber() uint64 {
if m != nil {
return m.Number
}
return 0
}
func (m *TableModel) GetMetadata() []byte {
if m != nil {
return m.Metadata
}
return nil
}
func init() {
proto.RegisterType((*Dog)(nil), "testdata.Dog")
proto.RegisterType((*Cat)(nil), "testdata.Cat")
@@ -387,32 +403,34 @@ func init() {
func init() { proto.RegisterFile("testdata.proto", fileDescriptor_40c4782d007dfce9) }
var fileDescriptor_40c4782d007dfce9 = []byte{
// 393 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xb1, 0x8e, 0xda, 0x40,
0x14, 0x45, 0x19, 0x0c, 0x24, 0xbc, 0x58, 0x46, 0x19, 0x51, 0x38, 0x14, 0x0e, 0x72, 0x13, 0x8a,
0x60, 0x47, 0x41, 0x69, 0xe8, 0x80, 0x28, 0xa1, 0xa1, 0x71, 0x52, 0xa5, 0x41, 0x63, 0x3c, 0xd8,
0x23, 0xc6, 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xe4, 0xc2, 0x19, 0x83, 0x55, 0x70, 0x6e,
0x64, 0x99, 0xc9, 0x55, 0xd7, 0x0d, 0xe1, 0xfd, 0x94, 0x44, 0x8b, 0x9c, 0x2b, 0xf6, 0x8b, 0xc5,
0x19, 0x51, 0xf9, 0x96, 0x62, 0x07, 0x40, 0x56, 0x46, 0xda, 0xa8, 0x6f, 0x0c, 0xcc, 0xe0, 0x2a,
0xc1, 0x9f, 0xa0, 0x93, 0x12, 0xce, 0x56, 0x4c, 0xe4, 0x72, 0xb9, 0x66, 0x94, 0x47, 0x76, 0xb3,
0x8f, 0x06, 0x66, 0x60, 0xbd, 0xc4, 0x3f, 0x8a, 0x74, 0xdc, 0x38, 0xdc, 0x7f, 0x44, 0xee, 0x17,
0x80, 0xdf, 0x24, 0xe4, 0x74, 0x21, 0x22, 0xca, 0xb1, 0x05, 0x75, 0x16, 0xe9, 0x0d, 0x1b, 0x41,
0x9d, 0x45, 0xaf, 0xfd, 0xa9, 0xe9, 0xfc, 0xe1, 0xe8, 0xa0, 0xc3, 0xd1, 0x41, 0x4f, 0x47, 0x07,
0xdd, 0x9d, 0x9c, 0xda, 0xe1, 0xe4, 0xd4, 0x1e, 0x4f, 0x4e, 0xed, 0x8f, 0x17, 0x33, 0x95, 0xe4,
0xa1, 0xb7, 0x12, 0xa9, 0xbf, 0x12, 0x32, 0x15, 0xf2, 0xfc, 0x18, 0xca, 0x68, 0xe3, 0x17, 0xa7,
0x94, 0x2b, 0xc6, 0xfd, 0xea, 0xa6, 0xc2, 0x96, 0xfe, 0xf6, 0xd1, 0x73, 0x00, 0x00, 0x00, 0xff,
0xff, 0x7a, 0x9a, 0x17, 0x6f, 0x76, 0x02, 0x00, 0x00,
// 419 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0xb1, 0x6e, 0xdb, 0x30,
0x10, 0x35, 0x2d, 0xd9, 0x8d, 0xaf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4, 0x21, 0x69, 0xd6, 0xaf, 0x36, 0x5c, 0x24, 0xfd, 0x1e,
0x66, 0x63, 0xfb, 0x5e, 0x97, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0xb5, 0x8f, 0xef, 0x9c, 0xaa,
0x02, 0x00, 0x00,
}
func (m *Dog) Marshal() (dAtA []byte, err error) {
@@ -660,6 +678,18 @@ func (m *TableModel) MarshalToSizedBuffer(dAtA []byte) (int, error) {
_ = i
var l int
_ = l
if len(m.Metadata) > 0 {
i -= len(m.Metadata)
copy(dAtA[i:], m.Metadata)
i = encodeVarintTestdata(dAtA, i, uint64(len(m.Metadata)))
i--
dAtA[i] = 0x22
}
if m.Number != 0 {
i = encodeVarintTestdata(dAtA, i, uint64(m.Number))
i--
dAtA[i] = 0x18
}
if len(m.Name) > 0 {
i -= len(m.Name)
copy(dAtA[i:], m.Name)
@@ -796,6 +826,13 @@ func (m *TableModel) Size() (n int) {
if l > 0 {
n += 1 + l + sovTestdata(uint64(l))
}
if m.Number != 0 {
n += 1 + sovTestdata(uint64(m.Number))
}
l = len(m.Metadata)
if l > 0 {
n += 1 + l + sovTestdata(uint64(l))
}
return n
}
@@ -1494,6 +1531,59 @@ func (m *TableModel) Unmarshal(dAtA []byte) error {
}
m.Name = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 3:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Number", wireType)
}
m.Number = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTestdata
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Number |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
case 4:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Metadata", wireType)
}
var byteLen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTestdata
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
byteLen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if byteLen < 0 {
return ErrInvalidLengthTestdata
}
postIndex := iNdEx + byteLen
if postIndex < 0 {
return ErrInvalidLengthTestdata
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Metadata = append(m.Metadata[:0], dAtA[iNdEx:postIndex]...)
if m.Metadata == nil {
m.Metadata = []byte{}
}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipTestdata(dAtA[iNdEx:])
+2
View File
@@ -39,4 +39,6 @@ message BadMultiSignature {
message TableModel {
uint64 id = 1;
string name = 2;
uint64 number = 3;
bytes metadata = 4;
}