refactor(ORM)!: InsertReturningID -> InsertReturning<PrimaryKeyName> (#11659)
## Description - changes the generated function signature for InsertReturningID to InsertReturning[AutoIncrement Field Name] Closes: #11655 --- ### 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:
parent
16c8e2739f
commit
f6150bd4af
@ -61,7 +61,7 @@ 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)")
|
||||
t.P("InsertReturning", t.fieldsToCamelCase(t.table.PrimaryKey.Fields), "(ctx ", contextPkg.Ident("Context"), ", ", t.param(t.msg.GoIdent.GoName), " *", t.QualifiedGoIdent(t.msg.GoIdent), ") (uint64, 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")
|
||||
@ -180,8 +180,8 @@ func (t tableGen) genTableImpl() {
|
||||
}
|
||||
|
||||
if t.table.PrimaryKey.AutoIncrement {
|
||||
t.P(receiver, "InsertReturningID(ctx ", contextPkg.Ident("Context"), ", ", varName, " *", varTypeName, ") (uint64, error) {")
|
||||
t.P("return ", receiverVar, ".table.InsertReturningID(ctx, ", varName, ")")
|
||||
t.P(receiver, "InsertReturning", t.fieldsToCamelCase(t.table.PrimaryKey.Fields), "(ctx ", contextPkg.Ident("Context"), ", ", varName, " *", varTypeName, ") (uint64, error) {")
|
||||
t.P("return ", receiverVar, ".table.InsertReturningPKey(ctx, ", varName, ")")
|
||||
t.P("}")
|
||||
t.P()
|
||||
}
|
||||
|
||||
@ -215,7 +215,7 @@ func NewExampleTableTable(db ormtable.Schema) (ExampleTableTable, error) {
|
||||
|
||||
type ExampleAutoIncrementTableTable interface {
|
||||
Insert(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error
|
||||
InsertReturningID(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) (uint64, error)
|
||||
InsertReturningId(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) (uint64, error)
|
||||
Update(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error
|
||||
Save(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error
|
||||
Delete(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) error
|
||||
@ -298,8 +298,8 @@ func (this exampleAutoIncrementTableTable) Delete(ctx context.Context, exampleAu
|
||||
return this.table.Delete(ctx, exampleAutoIncrementTable)
|
||||
}
|
||||
|
||||
func (this exampleAutoIncrementTableTable) InsertReturningID(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) (uint64, error) {
|
||||
return this.table.InsertReturningID(ctx, exampleAutoIncrementTable)
|
||||
func (this exampleAutoIncrementTableTable) InsertReturningId(ctx context.Context, exampleAutoIncrementTable *ExampleAutoIncrementTable) (uint64, error) {
|
||||
return this.table.InsertReturningPKey(ctx, exampleAutoIncrementTable)
|
||||
}
|
||||
|
||||
func (this exampleAutoIncrementTableTable) Has(ctx context.Context, id uint64) (found bool, err error) {
|
||||
@ -400,7 +400,7 @@ func NewExampleSingletonTable(db ormtable.Schema) (ExampleSingletonTable, error)
|
||||
|
||||
type ExampleTimestampTable interface {
|
||||
Insert(ctx context.Context, exampleTimestamp *ExampleTimestamp) error
|
||||
InsertReturningID(ctx context.Context, exampleTimestamp *ExampleTimestamp) (uint64, error)
|
||||
InsertReturningId(ctx context.Context, exampleTimestamp *ExampleTimestamp) (uint64, error)
|
||||
Update(ctx context.Context, exampleTimestamp *ExampleTimestamp) error
|
||||
Save(ctx context.Context, exampleTimestamp *ExampleTimestamp) error
|
||||
Delete(ctx context.Context, exampleTimestamp *ExampleTimestamp) error
|
||||
@ -480,8 +480,8 @@ func (this exampleTimestampTable) Delete(ctx context.Context, exampleTimestamp *
|
||||
return this.table.Delete(ctx, exampleTimestamp)
|
||||
}
|
||||
|
||||
func (this exampleTimestampTable) InsertReturningID(ctx context.Context, exampleTimestamp *ExampleTimestamp) (uint64, error) {
|
||||
return this.table.InsertReturningID(ctx, exampleTimestamp)
|
||||
func (this exampleTimestampTable) InsertReturningId(ctx context.Context, exampleTimestamp *ExampleTimestamp) (uint64, error) {
|
||||
return this.table.InsertReturningPKey(ctx, exampleTimestamp)
|
||||
}
|
||||
|
||||
func (this exampleTimestampTable) Has(ctx context.Context, id uint64) (found bool, err error) {
|
||||
@ -680,12 +680,132 @@ func NewSimpleExampleTable(db ormtable.Schema) (SimpleExampleTable, error) {
|
||||
return simpleExampleTable{table}, nil
|
||||
}
|
||||
|
||||
type ExampleAutoIncFieldNameTable interface {
|
||||
Insert(ctx context.Context, exampleAutoIncFieldName *ExampleAutoIncFieldName) error
|
||||
InsertReturningFoo(ctx context.Context, exampleAutoIncFieldName *ExampleAutoIncFieldName) (uint64, error)
|
||||
Update(ctx context.Context, exampleAutoIncFieldName *ExampleAutoIncFieldName) error
|
||||
Save(ctx context.Context, exampleAutoIncFieldName *ExampleAutoIncFieldName) error
|
||||
Delete(ctx context.Context, exampleAutoIncFieldName *ExampleAutoIncFieldName) error
|
||||
Has(ctx context.Context, foo uint64) (found bool, err error)
|
||||
// Get returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found.
|
||||
Get(ctx context.Context, foo uint64) (*ExampleAutoIncFieldName, error)
|
||||
List(ctx context.Context, prefixKey ExampleAutoIncFieldNameIndexKey, opts ...ormlist.Option) (ExampleAutoIncFieldNameIterator, error)
|
||||
ListRange(ctx context.Context, from, to ExampleAutoIncFieldNameIndexKey, opts ...ormlist.Option) (ExampleAutoIncFieldNameIterator, error)
|
||||
DeleteBy(ctx context.Context, prefixKey ExampleAutoIncFieldNameIndexKey) error
|
||||
DeleteRange(ctx context.Context, from, to ExampleAutoIncFieldNameIndexKey) error
|
||||
|
||||
doNotImplement()
|
||||
}
|
||||
|
||||
type ExampleAutoIncFieldNameIterator struct {
|
||||
ormtable.Iterator
|
||||
}
|
||||
|
||||
func (i ExampleAutoIncFieldNameIterator) Value() (*ExampleAutoIncFieldName, error) {
|
||||
var exampleAutoIncFieldName ExampleAutoIncFieldName
|
||||
err := i.UnmarshalMessage(&exampleAutoIncFieldName)
|
||||
return &exampleAutoIncFieldName, err
|
||||
}
|
||||
|
||||
type ExampleAutoIncFieldNameIndexKey interface {
|
||||
id() uint32
|
||||
values() []interface{}
|
||||
exampleAutoIncFieldNameIndexKey()
|
||||
}
|
||||
|
||||
// primary key starting index..
|
||||
type ExampleAutoIncFieldNamePrimaryKey = ExampleAutoIncFieldNameFooIndexKey
|
||||
|
||||
type ExampleAutoIncFieldNameFooIndexKey struct {
|
||||
vs []interface{}
|
||||
}
|
||||
|
||||
func (x ExampleAutoIncFieldNameFooIndexKey) id() uint32 { return 0 }
|
||||
func (x ExampleAutoIncFieldNameFooIndexKey) values() []interface{} { return x.vs }
|
||||
func (x ExampleAutoIncFieldNameFooIndexKey) exampleAutoIncFieldNameIndexKey() {}
|
||||
|
||||
func (this ExampleAutoIncFieldNameFooIndexKey) WithFoo(foo uint64) ExampleAutoIncFieldNameFooIndexKey {
|
||||
this.vs = []interface{}{foo}
|
||||
return this
|
||||
}
|
||||
|
||||
type exampleAutoIncFieldNameTable struct {
|
||||
table ormtable.AutoIncrementTable
|
||||
}
|
||||
|
||||
func (this exampleAutoIncFieldNameTable) Insert(ctx context.Context, exampleAutoIncFieldName *ExampleAutoIncFieldName) error {
|
||||
return this.table.Insert(ctx, exampleAutoIncFieldName)
|
||||
}
|
||||
|
||||
func (this exampleAutoIncFieldNameTable) Update(ctx context.Context, exampleAutoIncFieldName *ExampleAutoIncFieldName) error {
|
||||
return this.table.Update(ctx, exampleAutoIncFieldName)
|
||||
}
|
||||
|
||||
func (this exampleAutoIncFieldNameTable) Save(ctx context.Context, exampleAutoIncFieldName *ExampleAutoIncFieldName) error {
|
||||
return this.table.Save(ctx, exampleAutoIncFieldName)
|
||||
}
|
||||
|
||||
func (this exampleAutoIncFieldNameTable) Delete(ctx context.Context, exampleAutoIncFieldName *ExampleAutoIncFieldName) error {
|
||||
return this.table.Delete(ctx, exampleAutoIncFieldName)
|
||||
}
|
||||
|
||||
func (this exampleAutoIncFieldNameTable) InsertReturningFoo(ctx context.Context, exampleAutoIncFieldName *ExampleAutoIncFieldName) (uint64, error) {
|
||||
return this.table.InsertReturningPKey(ctx, exampleAutoIncFieldName)
|
||||
}
|
||||
|
||||
func (this exampleAutoIncFieldNameTable) Has(ctx context.Context, foo uint64) (found bool, err error) {
|
||||
return this.table.PrimaryKey().Has(ctx, foo)
|
||||
}
|
||||
|
||||
func (this exampleAutoIncFieldNameTable) Get(ctx context.Context, foo uint64) (*ExampleAutoIncFieldName, error) {
|
||||
var exampleAutoIncFieldName ExampleAutoIncFieldName
|
||||
found, err := this.table.PrimaryKey().Get(ctx, &exampleAutoIncFieldName, foo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !found {
|
||||
return nil, ormerrors.NotFound
|
||||
}
|
||||
return &exampleAutoIncFieldName, nil
|
||||
}
|
||||
|
||||
func (this exampleAutoIncFieldNameTable) List(ctx context.Context, prefixKey ExampleAutoIncFieldNameIndexKey, opts ...ormlist.Option) (ExampleAutoIncFieldNameIterator, error) {
|
||||
it, err := this.table.GetIndexByID(prefixKey.id()).List(ctx, prefixKey.values(), opts...)
|
||||
return ExampleAutoIncFieldNameIterator{it}, err
|
||||
}
|
||||
|
||||
func (this exampleAutoIncFieldNameTable) ListRange(ctx context.Context, from, to ExampleAutoIncFieldNameIndexKey, opts ...ormlist.Option) (ExampleAutoIncFieldNameIterator, error) {
|
||||
it, err := this.table.GetIndexByID(from.id()).ListRange(ctx, from.values(), to.values(), opts...)
|
||||
return ExampleAutoIncFieldNameIterator{it}, err
|
||||
}
|
||||
|
||||
func (this exampleAutoIncFieldNameTable) DeleteBy(ctx context.Context, prefixKey ExampleAutoIncFieldNameIndexKey) error {
|
||||
return this.table.GetIndexByID(prefixKey.id()).DeleteBy(ctx, prefixKey.values()...)
|
||||
}
|
||||
|
||||
func (this exampleAutoIncFieldNameTable) DeleteRange(ctx context.Context, from, to ExampleAutoIncFieldNameIndexKey) error {
|
||||
return this.table.GetIndexByID(from.id()).DeleteRange(ctx, from.values(), to.values())
|
||||
}
|
||||
|
||||
func (this exampleAutoIncFieldNameTable) doNotImplement() {}
|
||||
|
||||
var _ ExampleAutoIncFieldNameTable = exampleAutoIncFieldNameTable{}
|
||||
|
||||
func NewExampleAutoIncFieldNameTable(db ormtable.Schema) (ExampleAutoIncFieldNameTable, error) {
|
||||
table := db.GetTable(&ExampleAutoIncFieldName{})
|
||||
if table == nil {
|
||||
return nil, ormerrors.TableNotFound.Wrap(string((&ExampleAutoIncFieldName{}).ProtoReflect().Descriptor().FullName()))
|
||||
}
|
||||
return exampleAutoIncFieldNameTable{table.(ormtable.AutoIncrementTable)}, nil
|
||||
}
|
||||
|
||||
type TestSchemaStore interface {
|
||||
ExampleTableTable() ExampleTableTable
|
||||
ExampleAutoIncrementTableTable() ExampleAutoIncrementTableTable
|
||||
ExampleSingletonTable() ExampleSingletonTable
|
||||
ExampleTimestampTable() ExampleTimestampTable
|
||||
SimpleExampleTable() SimpleExampleTable
|
||||
ExampleAutoIncFieldNameTable() ExampleAutoIncFieldNameTable
|
||||
|
||||
doNotImplement()
|
||||
}
|
||||
@ -696,6 +816,7 @@ type testSchemaStore struct {
|
||||
exampleSingleton ExampleSingletonTable
|
||||
exampleTimestamp ExampleTimestampTable
|
||||
simpleExample SimpleExampleTable
|
||||
exampleAutoIncFieldName ExampleAutoIncFieldNameTable
|
||||
}
|
||||
|
||||
func (x testSchemaStore) ExampleTableTable() ExampleTableTable {
|
||||
@ -718,6 +839,10 @@ func (x testSchemaStore) SimpleExampleTable() SimpleExampleTable {
|
||||
return x.simpleExample
|
||||
}
|
||||
|
||||
func (x testSchemaStore) ExampleAutoIncFieldNameTable() ExampleAutoIncFieldNameTable {
|
||||
return x.exampleAutoIncFieldName
|
||||
}
|
||||
|
||||
func (testSchemaStore) doNotImplement() {}
|
||||
|
||||
var _ TestSchemaStore = testSchemaStore{}
|
||||
@ -748,11 +873,17 @@ func NewTestSchemaStore(db ormtable.Schema) (TestSchemaStore, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
exampleAutoIncFieldNameTable, err := NewExampleAutoIncFieldNameTable(db)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return testSchemaStore{
|
||||
exampleTableTable,
|
||||
exampleAutoIncrementTableTable,
|
||||
exampleSingletonTable,
|
||||
exampleTimestampTable,
|
||||
simpleExampleTable,
|
||||
exampleAutoIncFieldNameTable,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -115,4 +115,14 @@ message SimpleExample {
|
||||
string name = 1;
|
||||
string unique = 2;
|
||||
string not_unique = 3;
|
||||
}
|
||||
|
||||
// ExampleAutoIncFieldName is a table for testing InsertReturning<FieldName>.
|
||||
message ExampleAutoIncFieldName {
|
||||
option (cosmos.orm.v1.table) = {
|
||||
id: 6
|
||||
primary_key: {fields: "foo" auto_increment: true}
|
||||
};
|
||||
uint64 foo = 1;
|
||||
uint64 bar = 2;
|
||||
}
|
||||
@ -1872,7 +1872,7 @@ func (x *ExampleTable_ExampleMessage) ProtoReflect() protoreflect.Message {
|
||||
}
|
||||
|
||||
func (x *ExampleTable_ExampleMessage) slowProtoReflect() protoreflect.Message {
|
||||
mi := &file_testpb_test_schema_proto_msgTypes[6]
|
||||
mi := &file_testpb_test_schema_proto_msgTypes[7]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@ -4397,6 +4397,458 @@ func (x *fastReflection_SimpleExample) ProtoMethods() *protoiface.Methods {
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
md_ExampleAutoIncFieldName protoreflect.MessageDescriptor
|
||||
fd_ExampleAutoIncFieldName_foo protoreflect.FieldDescriptor
|
||||
fd_ExampleAutoIncFieldName_bar protoreflect.FieldDescriptor
|
||||
)
|
||||
|
||||
func init() {
|
||||
file_testpb_test_schema_proto_init()
|
||||
md_ExampleAutoIncFieldName = File_testpb_test_schema_proto.Messages().ByName("ExampleAutoIncFieldName")
|
||||
fd_ExampleAutoIncFieldName_foo = md_ExampleAutoIncFieldName.Fields().ByName("foo")
|
||||
fd_ExampleAutoIncFieldName_bar = md_ExampleAutoIncFieldName.Fields().ByName("bar")
|
||||
}
|
||||
|
||||
var _ protoreflect.Message = (*fastReflection_ExampleAutoIncFieldName)(nil)
|
||||
|
||||
type fastReflection_ExampleAutoIncFieldName ExampleAutoIncFieldName
|
||||
|
||||
func (x *ExampleAutoIncFieldName) ProtoReflect() protoreflect.Message {
|
||||
return (*fastReflection_ExampleAutoIncFieldName)(x)
|
||||
}
|
||||
|
||||
func (x *ExampleAutoIncFieldName) slowProtoReflect() protoreflect.Message {
|
||||
mi := &file_testpb_test_schema_proto_msgTypes[5]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
var _fastReflection_ExampleAutoIncFieldName_messageType fastReflection_ExampleAutoIncFieldName_messageType
|
||||
var _ protoreflect.MessageType = fastReflection_ExampleAutoIncFieldName_messageType{}
|
||||
|
||||
type fastReflection_ExampleAutoIncFieldName_messageType struct{}
|
||||
|
||||
func (x fastReflection_ExampleAutoIncFieldName_messageType) Zero() protoreflect.Message {
|
||||
return (*fastReflection_ExampleAutoIncFieldName)(nil)
|
||||
}
|
||||
func (x fastReflection_ExampleAutoIncFieldName_messageType) New() protoreflect.Message {
|
||||
return new(fastReflection_ExampleAutoIncFieldName)
|
||||
}
|
||||
func (x fastReflection_ExampleAutoIncFieldName_messageType) Descriptor() protoreflect.MessageDescriptor {
|
||||
return md_ExampleAutoIncFieldName
|
||||
}
|
||||
|
||||
// Descriptor returns message descriptor, which contains only the protobuf
|
||||
// type information for the message.
|
||||
func (x *fastReflection_ExampleAutoIncFieldName) Descriptor() protoreflect.MessageDescriptor {
|
||||
return md_ExampleAutoIncFieldName
|
||||
}
|
||||
|
||||
// Type returns the message type, which encapsulates both Go and protobuf
|
||||
// type information. If the Go type information is not needed,
|
||||
// it is recommended that the message descriptor be used instead.
|
||||
func (x *fastReflection_ExampleAutoIncFieldName) Type() protoreflect.MessageType {
|
||||
return _fastReflection_ExampleAutoIncFieldName_messageType
|
||||
}
|
||||
|
||||
// New returns a newly allocated and mutable empty message.
|
||||
func (x *fastReflection_ExampleAutoIncFieldName) New() protoreflect.Message {
|
||||
return new(fastReflection_ExampleAutoIncFieldName)
|
||||
}
|
||||
|
||||
// Interface unwraps the message reflection interface and
|
||||
// returns the underlying ProtoMessage interface.
|
||||
func (x *fastReflection_ExampleAutoIncFieldName) Interface() protoreflect.ProtoMessage {
|
||||
return (*ExampleAutoIncFieldName)(x)
|
||||
}
|
||||
|
||||
// Range iterates over every populated field in an undefined order,
|
||||
// calling f for each field descriptor and value encountered.
|
||||
// Range returns immediately if f returns false.
|
||||
// While iterating, mutating operations may only be performed
|
||||
// on the current field descriptor.
|
||||
func (x *fastReflection_ExampleAutoIncFieldName) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) {
|
||||
if x.Foo != uint64(0) {
|
||||
value := protoreflect.ValueOfUint64(x.Foo)
|
||||
if !f(fd_ExampleAutoIncFieldName_foo, value) {
|
||||
return
|
||||
}
|
||||
}
|
||||
if x.Bar != uint64(0) {
|
||||
value := protoreflect.ValueOfUint64(x.Bar)
|
||||
if !f(fd_ExampleAutoIncFieldName_bar, value) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Has reports whether a field is populated.
|
||||
//
|
||||
// Some fields have the property of nullability where it is possible to
|
||||
// distinguish between the default value of a field and whether the field
|
||||
// was explicitly populated with the default value. Singular message fields,
|
||||
// member fields of a oneof, and proto2 scalar fields are nullable. Such
|
||||
// fields are populated only if explicitly set.
|
||||
//
|
||||
// In other cases (aside from the nullable cases above),
|
||||
// a proto3 scalar field is populated if it contains a non-zero value, and
|
||||
// a repeated field is populated if it is non-empty.
|
||||
func (x *fastReflection_ExampleAutoIncFieldName) Has(fd protoreflect.FieldDescriptor) bool {
|
||||
switch fd.FullName() {
|
||||
case "testpb.ExampleAutoIncFieldName.foo":
|
||||
return x.Foo != uint64(0)
|
||||
case "testpb.ExampleAutoIncFieldName.bar":
|
||||
return x.Bar != uint64(0)
|
||||
default:
|
||||
if fd.IsExtension() {
|
||||
panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ExampleAutoIncFieldName"))
|
||||
}
|
||||
panic(fmt.Errorf("message testpb.ExampleAutoIncFieldName does not contain field %s", fd.FullName()))
|
||||
}
|
||||
}
|
||||
|
||||
// Clear clears the field such that a subsequent Has call reports false.
|
||||
//
|
||||
// Clearing an extension field clears both the extension type and value
|
||||
// associated with the given field number.
|
||||
//
|
||||
// Clear is a mutating operation and unsafe for concurrent use.
|
||||
func (x *fastReflection_ExampleAutoIncFieldName) Clear(fd protoreflect.FieldDescriptor) {
|
||||
switch fd.FullName() {
|
||||
case "testpb.ExampleAutoIncFieldName.foo":
|
||||
x.Foo = uint64(0)
|
||||
case "testpb.ExampleAutoIncFieldName.bar":
|
||||
x.Bar = uint64(0)
|
||||
default:
|
||||
if fd.IsExtension() {
|
||||
panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ExampleAutoIncFieldName"))
|
||||
}
|
||||
panic(fmt.Errorf("message testpb.ExampleAutoIncFieldName does not contain field %s", fd.FullName()))
|
||||
}
|
||||
}
|
||||
|
||||
// Get retrieves the value for a field.
|
||||
//
|
||||
// For unpopulated scalars, it returns the default value, where
|
||||
// the default value of a bytes scalar is guaranteed to be a copy.
|
||||
// For unpopulated composite types, it returns an empty, read-only view
|
||||
// of the value; to obtain a mutable reference, use Mutable.
|
||||
func (x *fastReflection_ExampleAutoIncFieldName) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value {
|
||||
switch descriptor.FullName() {
|
||||
case "testpb.ExampleAutoIncFieldName.foo":
|
||||
value := x.Foo
|
||||
return protoreflect.ValueOfUint64(value)
|
||||
case "testpb.ExampleAutoIncFieldName.bar":
|
||||
value := x.Bar
|
||||
return protoreflect.ValueOfUint64(value)
|
||||
default:
|
||||
if descriptor.IsExtension() {
|
||||
panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ExampleAutoIncFieldName"))
|
||||
}
|
||||
panic(fmt.Errorf("message testpb.ExampleAutoIncFieldName does not contain field %s", descriptor.FullName()))
|
||||
}
|
||||
}
|
||||
|
||||
// Set stores the value for a field.
|
||||
//
|
||||
// For a field belonging to a oneof, it implicitly clears any other field
|
||||
// that may be currently set within the same oneof.
|
||||
// For extension fields, it implicitly stores the provided ExtensionType.
|
||||
// When setting a composite type, it is unspecified whether the stored value
|
||||
// aliases the source's memory in any way. If the composite value is an
|
||||
// empty, read-only value, then it panics.
|
||||
//
|
||||
// Set is a mutating operation and unsafe for concurrent use.
|
||||
func (x *fastReflection_ExampleAutoIncFieldName) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) {
|
||||
switch fd.FullName() {
|
||||
case "testpb.ExampleAutoIncFieldName.foo":
|
||||
x.Foo = value.Uint()
|
||||
case "testpb.ExampleAutoIncFieldName.bar":
|
||||
x.Bar = value.Uint()
|
||||
default:
|
||||
if fd.IsExtension() {
|
||||
panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ExampleAutoIncFieldName"))
|
||||
}
|
||||
panic(fmt.Errorf("message testpb.ExampleAutoIncFieldName does not contain field %s", fd.FullName()))
|
||||
}
|
||||
}
|
||||
|
||||
// Mutable returns a mutable reference to a composite type.
|
||||
//
|
||||
// If the field is unpopulated, it may allocate a composite value.
|
||||
// For a field belonging to a oneof, it implicitly clears any other field
|
||||
// that may be currently set within the same oneof.
|
||||
// For extension fields, it implicitly stores the provided ExtensionType
|
||||
// if not already stored.
|
||||
// It panics if the field does not contain a composite type.
|
||||
//
|
||||
// Mutable is a mutating operation and unsafe for concurrent use.
|
||||
func (x *fastReflection_ExampleAutoIncFieldName) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value {
|
||||
switch fd.FullName() {
|
||||
case "testpb.ExampleAutoIncFieldName.foo":
|
||||
panic(fmt.Errorf("field foo of message testpb.ExampleAutoIncFieldName is not mutable"))
|
||||
case "testpb.ExampleAutoIncFieldName.bar":
|
||||
panic(fmt.Errorf("field bar of message testpb.ExampleAutoIncFieldName is not mutable"))
|
||||
default:
|
||||
if fd.IsExtension() {
|
||||
panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ExampleAutoIncFieldName"))
|
||||
}
|
||||
panic(fmt.Errorf("message testpb.ExampleAutoIncFieldName does not contain field %s", fd.FullName()))
|
||||
}
|
||||
}
|
||||
|
||||
// NewField returns a new value that is assignable to the field
|
||||
// for the given descriptor. For scalars, this returns the default value.
|
||||
// For lists, maps, and messages, this returns a new, empty, mutable value.
|
||||
func (x *fastReflection_ExampleAutoIncFieldName) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value {
|
||||
switch fd.FullName() {
|
||||
case "testpb.ExampleAutoIncFieldName.foo":
|
||||
return protoreflect.ValueOfUint64(uint64(0))
|
||||
case "testpb.ExampleAutoIncFieldName.bar":
|
||||
return protoreflect.ValueOfUint64(uint64(0))
|
||||
default:
|
||||
if fd.IsExtension() {
|
||||
panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ExampleAutoIncFieldName"))
|
||||
}
|
||||
panic(fmt.Errorf("message testpb.ExampleAutoIncFieldName does not contain field %s", fd.FullName()))
|
||||
}
|
||||
}
|
||||
|
||||
// WhichOneof reports which field within the oneof is populated,
|
||||
// returning nil if none are populated.
|
||||
// It panics if the oneof descriptor does not belong to this message.
|
||||
func (x *fastReflection_ExampleAutoIncFieldName) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor {
|
||||
switch d.FullName() {
|
||||
default:
|
||||
panic(fmt.Errorf("%s is not a oneof field in testpb.ExampleAutoIncFieldName", d.FullName()))
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
// GetUnknown retrieves the entire list of unknown fields.
|
||||
// The caller may only mutate the contents of the RawFields
|
||||
// if the mutated bytes are stored back into the message with SetUnknown.
|
||||
func (x *fastReflection_ExampleAutoIncFieldName) GetUnknown() protoreflect.RawFields {
|
||||
return x.unknownFields
|
||||
}
|
||||
|
||||
// SetUnknown stores an entire list of unknown fields.
|
||||
// The raw fields must be syntactically valid according to the wire format.
|
||||
// An implementation may panic if this is not the case.
|
||||
// Once stored, the caller must not mutate the content of the RawFields.
|
||||
// An empty RawFields may be passed to clear the fields.
|
||||
//
|
||||
// SetUnknown is a mutating operation and unsafe for concurrent use.
|
||||
func (x *fastReflection_ExampleAutoIncFieldName) SetUnknown(fields protoreflect.RawFields) {
|
||||
x.unknownFields = fields
|
||||
}
|
||||
|
||||
// IsValid reports whether the message is valid.
|
||||
//
|
||||
// An invalid message is an empty, read-only value.
|
||||
//
|
||||
// An invalid message often corresponds to a nil pointer of the concrete
|
||||
// message type, but the details are implementation dependent.
|
||||
// Validity is not part of the protobuf data model, and may not
|
||||
// be preserved in marshaling or other operations.
|
||||
func (x *fastReflection_ExampleAutoIncFieldName) IsValid() bool {
|
||||
return x != nil
|
||||
}
|
||||
|
||||
// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations.
|
||||
// This method may return nil.
|
||||
//
|
||||
// The returned methods type is identical to
|
||||
// "google.golang.org/protobuf/runtime/protoiface".Methods.
|
||||
// Consult the protoiface package documentation for details.
|
||||
func (x *fastReflection_ExampleAutoIncFieldName) ProtoMethods() *protoiface.Methods {
|
||||
size := func(input protoiface.SizeInput) protoiface.SizeOutput {
|
||||
x := input.Message.Interface().(*ExampleAutoIncFieldName)
|
||||
if x == nil {
|
||||
return protoiface.SizeOutput{
|
||||
NoUnkeyedLiterals: input.NoUnkeyedLiterals,
|
||||
Size: 0,
|
||||
}
|
||||
}
|
||||
options := runtime.SizeInputToOptions(input)
|
||||
_ = options
|
||||
var n int
|
||||
var l int
|
||||
_ = l
|
||||
if x.Foo != 0 {
|
||||
n += 1 + runtime.Sov(uint64(x.Foo))
|
||||
}
|
||||
if x.Bar != 0 {
|
||||
n += 1 + runtime.Sov(uint64(x.Bar))
|
||||
}
|
||||
if x.unknownFields != nil {
|
||||
n += len(x.unknownFields)
|
||||
}
|
||||
return protoiface.SizeOutput{
|
||||
NoUnkeyedLiterals: input.NoUnkeyedLiterals,
|
||||
Size: n,
|
||||
}
|
||||
}
|
||||
|
||||
marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) {
|
||||
x := input.Message.Interface().(*ExampleAutoIncFieldName)
|
||||
if x == nil {
|
||||
return protoiface.MarshalOutput{
|
||||
NoUnkeyedLiterals: input.NoUnkeyedLiterals,
|
||||
Buf: input.Buf,
|
||||
}, nil
|
||||
}
|
||||
options := runtime.MarshalInputToOptions(input)
|
||||
_ = options
|
||||
size := options.Size(x)
|
||||
dAtA := make([]byte, size)
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if x.unknownFields != nil {
|
||||
i -= len(x.unknownFields)
|
||||
copy(dAtA[i:], x.unknownFields)
|
||||
}
|
||||
if x.Bar != 0 {
|
||||
i = runtime.EncodeVarint(dAtA, i, uint64(x.Bar))
|
||||
i--
|
||||
dAtA[i] = 0x10
|
||||
}
|
||||
if x.Foo != 0 {
|
||||
i = runtime.EncodeVarint(dAtA, i, uint64(x.Foo))
|
||||
i--
|
||||
dAtA[i] = 0x8
|
||||
}
|
||||
if input.Buf != nil {
|
||||
input.Buf = append(input.Buf, dAtA...)
|
||||
} else {
|
||||
input.Buf = dAtA
|
||||
}
|
||||
return protoiface.MarshalOutput{
|
||||
NoUnkeyedLiterals: input.NoUnkeyedLiterals,
|
||||
Buf: input.Buf,
|
||||
}, nil
|
||||
}
|
||||
unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) {
|
||||
x := input.Message.Interface().(*ExampleAutoIncFieldName)
|
||||
if x == nil {
|
||||
return protoiface.UnmarshalOutput{
|
||||
NoUnkeyedLiterals: input.NoUnkeyedLiterals,
|
||||
Flags: input.Flags,
|
||||
}, nil
|
||||
}
|
||||
options := runtime.UnmarshalInputToOptions(input)
|
||||
_ = options
|
||||
dAtA := input.Buf
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: ExampleAutoIncFieldName: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: ExampleAutoIncFieldName: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 0 {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Foo", wireType)
|
||||
}
|
||||
x.Foo = 0
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
x.Foo |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
case 2:
|
||||
if wireType != 0 {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Bar", wireType)
|
||||
}
|
||||
x.Bar = 0
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
x.Bar |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := runtime.Skip(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err
|
||||
}
|
||||
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
|
||||
}
|
||||
if !options.DiscardUnknown {
|
||||
x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...)
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
|
||||
}
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil
|
||||
}
|
||||
return &protoiface.Methods{
|
||||
NoUnkeyedLiterals: struct{}{},
|
||||
Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown,
|
||||
Size: size,
|
||||
Marshal: marshal,
|
||||
Unmarshal: unmarshal,
|
||||
Merge: nil,
|
||||
CheckInitialized: nil,
|
||||
}
|
||||
}
|
||||
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.27.0
|
||||
@ -4869,6 +5321,50 @@ func (x *SimpleExample) GetNotUnique() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// ExampleAutoIncFieldName is a table for testing InsertReturning<FieldName>.
|
||||
type ExampleAutoIncFieldName struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Foo uint64 `protobuf:"varint,1,opt,name=foo,proto3" json:"foo,omitempty"`
|
||||
Bar uint64 `protobuf:"varint,2,opt,name=bar,proto3" json:"bar,omitempty"`
|
||||
}
|
||||
|
||||
func (x *ExampleAutoIncFieldName) Reset() {
|
||||
*x = ExampleAutoIncFieldName{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_testpb_test_schema_proto_msgTypes[5]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *ExampleAutoIncFieldName) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ExampleAutoIncFieldName) ProtoMessage() {}
|
||||
|
||||
// Deprecated: Use ExampleAutoIncFieldName.ProtoReflect.Descriptor instead.
|
||||
func (*ExampleAutoIncFieldName) Descriptor() ([]byte, []int) {
|
||||
return file_testpb_test_schema_proto_rawDescGZIP(), []int{5}
|
||||
}
|
||||
|
||||
func (x *ExampleAutoIncFieldName) GetFoo() uint64 {
|
||||
if x != nil {
|
||||
return x.Foo
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ExampleAutoIncFieldName) GetBar() uint64 {
|
||||
if x != nil {
|
||||
return x.Bar
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type ExampleTable_ExampleMessage struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@ -4881,7 +5377,7 @@ type ExampleTable_ExampleMessage struct {
|
||||
func (x *ExampleTable_ExampleMessage) Reset() {
|
||||
*x = ExampleTable_ExampleMessage{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_testpb_test_schema_proto_msgTypes[6]
|
||||
mi := &file_testpb_test_schema_proto_msgTypes[7]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@ -4992,23 +5488,28 @@ var file_testpb_test_schema_proto_rawDesc = []byte{
|
||||
0x0a, 0x6e, 0x6f, 0x74, 0x5f, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x09, 0x6e, 0x6f, 0x74, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x3a, 0x1e, 0xf2, 0x9e,
|
||||
0xd3, 0x8e, 0x03, 0x18, 0x0a, 0x06, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x0c, 0x0a, 0x06,
|
||||
0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x10, 0x01, 0x18, 0x01, 0x18, 0x05, 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,
|
||||
0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x10, 0x01, 0x18, 0x01, 0x18, 0x05, 0x22, 0x50, 0x0a, 0x17,
|
||||
0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x41, 0x75, 0x74, 0x6f, 0x49, 0x6e, 0x63, 0x46, 0x69,
|
||||
0x65, 0x6c, 0x64, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x66, 0x6f, 0x6f, 0x18, 0x01,
|
||||
0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x61, 0x72,
|
||||
0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x62, 0x61, 0x72, 0x3a, 0x11, 0xf2, 0x9e, 0xd3,
|
||||
0x8e, 0x03, 0x0b, 0x0a, 0x07, 0x0a, 0x03, 0x66, 0x6f, 0x6f, 0x10, 0x01, 0x18, 0x06, 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 (
|
||||
@ -5024,7 +5525,7 @@ func file_testpb_test_schema_proto_rawDescGZIP() []byte {
|
||||
}
|
||||
|
||||
var file_testpb_test_schema_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
||||
var file_testpb_test_schema_proto_msgTypes = make([]protoimpl.MessageInfo, 7)
|
||||
var file_testpb_test_schema_proto_msgTypes = make([]protoimpl.MessageInfo, 8)
|
||||
var file_testpb_test_schema_proto_goTypes = []interface{}{
|
||||
(Enum)(0), // 0: testpb.Enum
|
||||
(*ExampleTable)(nil), // 1: testpb.ExampleTable
|
||||
@ -5032,23 +5533,24 @@ var file_testpb_test_schema_proto_goTypes = []interface{}{
|
||||
(*ExampleSingleton)(nil), // 3: testpb.ExampleSingleton
|
||||
(*ExampleTimestamp)(nil), // 4: testpb.ExampleTimestamp
|
||||
(*SimpleExample)(nil), // 5: testpb.SimpleExample
|
||||
nil, // 6: testpb.ExampleTable.MapEntry
|
||||
(*ExampleTable_ExampleMessage)(nil), // 7: testpb.ExampleTable.ExampleMessage
|
||||
(*timestamppb.Timestamp)(nil), // 8: google.protobuf.Timestamp
|
||||
(*durationpb.Duration)(nil), // 9: google.protobuf.Duration
|
||||
(*ExampleAutoIncFieldName)(nil), // 6: testpb.ExampleAutoIncFieldName
|
||||
nil, // 7: testpb.ExampleTable.MapEntry
|
||||
(*ExampleTable_ExampleMessage)(nil), // 8: testpb.ExampleTable.ExampleMessage
|
||||
(*timestamppb.Timestamp)(nil), // 9: google.protobuf.Timestamp
|
||||
(*durationpb.Duration)(nil), // 10: google.protobuf.Duration
|
||||
}
|
||||
var file_testpb_test_schema_proto_depIdxs = []int32{
|
||||
8, // 0: testpb.ExampleTable.ts:type_name -> google.protobuf.Timestamp
|
||||
9, // 1: testpb.ExampleTable.dur:type_name -> google.protobuf.Duration
|
||||
0, // 2: testpb.ExampleTable.e:type_name -> testpb.Enum
|
||||
6, // 3: testpb.ExampleTable.map:type_name -> testpb.ExampleTable.MapEntry
|
||||
7, // 4: testpb.ExampleTable.msg:type_name -> testpb.ExampleTable.ExampleMessage
|
||||
8, // 5: testpb.ExampleTimestamp.ts:type_name -> google.protobuf.Timestamp
|
||||
6, // [6:6] is the sub-list for method output_type
|
||||
6, // [6:6] is the sub-list for method input_type
|
||||
6, // [6:6] is the sub-list for extension type_name
|
||||
6, // [6:6] is the sub-list for extension extendee
|
||||
0, // [0:6] is the sub-list for field type_name
|
||||
9, // 0: testpb.ExampleTable.ts:type_name -> google.protobuf.Timestamp
|
||||
10, // 1: testpb.ExampleTable.dur:type_name -> google.protobuf.Duration
|
||||
0, // 2: testpb.ExampleTable.e:type_name -> testpb.Enum
|
||||
7, // 3: testpb.ExampleTable.map:type_name -> testpb.ExampleTable.MapEntry
|
||||
8, // 4: testpb.ExampleTable.msg:type_name -> testpb.ExampleTable.ExampleMessage
|
||||
9, // 5: testpb.ExampleTimestamp.ts:type_name -> google.protobuf.Timestamp
|
||||
6, // [6:6] is the sub-list for method output_type
|
||||
6, // [6:6] is the sub-list for method input_type
|
||||
6, // [6:6] is the sub-list for extension type_name
|
||||
6, // [6:6] is the sub-list for extension extendee
|
||||
0, // [0:6] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_testpb_test_schema_proto_init() }
|
||||
@ -5117,7 +5619,19 @@ func file_testpb_test_schema_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_testpb_test_schema_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
|
||||
file_testpb_test_schema_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ExampleAutoIncFieldName); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_testpb_test_schema_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ExampleTable_ExampleMessage); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@ -5139,7 +5653,7 @@ func file_testpb_test_schema_proto_init() {
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_testpb_test_schema_proto_rawDesc,
|
||||
NumEnums: 1,
|
||||
NumMessages: 7,
|
||||
NumMessages: 8,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
|
||||
@ -22,7 +22,7 @@ type autoIncrementTable struct {
|
||||
seqCodec *ormkv.SeqCodec
|
||||
}
|
||||
|
||||
func (t autoIncrementTable) InsertReturningID(ctx context.Context, message proto.Message) (newId uint64, err error) {
|
||||
func (t autoIncrementTable) InsertReturningPKey(ctx context.Context, message proto.Message) (newPK uint64, err error) {
|
||||
backend, err := t.getWriteBackend(ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@ -61,7 +61,7 @@ func (t autoIncrementTable) Update(ctx context.Context, message proto.Message) e
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *autoIncrementTable) save(ctx context.Context, backend Backend, message proto.Message, mode saveMode) (newId uint64, err error) {
|
||||
func (t *autoIncrementTable) save(ctx context.Context, backend Backend, message proto.Message, mode saveMode) (newPK uint64, err error) {
|
||||
messageRef := message.ProtoReflect()
|
||||
val := messageRef.Get(t.autoIncField).Uint()
|
||||
writer := newBatchIndexCommitmentWriter(backend)
|
||||
@ -73,12 +73,12 @@ func (t *autoIncrementTable) save(ctx context.Context, backend Backend, message
|
||||
}
|
||||
|
||||
mode = saveModeInsert
|
||||
newId, err = t.nextSeqValue(writer.IndexStore())
|
||||
newPK, err = t.nextSeqValue(writer.IndexStore())
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
messageRef.Set(t.autoIncField, protoreflect.ValueOfUint64(newId))
|
||||
messageRef.Set(t.autoIncField, protoreflect.ValueOfUint64(newPK))
|
||||
} else {
|
||||
if mode == saveModeInsert {
|
||||
return 0, ormerrors.AutoIncrementKeyAlreadySet
|
||||
@ -87,7 +87,7 @@ func (t *autoIncrementTable) save(ctx context.Context, backend Backend, message
|
||||
mode = saveModeUpdate
|
||||
}
|
||||
|
||||
return newId, t.tableImpl.doSave(ctx, writer, message, mode)
|
||||
return newPK, t.tableImpl.doSave(ctx, writer, message, mode)
|
||||
}
|
||||
|
||||
func (t *autoIncrementTable) curSeqValue(kv kv.ReadonlyStore) (uint64, error) {
|
||||
@ -121,11 +121,12 @@ func (t autoIncrementTable) EncodeEntry(entry ormkv.Entry) (k, v []byte, err err
|
||||
}
|
||||
|
||||
func (t autoIncrementTable) ValidateJSON(reader io.Reader) error {
|
||||
return t.decodeAutoIncJson(nil, reader, func(message proto.Message, maxID uint64) error {
|
||||
return t.decodeAutoIncJson(nil, reader, func(message proto.Message, maxSeq uint64) error {
|
||||
messageRef := message.ProtoReflect()
|
||||
id := messageRef.Get(t.autoIncField).Uint()
|
||||
if id > maxID {
|
||||
return fmt.Errorf("invalid ID %d, expected a value <= %d, the highest sequence number", id, maxID)
|
||||
pkey := messageRef.Get(t.autoIncField).Uint()
|
||||
if pkey > maxSeq {
|
||||
return fmt.Errorf("invalid auto increment primary key %d, expected a value <= %d, the highest "+
|
||||
"sequence number", pkey, maxSeq)
|
||||
}
|
||||
|
||||
if t.customJSONValidator != nil {
|
||||
@ -142,22 +143,23 @@ func (t autoIncrementTable) ImportJSON(ctx context.Context, reader io.Reader) er
|
||||
return err
|
||||
}
|
||||
|
||||
return t.decodeAutoIncJson(backend, reader, func(message proto.Message, maxID uint64) error {
|
||||
return t.decodeAutoIncJson(backend, reader, func(message proto.Message, maxSeq uint64) error {
|
||||
messageRef := message.ProtoReflect()
|
||||
id := messageRef.Get(t.autoIncField).Uint()
|
||||
if id == 0 {
|
||||
// we don't have an ID in the JSON, so we call Save to insert and
|
||||
pkey := messageRef.Get(t.autoIncField).Uint()
|
||||
if pkey == 0 {
|
||||
// we don't have a primary key in the JSON, so we call Save to insert and
|
||||
// generate one
|
||||
_, err = t.save(ctx, backend, message, saveModeInsert)
|
||||
return err
|
||||
} else {
|
||||
if id > maxID {
|
||||
return fmt.Errorf("invalid ID %d, expected a value <= %d, the highest sequence number", id, maxID)
|
||||
if pkey > maxSeq {
|
||||
return fmt.Errorf("invalid auto increment primary key %d, expected a value <= %d, the highest "+
|
||||
"sequence number", pkey, maxSeq)
|
||||
}
|
||||
// we do have an ID and calling Save will fail because it expects
|
||||
// either no ID or SAVE_MODE_UPDATE. So instead we drop one level
|
||||
// we do have a primary key and calling Save will fail because it expects
|
||||
// either no primary key or SAVE_MODE_UPDATE. So instead we drop one level
|
||||
// down and insert using tableImpl which doesn't know about
|
||||
// auto-incrementing IDs
|
||||
// auto-incrementing primary keys.
|
||||
return t.tableImpl.save(ctx, backend, message, saveModeInsert)
|
||||
}
|
||||
})
|
||||
|
||||
@ -54,7 +54,7 @@ func runAutoIncrementScenario(t *testing.T, table ormtable.AutoIncrementTable, c
|
||||
assert.Equal(t, uint64(1), ex1.Id)
|
||||
|
||||
ex2 := &testpb.ExampleAutoIncrementTable{X: "bar", Y: 10}
|
||||
newId, err := table.InsertReturningID(ctx, ex2)
|
||||
newId, err := table.InsertReturningPKey(ctx, ex2)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, uint64(2), ex2.Id)
|
||||
assert.Equal(t, newId, ex2.Id)
|
||||
@ -89,9 +89,9 @@ func TestBadJSON(t *testing.T) {
|
||||
store := ormtable.WrapContextDefault(testkv.NewSplitMemBackend())
|
||||
f, err := os.Open("testdata/bad_auto_inc.json")
|
||||
assert.NilError(t, err)
|
||||
assert.ErrorContains(t, table.ImportJSON(store, f), "invalid ID")
|
||||
assert.ErrorContains(t, table.ImportJSON(store, f), "invalid auto increment primary key")
|
||||
|
||||
f, err = os.Open("testdata/bad_auto_inc2.json")
|
||||
assert.NilError(t, err)
|
||||
assert.ErrorContains(t, table.ImportJSON(store, f), "invalid ID")
|
||||
assert.ErrorContains(t, table.ImportJSON(store, f), "invalid auto increment primary key")
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@ type Schema interface {
|
||||
type AutoIncrementTable interface {
|
||||
Table
|
||||
|
||||
// InsertReturningID inserts the provided entry in the store and returns the newly
|
||||
// generated ID for the message or an error.
|
||||
InsertReturningID(ctx context.Context, message proto.Message) (newId uint64, err error)
|
||||
// InsertReturningPKey inserts the provided entry in the store and returns the newly
|
||||
// generated primary key for the message or an error.
|
||||
InsertReturningPKey(ctx context.Context, message proto.Message) (newPK uint64, err error)
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ import (
|
||||
|
||||
sdkerrors "cosmossdk.io/errors"
|
||||
queryv1beta1 "github.com/cosmos/cosmos-sdk/api/cosmos/base/query/v1beta1"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/orm/encoding/ormkv"
|
||||
"github.com/cosmos/cosmos-sdk/orm/internal/testkv"
|
||||
"github.com/cosmos/cosmos-sdk/orm/internal/testpb"
|
||||
@ -790,3 +791,18 @@ func TestReadonly(t *testing.T) {
|
||||
ctx := ormtable.WrapContextDefault(readBackend)
|
||||
assert.ErrorIs(t, ormerrors.ReadOnly, table.Insert(ctx, &testpb.ExampleTable{}))
|
||||
}
|
||||
|
||||
func TestInsertReturningFieldName(t *testing.T) {
|
||||
table, err := ormtable.Build(ormtable.Options{
|
||||
MessageType: (&testpb.ExampleAutoIncFieldName{}).ProtoReflect().Type(),
|
||||
})
|
||||
backend := testkv.NewSplitMemBackend()
|
||||
ctx := ormtable.WrapContextDefault(backend)
|
||||
store, err := testpb.NewExampleAutoIncFieldNameTable(table)
|
||||
assert.NilError(t, err)
|
||||
foo, err := store.InsertReturningFoo(ctx, &testpb.ExampleAutoIncFieldName{
|
||||
Bar: 45,
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, uint64(1), foo)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user