Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Zachary Becker <zrbecker@gmail.com>
This commit is contained in:
parent
d9bc4bb317
commit
edafb06a9b
@ -1,7 +0,0 @@
|
||||
codegen:
|
||||
go install ./cmd/protoc-gen-go-cosmos-orm
|
||||
go install ./cmd/protoc-gen-go-cosmos-orm-proto
|
||||
# generate .proto files first
|
||||
(cd internal; buf generate --template buf.proto.gen.yaml)
|
||||
# generate go code
|
||||
(cd internal; buf generate)
|
||||
@ -1,11 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"google.golang.org/protobuf/compiler/protogen"
|
||||
|
||||
"cosmossdk.io/orm/internal/codegen"
|
||||
)
|
||||
|
||||
func main() {
|
||||
protogen.Options{}.Run(codegen.QueryProtoPluginRunner)
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"google.golang.org/protobuf/compiler/protogen"
|
||||
|
||||
"cosmossdk.io/orm/internal/codegen"
|
||||
)
|
||||
|
||||
func main() {
|
||||
protogen.Options{}.Run(codegen.ORMPluginRunner)
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
// Package encoding defines the core types and algorithms for encoding and decoding
|
||||
// protobuf objects and values to/from ORM key-value pairs.
|
||||
package encoding
|
||||
@ -1,121 +0,0 @@
|
||||
package ormfield
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"io"
|
||||
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
)
|
||||
|
||||
// BytesCodec encodes bytes as raw bytes. It errors if the byte array is longer
|
||||
// than 255 bytes.
|
||||
type BytesCodec struct{}
|
||||
|
||||
func (b BytesCodec) FixedBufferSize() int {
|
||||
return -1
|
||||
}
|
||||
|
||||
// ComputeBufferSize returns the bytes size of the value.
|
||||
func (b BytesCodec) ComputeBufferSize(value protoreflect.Value) (int, error) {
|
||||
return bytesSize(value), nil
|
||||
}
|
||||
|
||||
func bytesSize(value protoreflect.Value) int {
|
||||
if !value.IsValid() {
|
||||
return 0
|
||||
}
|
||||
return len(value.Bytes())
|
||||
}
|
||||
|
||||
func (b BytesCodec) IsOrdered() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (b BytesCodec) Decode(r Reader) (protoreflect.Value, error) {
|
||||
bz, err := io.ReadAll(r)
|
||||
return protoreflect.ValueOfBytes(bz), err
|
||||
}
|
||||
|
||||
func (b BytesCodec) Encode(value protoreflect.Value, w io.Writer) error {
|
||||
if !value.IsValid() {
|
||||
return nil
|
||||
}
|
||||
_, err := w.Write(value.Bytes())
|
||||
return err
|
||||
}
|
||||
|
||||
func (b BytesCodec) Compare(v1, v2 protoreflect.Value) int {
|
||||
return compareBytes(v1, v2)
|
||||
}
|
||||
|
||||
// NonTerminalBytesCodec encodes bytes as raw bytes length prefixed by a single
|
||||
// byte. It errors if the byte array is longer than 255 bytes.
|
||||
type NonTerminalBytesCodec struct{}
|
||||
|
||||
func (b NonTerminalBytesCodec) FixedBufferSize() int {
|
||||
return -1
|
||||
}
|
||||
|
||||
// ComputeBufferSize returns the bytes size of the value plus the length of the
|
||||
// varint length-prefix.
|
||||
func (b NonTerminalBytesCodec) ComputeBufferSize(value protoreflect.Value) (int, error) {
|
||||
n := bytesSize(value)
|
||||
prefixLen := 1
|
||||
// we use varint, if the first bit of a byte is 1 then we need to signal continuation
|
||||
for n >= 0x80 {
|
||||
prefixLen++
|
||||
n >>= 7
|
||||
}
|
||||
return n + prefixLen, nil
|
||||
}
|
||||
|
||||
func (b NonTerminalBytesCodec) IsOrdered() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (b NonTerminalBytesCodec) Compare(v1, v2 protoreflect.Value) int {
|
||||
return compareBytes(v1, v2)
|
||||
}
|
||||
|
||||
func (b NonTerminalBytesCodec) Decode(r Reader) (protoreflect.Value, error) {
|
||||
n, err := binary.ReadUvarint(r)
|
||||
if err != nil {
|
||||
return protoreflect.Value{}, err
|
||||
}
|
||||
|
||||
if n == 0 {
|
||||
return protoreflect.ValueOfBytes([]byte{}), nil
|
||||
}
|
||||
|
||||
bz := make([]byte, n)
|
||||
_, err = r.Read(bz)
|
||||
return protoreflect.ValueOfBytes(bz), err
|
||||
}
|
||||
|
||||
func (b NonTerminalBytesCodec) Encode(value protoreflect.Value, w io.Writer) error {
|
||||
var bz []byte
|
||||
if value.IsValid() {
|
||||
bz = value.Bytes()
|
||||
}
|
||||
n := len(bz)
|
||||
var prefix [binary.MaxVarintLen64]byte
|
||||
prefixLen := binary.PutUvarint(prefix[:], uint64(n))
|
||||
_, err := w.Write(prefix[:prefixLen])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = w.Write(bz)
|
||||
return err
|
||||
}
|
||||
|
||||
func compareBytes(v1, v2 protoreflect.Value) int {
|
||||
var bz1, bz2 []byte
|
||||
if v1.IsValid() {
|
||||
bz1 = v1.Bytes()
|
||||
}
|
||||
if v2.IsValid() {
|
||||
bz2 = v2.Bytes()
|
||||
}
|
||||
return bytes.Compare(bz1, bz2)
|
||||
}
|
||||
@ -1,113 +0,0 @@
|
||||
package ormfield
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/types/known/durationpb"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
"cosmossdk.io/orm/types/ormerrors"
|
||||
)
|
||||
|
||||
// Codec defines an interface for decoding and encoding values in ORM index keys.
|
||||
type Codec interface {
|
||||
// Decode decodes a value in a key.
|
||||
Decode(r Reader) (protoreflect.Value, error)
|
||||
|
||||
// Encode encodes a value in a key.
|
||||
Encode(value protoreflect.Value, w io.Writer) error
|
||||
|
||||
// Compare compares two values of this type and should primarily be used
|
||||
// for testing.
|
||||
Compare(v1, v2 protoreflect.Value) int
|
||||
|
||||
// IsOrdered returns true if callers can always assume that this ordering
|
||||
// is suitable for sorted iteration.
|
||||
IsOrdered() bool
|
||||
|
||||
// FixedBufferSize returns a positive value if encoders should assume a
|
||||
// fixed size buffer for encoding. Encoders will use at most this much size
|
||||
// to encode the value.
|
||||
FixedBufferSize() int
|
||||
|
||||
// ComputeBufferSize estimates the buffer size needed to encode the field.
|
||||
// Encoders will use at most this much size to encode the value.
|
||||
ComputeBufferSize(value protoreflect.Value) (int, error)
|
||||
}
|
||||
|
||||
type Reader interface {
|
||||
io.Reader
|
||||
io.ByteReader
|
||||
}
|
||||
|
||||
var (
|
||||
timestampMsgType = (×tamppb.Timestamp{}).ProtoReflect().Type()
|
||||
timestampFullName = timestampMsgType.Descriptor().FullName()
|
||||
durationMsgType = (&durationpb.Duration{}).ProtoReflect().Type()
|
||||
durationFullName = durationMsgType.Descriptor().FullName()
|
||||
)
|
||||
|
||||
// GetCodec returns the Codec for the provided field if one is defined.
|
||||
// nonTerminal should be set to true if this value is being encoded as a
|
||||
// non-terminal segment of a multi-part key.
|
||||
func GetCodec(field protoreflect.FieldDescriptor, nonTerminal bool) (Codec, error) {
|
||||
if field == nil {
|
||||
return nil, ormerrors.InvalidKeyField.Wrap("nil field")
|
||||
}
|
||||
if field.IsList() {
|
||||
return nil, ormerrors.InvalidKeyField.Wrapf("repeated field %s", field.FullName())
|
||||
}
|
||||
|
||||
if field.ContainingOneof() != nil {
|
||||
return nil, ormerrors.InvalidKeyField.Wrapf("oneof field %s", field.FullName())
|
||||
}
|
||||
|
||||
if field.HasOptionalKeyword() {
|
||||
return nil, ormerrors.InvalidKeyField.Wrapf("optional field %s", field.FullName())
|
||||
}
|
||||
|
||||
switch field.Kind() {
|
||||
case protoreflect.BytesKind:
|
||||
if nonTerminal {
|
||||
return NonTerminalBytesCodec{}, nil
|
||||
}
|
||||
|
||||
return BytesCodec{}, nil
|
||||
case protoreflect.StringKind:
|
||||
if nonTerminal {
|
||||
return NonTerminalStringCodec{}, nil
|
||||
}
|
||||
|
||||
return StringCodec{}, nil
|
||||
|
||||
case protoreflect.Uint32Kind:
|
||||
return CompactUint32Codec{}, nil
|
||||
case protoreflect.Fixed32Kind:
|
||||
return FixedUint32Codec{}, nil
|
||||
case protoreflect.Uint64Kind:
|
||||
return CompactUint64Codec{}, nil
|
||||
case protoreflect.Fixed64Kind:
|
||||
return FixedUint64Codec{}, nil
|
||||
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
|
||||
return Int32Codec{}, nil
|
||||
case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
|
||||
return Int64Codec{}, nil
|
||||
case protoreflect.BoolKind:
|
||||
return BoolCodec{}, nil
|
||||
case protoreflect.EnumKind:
|
||||
return EnumCodec{}, nil
|
||||
case protoreflect.MessageKind:
|
||||
msgName := field.Message().FullName()
|
||||
switch msgName {
|
||||
case timestampFullName:
|
||||
return TimestampCodec{}, nil
|
||||
case durationFullName:
|
||||
return DurationCodec{}, nil
|
||||
default:
|
||||
return nil, ormerrors.InvalidKeyField.Wrapf("%s of type %s", field.FullName(), msgName)
|
||||
}
|
||||
default:
|
||||
return nil, ormerrors.InvalidKeyField.Wrapf("%s of kind %s", field.FullName(), field.Kind())
|
||||
}
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
package ormkv
|
||||
|
||||
import "google.golang.org/protobuf/reflect/protoreflect"
|
||||
|
||||
// EntryCodec defines an interfaces for decoding and encoding entries in the
|
||||
// kv-store backing an ORM instance. EntryCodec's enable full logical decoding
|
||||
// of ORM data.
|
||||
type EntryCodec interface {
|
||||
// DecodeEntry decodes a kv-pair into an Entry.
|
||||
DecodeEntry(k, v []byte) (Entry, error)
|
||||
|
||||
// EncodeEntry encodes an entry into a kv-pair.
|
||||
EncodeEntry(entry Entry) (k, v []byte, err error)
|
||||
}
|
||||
|
||||
// IndexCodec defines an interfaces for encoding and decoding index-keys in the
|
||||
// kv-store.
|
||||
type IndexCodec interface {
|
||||
EntryCodec
|
||||
|
||||
// MessageType returns the message type this index codec applies to.
|
||||
MessageType() protoreflect.MessageType
|
||||
|
||||
// GetFieldNames returns the field names in the key of this index.
|
||||
GetFieldNames() []protoreflect.Name
|
||||
|
||||
// DecodeIndexKey decodes a kv-pair into index-fields and primary-key field
|
||||
// values. These fields may or may not overlap depending on the index.
|
||||
DecodeIndexKey(k, v []byte) (indexFields, primaryKey []protoreflect.Value, err error)
|
||||
|
||||
// EncodeKVFromMessage encodes a kv-pair for the index from a message.
|
||||
EncodeKVFromMessage(message protoreflect.Message) (k, v []byte, err error)
|
||||
|
||||
// CompareKeys compares the provided values which must correspond to the
|
||||
// fields in this key. Prefix keys of different lengths are supported but the
|
||||
// function will panic if either array is too long. A negative value is returned
|
||||
// if values1 is less than values2, 0 is returned if the two arrays are equal,
|
||||
// and a positive value is returned if values2 is greater.
|
||||
CompareKeys(key1, key2 []protoreflect.Value) int
|
||||
|
||||
// EncodeKeyFromMessage encodes the key part of this index and returns both
|
||||
// index values and encoded key.
|
||||
EncodeKeyFromMessage(message protoreflect.Message) (keyValues []protoreflect.Value, key []byte, err error)
|
||||
|
||||
// IsFullyOrdered returns true if all fields in the key are also ordered.
|
||||
IsFullyOrdered() bool
|
||||
}
|
||||
@ -1,135 +0,0 @@
|
||||
package ormkv
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
|
||||
"cosmossdk.io/orm/internal/stablejson"
|
||||
)
|
||||
|
||||
// Entry defines a logical representation of a kv-store entry for ORM instances.
|
||||
type Entry interface {
|
||||
fmt.Stringer
|
||||
|
||||
// GetTableName returns the table-name (equivalent to the fully-qualified
|
||||
// proto message name) this entry corresponds to.
|
||||
GetTableName() protoreflect.FullName
|
||||
|
||||
// to allow new methods to be added without breakage, this interface
|
||||
// shouldn't be implemented outside this package,
|
||||
// see https://go.dev/blog/module-compatibility
|
||||
doNotImplement()
|
||||
}
|
||||
|
||||
// PrimaryKeyEntry represents a logically decoded primary-key entry.
|
||||
type PrimaryKeyEntry struct {
|
||||
// TableName is the table this entry represents.
|
||||
TableName protoreflect.FullName
|
||||
|
||||
// Key represents the primary key values.
|
||||
Key []protoreflect.Value
|
||||
|
||||
// Value represents the message stored under the primary key.
|
||||
Value proto.Message
|
||||
}
|
||||
|
||||
func (p *PrimaryKeyEntry) GetTableName() protoreflect.FullName {
|
||||
return p.TableName
|
||||
}
|
||||
|
||||
func (p *PrimaryKeyEntry) String() string {
|
||||
if p.Value == nil {
|
||||
return fmt.Sprintf("PK %s %s -> _", p.TableName, fmtValues(p.Key))
|
||||
}
|
||||
|
||||
valBz, err := stablejson.Marshal(p.Value)
|
||||
valStr := string(valBz)
|
||||
if err != nil {
|
||||
valStr = fmt.Sprintf("ERR %v", err)
|
||||
}
|
||||
return fmt.Sprintf("PK %s %s -> %s", p.TableName, fmtValues(p.Key), valStr)
|
||||
}
|
||||
|
||||
func fmtValues(values []protoreflect.Value) string {
|
||||
if len(values) == 0 {
|
||||
return "_"
|
||||
}
|
||||
|
||||
parts := make([]string, len(values))
|
||||
for i, v := range values {
|
||||
parts[i] = fmt.Sprintf("%v", v.Interface())
|
||||
}
|
||||
|
||||
return strings.Join(parts, "/")
|
||||
}
|
||||
|
||||
func (p *PrimaryKeyEntry) doNotImplement() {}
|
||||
|
||||
// IndexKeyEntry represents a logically decoded index entry.
|
||||
type IndexKeyEntry struct {
|
||||
// TableName is the table this entry represents.
|
||||
TableName protoreflect.FullName
|
||||
|
||||
// Fields are the index fields this entry represents.
|
||||
Fields []protoreflect.Name
|
||||
|
||||
// IsUnique indicates whether this index is unique or not.
|
||||
IsUnique bool
|
||||
|
||||
// IndexValues represent the index values.
|
||||
IndexValues []protoreflect.Value
|
||||
|
||||
// PrimaryKey represents the primary key values, it is empty if this is a
|
||||
// prefix key
|
||||
PrimaryKey []protoreflect.Value
|
||||
}
|
||||
|
||||
func (i *IndexKeyEntry) GetTableName() protoreflect.FullName {
|
||||
return i.TableName
|
||||
}
|
||||
|
||||
func (i *IndexKeyEntry) doNotImplement() {}
|
||||
|
||||
func (i *IndexKeyEntry) string() string {
|
||||
return fmt.Sprintf("%s %s : %s -> %s", i.TableName, fmtFields(i.Fields), fmtValues(i.IndexValues), fmtValues(i.PrimaryKey))
|
||||
}
|
||||
|
||||
func fmtFields(fields []protoreflect.Name) string {
|
||||
strs := make([]string, len(fields))
|
||||
for i, field := range fields {
|
||||
strs[i] = string(field)
|
||||
}
|
||||
return strings.Join(strs, "/")
|
||||
}
|
||||
|
||||
func (i *IndexKeyEntry) String() string {
|
||||
if i.IsUnique {
|
||||
return fmt.Sprintf("UNIQ %s", i.string())
|
||||
}
|
||||
|
||||
return fmt.Sprintf("IDX %s", i.string())
|
||||
}
|
||||
|
||||
// SeqEntry represents a sequence for tables with auto-incrementing primary keys.
|
||||
type SeqEntry struct {
|
||||
// TableName is the table this entry represents.
|
||||
TableName protoreflect.FullName
|
||||
|
||||
// Value is the uint64 value stored for this sequence.
|
||||
Value uint64
|
||||
}
|
||||
|
||||
func (s *SeqEntry) GetTableName() protoreflect.FullName {
|
||||
return s.TableName
|
||||
}
|
||||
|
||||
func (s *SeqEntry) doNotImplement() {}
|
||||
|
||||
func (s *SeqEntry) String() string {
|
||||
return fmt.Sprintf("SEQ %s %d", s.TableName, s.Value)
|
||||
}
|
||||
|
||||
var _, _, _ Entry = &PrimaryKeyEntry{}, &IndexKeyEntry{}, &SeqEntry{}
|
||||
@ -1,75 +0,0 @@
|
||||
package ormkv_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
"cosmossdk.io/orm/encoding/encodeutil"
|
||||
"cosmossdk.io/orm/encoding/ormkv"
|
||||
"cosmossdk.io/orm/internal/testpb"
|
||||
)
|
||||
|
||||
var aFullName = (&testpb.ExampleTable{}).ProtoReflect().Descriptor().FullName()
|
||||
|
||||
func TestPrimaryKeyEntry(t *testing.T) {
|
||||
entry := &ormkv.PrimaryKeyEntry{
|
||||
TableName: aFullName,
|
||||
Key: encodeutil.ValuesOf(uint32(1), "abc"),
|
||||
Value: &testpb.ExampleTable{I32: -1},
|
||||
}
|
||||
assert.Equal(t, `PK testpb.ExampleTable 1/abc -> {"i32":-1}`, entry.String())
|
||||
assert.Equal(t, aFullName, entry.GetTableName())
|
||||
|
||||
// prefix key
|
||||
entry = &ormkv.PrimaryKeyEntry{
|
||||
TableName: aFullName,
|
||||
Key: encodeutil.ValuesOf(uint32(1), "abc"),
|
||||
Value: nil,
|
||||
}
|
||||
assert.Equal(t, `PK testpb.ExampleTable 1/abc -> _`, entry.String())
|
||||
assert.Equal(t, aFullName, entry.GetTableName())
|
||||
}
|
||||
|
||||
func TestIndexKeyEntry(t *testing.T) {
|
||||
entry := &ormkv.IndexKeyEntry{
|
||||
TableName: aFullName,
|
||||
Fields: []protoreflect.Name{"u32", "i32", "str"},
|
||||
IsUnique: false,
|
||||
IndexValues: encodeutil.ValuesOf(uint32(10), int32(-1), "abc"),
|
||||
PrimaryKey: encodeutil.ValuesOf("abc", int32(-1)),
|
||||
}
|
||||
assert.Equal(t, `IDX testpb.ExampleTable u32/i32/str : 10/-1/abc -> abc/-1`, entry.String())
|
||||
assert.Equal(t, aFullName, entry.GetTableName())
|
||||
|
||||
entry = &ormkv.IndexKeyEntry{
|
||||
TableName: aFullName,
|
||||
Fields: []protoreflect.Name{"u32"},
|
||||
IsUnique: true,
|
||||
IndexValues: encodeutil.ValuesOf(uint32(10)),
|
||||
PrimaryKey: encodeutil.ValuesOf("abc", int32(-1)),
|
||||
}
|
||||
assert.Equal(t, `UNIQ testpb.ExampleTable u32 : 10 -> abc/-1`, entry.String())
|
||||
assert.Equal(t, aFullName, entry.GetTableName())
|
||||
|
||||
// prefix key
|
||||
entry = &ormkv.IndexKeyEntry{
|
||||
TableName: aFullName,
|
||||
Fields: []protoreflect.Name{"u32", "i32", "str"},
|
||||
IsUnique: false,
|
||||
IndexValues: encodeutil.ValuesOf(uint32(10), int32(-1)),
|
||||
}
|
||||
assert.Equal(t, `IDX testpb.ExampleTable u32/i32/str : 10/-1 -> _`, entry.String())
|
||||
assert.Equal(t, aFullName, entry.GetTableName())
|
||||
|
||||
// prefix key
|
||||
entry = &ormkv.IndexKeyEntry{
|
||||
TableName: aFullName,
|
||||
Fields: []protoreflect.Name{"str", "i32"},
|
||||
IsUnique: true,
|
||||
IndexValues: encodeutil.ValuesOf("abc", int32(1)),
|
||||
}
|
||||
assert.Equal(t, `UNIQ testpb.ExampleTable str/i32 : abc/1 -> _`, entry.String())
|
||||
assert.Equal(t, aFullName, entry.GetTableName())
|
||||
}
|
||||
@ -1,63 +0,0 @@
|
||||
package ormkv_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"gotest.tools/v3/assert"
|
||||
"pgregory.net/rapid"
|
||||
|
||||
"cosmossdk.io/orm/encoding/ormkv"
|
||||
"cosmossdk.io/orm/internal/testpb"
|
||||
"cosmossdk.io/orm/internal/testutil"
|
||||
)
|
||||
|
||||
func TestIndexKeyCodec(t *testing.T) {
|
||||
rapid.Check(t, func(t *rapid.T) {
|
||||
idxPartCdc := testutil.TestKeyCodecGen(1, 5).Draw(t, "idxPartCdc")
|
||||
pkCodec := testutil.TestKeyCodecGen(1, 5).Draw(t, "pkCdc")
|
||||
prefix := rapid.SliceOfN(rapid.Byte(), 0, 5).Draw(t, "prefix")
|
||||
messageType := (&testpb.ExampleTable{}).ProtoReflect().Type()
|
||||
indexKeyCdc, err := ormkv.NewIndexKeyCodec(
|
||||
prefix,
|
||||
messageType,
|
||||
idxPartCdc.Codec.GetFieldNames(),
|
||||
pkCodec.Codec.GetFieldNames(),
|
||||
)
|
||||
assert.NilError(t, err)
|
||||
for i := 0; i < 100; i++ {
|
||||
a := testutil.GenA.Draw(t, fmt.Sprintf("a%d", i))
|
||||
key := indexKeyCdc.GetKeyValues(a.ProtoReflect())
|
||||
pk := pkCodec.Codec.GetKeyValues(a.ProtoReflect())
|
||||
idx1 := &ormkv.IndexKeyEntry{
|
||||
TableName: messageType.Descriptor().FullName(),
|
||||
Fields: indexKeyCdc.GetFieldNames(),
|
||||
IsUnique: false,
|
||||
IndexValues: key,
|
||||
PrimaryKey: pk,
|
||||
}
|
||||
k, v, err := indexKeyCdc.EncodeEntry(idx1)
|
||||
assert.NilError(t, err)
|
||||
|
||||
k2, v2, err := indexKeyCdc.EncodeKVFromMessage(a.ProtoReflect())
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, bytes.Equal(k, k2))
|
||||
assert.Assert(t, bytes.Equal(v, v2))
|
||||
|
||||
entry2, err := indexKeyCdc.DecodeEntry(k, v)
|
||||
assert.NilError(t, err)
|
||||
idx2 := entry2.(*ormkv.IndexKeyEntry)
|
||||
assert.Equal(t, 0, indexKeyCdc.CompareKeys(idx1.IndexValues, idx2.IndexValues))
|
||||
assert.Equal(t, 0, pkCodec.Codec.CompareKeys(idx1.PrimaryKey, idx2.PrimaryKey))
|
||||
assert.Equal(t, false, idx2.IsUnique)
|
||||
assert.Equal(t, messageType.Descriptor().FullName(), idx2.TableName)
|
||||
assert.DeepEqual(t, idx1.Fields, idx2.Fields)
|
||||
|
||||
idxFields, pk2, err := indexKeyCdc.DecodeIndexKey(k, v)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, 0, indexKeyCdc.CompareKeys(key, idxFields))
|
||||
assert.Equal(t, 0, pkCodec.Codec.CompareKeys(pk, pk2))
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -1,317 +0,0 @@
|
||||
package ormkv_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"gotest.tools/v3/assert"
|
||||
"pgregory.net/rapid"
|
||||
|
||||
"cosmossdk.io/orm/encoding/encodeutil"
|
||||
"cosmossdk.io/orm/encoding/ormkv"
|
||||
"cosmossdk.io/orm/internal/testpb"
|
||||
"cosmossdk.io/orm/internal/testutil"
|
||||
)
|
||||
|
||||
func TestKeyCodec(t *testing.T) {
|
||||
rapid.Check(t, func(t *rapid.T) {
|
||||
key := testutil.TestKeyCodecGen(0, 5).Draw(t, "key")
|
||||
for i := 0; i < 100; i++ {
|
||||
keyValues := key.Draw(t, "values")
|
||||
|
||||
bz1 := assertEncDecKey(t, key, keyValues)
|
||||
|
||||
if key.Codec.IsFullyOrdered() {
|
||||
// check if ordered keys have ordered encodings
|
||||
keyValues2 := key.Draw(t, "values2")
|
||||
bz2 := assertEncDecKey(t, key, keyValues2)
|
||||
// bytes comparison should equal comparison of values
|
||||
assert.Equal(t, key.Codec.CompareKeys(keyValues, keyValues2), bytes.Compare(bz1, bz2))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func assertEncDecKey(t *rapid.T, key testutil.TestKeyCodec, keyValues []protoreflect.Value) []byte {
|
||||
bz, err := key.Codec.EncodeKey(keyValues)
|
||||
assert.NilError(t, err)
|
||||
keyValues2, err := key.Codec.DecodeKey(bytes.NewReader(bz))
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, 0, key.Codec.CompareKeys(keyValues, keyValues2))
|
||||
return bz
|
||||
}
|
||||
|
||||
func TestCompareValues(t *testing.T) {
|
||||
cdc, err := ormkv.NewKeyCodec(nil,
|
||||
(&testpb.ExampleTable{}).ProtoReflect().Type(),
|
||||
[]protoreflect.Name{"u32", "str", "i32"})
|
||||
assert.NilError(t, err)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
values1 []protoreflect.Value
|
||||
values2 []protoreflect.Value
|
||||
expect int
|
||||
validRange bool
|
||||
}{
|
||||
{
|
||||
"eq",
|
||||
encodeutil.ValuesOf(uint32(0), "abc", int32(-3)),
|
||||
encodeutil.ValuesOf(uint32(0), "abc", int32(-3)),
|
||||
0,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"eq prefix 0",
|
||||
encodeutil.ValuesOf(),
|
||||
encodeutil.ValuesOf(),
|
||||
0,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"eq prefix 1",
|
||||
encodeutil.ValuesOf(uint32(0)),
|
||||
encodeutil.ValuesOf(uint32(0)),
|
||||
0,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"eq prefix 2",
|
||||
encodeutil.ValuesOf(uint32(0), "abc"),
|
||||
encodeutil.ValuesOf(uint32(0), "abc"),
|
||||
0,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"lt1",
|
||||
encodeutil.ValuesOf(uint32(0), "abc", int32(-3)),
|
||||
encodeutil.ValuesOf(uint32(1), "abc", int32(-3)),
|
||||
-1,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"lt2",
|
||||
encodeutil.ValuesOf(uint32(1), "abb", int32(-3)),
|
||||
encodeutil.ValuesOf(uint32(1), "abc", int32(-3)),
|
||||
-1,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"lt3",
|
||||
encodeutil.ValuesOf(uint32(1), "abb", int32(-4)),
|
||||
encodeutil.ValuesOf(uint32(1), "abb", int32(-3)),
|
||||
-1,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"less prefix 0",
|
||||
encodeutil.ValuesOf(),
|
||||
encodeutil.ValuesOf(uint32(1), "abb", int32(-4)),
|
||||
-1,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"less prefix 1",
|
||||
encodeutil.ValuesOf(uint32(1)),
|
||||
encodeutil.ValuesOf(uint32(1), "abb", int32(-4)),
|
||||
-1,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"less prefix 2",
|
||||
encodeutil.ValuesOf(uint32(1), "abb"),
|
||||
encodeutil.ValuesOf(uint32(1), "abb", int32(-4)),
|
||||
-1,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"gt1",
|
||||
encodeutil.ValuesOf(uint32(2), "abb", int32(-4)),
|
||||
encodeutil.ValuesOf(uint32(1), "abb", int32(-4)),
|
||||
1,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"gt2",
|
||||
encodeutil.ValuesOf(uint32(2), "abc", int32(-4)),
|
||||
encodeutil.ValuesOf(uint32(2), "abb", int32(-4)),
|
||||
1,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"gt3",
|
||||
encodeutil.ValuesOf(uint32(2), "abc", int32(1)),
|
||||
encodeutil.ValuesOf(uint32(2), "abc", int32(-3)),
|
||||
1,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"gt prefix 0",
|
||||
encodeutil.ValuesOf(uint32(2), "abc", int32(-3)),
|
||||
encodeutil.ValuesOf(),
|
||||
1,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"gt prefix 1",
|
||||
encodeutil.ValuesOf(uint32(2), "abc", int32(-3)),
|
||||
encodeutil.ValuesOf(uint32(2)),
|
||||
1,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"gt prefix 2",
|
||||
encodeutil.ValuesOf(uint32(2), "abc", int32(-3)),
|
||||
encodeutil.ValuesOf(uint32(2), "abc"),
|
||||
1,
|
||||
true,
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
assert.Equal(
|
||||
t, test.expect,
|
||||
cdc.CompareKeys(test.values1, test.values2),
|
||||
)
|
||||
// CheckValidRangeIterationKeys should give comparable results
|
||||
err := cdc.CheckValidRangeIterationKeys(test.values1, test.values2)
|
||||
if test.validRange {
|
||||
assert.NilError(t, err)
|
||||
} else {
|
||||
assert.ErrorContains(t, err, "")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodePrefixKey(t *testing.T) {
|
||||
cdc, err := ormkv.NewKeyCodec(nil,
|
||||
(&testpb.ExampleTable{}).ProtoReflect().Type(),
|
||||
[]protoreflect.Name{"u32", "str", "bz", "i32"})
|
||||
|
||||
assert.NilError(t, err)
|
||||
tests := []struct {
|
||||
name string
|
||||
values []protoreflect.Value
|
||||
}{
|
||||
{
|
||||
"1",
|
||||
encodeutil.ValuesOf(uint32(5), "abc"),
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
bz, err := cdc.EncodeKey(test.values)
|
||||
assert.NilError(t, err)
|
||||
values, err := cdc.DecodeKey(bytes.NewReader(bz))
|
||||
assert.ErrorIs(t, err, io.EOF)
|
||||
assert.Equal(t, 0, cdc.CompareKeys(test.values, values))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidRangeIterationKeys(t *testing.T) {
|
||||
cdc, err := ormkv.NewKeyCodec(nil,
|
||||
(&testpb.ExampleTable{}).ProtoReflect().Type(),
|
||||
[]protoreflect.Name{"u32", "str", "bz", "i32"})
|
||||
assert.NilError(t, err)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
values1 []protoreflect.Value
|
||||
values2 []protoreflect.Value
|
||||
expectErr bool
|
||||
}{
|
||||
{
|
||||
"1 eq",
|
||||
encodeutil.ValuesOf(uint32(0)),
|
||||
encodeutil.ValuesOf(uint32(0)),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"1 lt",
|
||||
encodeutil.ValuesOf(uint32(0)),
|
||||
encodeutil.ValuesOf(uint32(1)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"1 gt",
|
||||
encodeutil.ValuesOf(uint32(1)),
|
||||
encodeutil.ValuesOf(uint32(0)),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"1,2 lt",
|
||||
encodeutil.ValuesOf(uint32(0)),
|
||||
encodeutil.ValuesOf(uint32(0), "abc"),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"1,2 gt",
|
||||
encodeutil.ValuesOf(uint32(0), "abc"),
|
||||
encodeutil.ValuesOf(uint32(0)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"1,2,3",
|
||||
encodeutil.ValuesOf(uint32(0)),
|
||||
encodeutil.ValuesOf(uint32(0), "abc", []byte{1, 2}),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"1,2,3,4 lt",
|
||||
encodeutil.ValuesOf(uint32(0), "abc", []byte{1, 2}, int32(-1)),
|
||||
encodeutil.ValuesOf(uint32(0), "abc", []byte{1, 2}, int32(1)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"too long",
|
||||
encodeutil.ValuesOf(uint32(0), "abc", []byte{1, 2}, int32(-1)),
|
||||
encodeutil.ValuesOf(uint32(0), "abc", []byte{1, 2}, int32(1), int32(1)),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"1,2,3,4 eq",
|
||||
encodeutil.ValuesOf(uint32(0), "abc", []byte{1, 2}, int32(1)),
|
||||
encodeutil.ValuesOf(uint32(0), "abc", []byte{1, 2}, int32(1)),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"1,2,3,4 bz err",
|
||||
encodeutil.ValuesOf(uint32(0), "abc", []byte{1, 2}, int32(-1)),
|
||||
encodeutil.ValuesOf(uint32(0), "abc", []byte{1, 2, 3}, int32(1)),
|
||||
true,
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
err := cdc.CheckValidRangeIterationKeys(test.values1, test.values2)
|
||||
if test.expectErr {
|
||||
assert.ErrorContains(t, err, "")
|
||||
} else {
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetSet(t *testing.T) {
|
||||
cdc, err := ormkv.NewKeyCodec(nil,
|
||||
(&testpb.ExampleTable{}).ProtoReflect().Type(),
|
||||
[]protoreflect.Name{"u32", "str", "i32"})
|
||||
assert.NilError(t, err)
|
||||
|
||||
var a testpb.ExampleTable
|
||||
values := encodeutil.ValuesOf(uint32(4), "abc", int32(1))
|
||||
cdc.SetKeyValues(a.ProtoReflect(), values)
|
||||
values2 := cdc.GetKeyValues(a.ProtoReflect())
|
||||
assert.Equal(t, 0, cdc.CompareKeys(values, values2))
|
||||
bz, err := cdc.EncodeKey(values)
|
||||
assert.NilError(t, err)
|
||||
values3, bz2, err := cdc.EncodeKeyFromMessage(a.ProtoReflect())
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, 0, cdc.CompareKeys(values, values3))
|
||||
assert.Assert(t, bytes.Equal(bz, bz2))
|
||||
}
|
||||
@ -1,60 +0,0 @@
|
||||
package ormkv_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/testing/protocmp"
|
||||
"gotest.tools/v3/assert"
|
||||
"pgregory.net/rapid"
|
||||
|
||||
"cosmossdk.io/orm/encoding/ormkv"
|
||||
"cosmossdk.io/orm/internal/testpb"
|
||||
"cosmossdk.io/orm/internal/testutil"
|
||||
)
|
||||
|
||||
func TestPrimaryKeyCodec(t *testing.T) {
|
||||
rapid.Check(t, func(t *rapid.T) {
|
||||
keyCodec := testutil.TestKeyCodecGen(0, 5).Draw(t, "keyCodec")
|
||||
pkCodec, err := ormkv.NewPrimaryKeyCodec(
|
||||
keyCodec.Codec.Prefix(),
|
||||
(&testpb.ExampleTable{}).ProtoReflect().Type(),
|
||||
keyCodec.Codec.GetFieldNames(),
|
||||
proto.UnmarshalOptions{},
|
||||
)
|
||||
assert.NilError(t, err)
|
||||
for i := 0; i < 100; i++ {
|
||||
a := testutil.GenA.Draw(t, fmt.Sprintf("a%d", i))
|
||||
key := keyCodec.Codec.GetKeyValues(a.ProtoReflect())
|
||||
pk1 := &ormkv.PrimaryKeyEntry{
|
||||
TableName: aFullName,
|
||||
Key: key,
|
||||
Value: a,
|
||||
}
|
||||
k, v, err := pkCodec.EncodeEntry(pk1)
|
||||
assert.NilError(t, err)
|
||||
|
||||
k2, v2, err := pkCodec.EncodeKVFromMessage(a.ProtoReflect())
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, bytes.Equal(k, k2))
|
||||
assert.Assert(t, bytes.Equal(v, v2))
|
||||
|
||||
entry2, err := pkCodec.DecodeEntry(k, v)
|
||||
assert.NilError(t, err)
|
||||
pk2 := entry2.(*ormkv.PrimaryKeyEntry)
|
||||
assert.Equal(t, 0, pkCodec.CompareKeys(pk1.Key, pk2.Key))
|
||||
assert.DeepEqual(t, pk1.Value, pk2.Value, protocmp.Transform())
|
||||
|
||||
idxFields, pk3, err := pkCodec.DecodeIndexKey(k, v)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, 0, pkCodec.CompareKeys(pk1.Key, pk3))
|
||||
assert.Equal(t, 0, pkCodec.CompareKeys(pk1.Key, idxFields))
|
||||
|
||||
pkCodec.ClearValues(a.ProtoReflect())
|
||||
pkCodec.SetKeyValues(a.ProtoReflect(), pk1.Key)
|
||||
assert.DeepEqual(t, a, pk2.Value, protocmp.Transform())
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -1,69 +0,0 @@
|
||||
package ormkv
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
|
||||
"cosmossdk.io/orm/types/ormerrors"
|
||||
)
|
||||
|
||||
// SeqCodec is the codec for auto-incrementing uint64 primary key sequences.
|
||||
type SeqCodec struct {
|
||||
messageType protoreflect.FullName
|
||||
prefix []byte
|
||||
}
|
||||
|
||||
// NewSeqCodec creates a new SeqCodec.
|
||||
func NewSeqCodec(messageType protoreflect.MessageType, prefix []byte) *SeqCodec {
|
||||
return &SeqCodec{messageType: messageType.Descriptor().FullName(), prefix: prefix}
|
||||
}
|
||||
|
||||
var _ EntryCodec = &SeqCodec{}
|
||||
|
||||
func (s SeqCodec) DecodeEntry(k, v []byte) (Entry, error) {
|
||||
if !bytes.Equal(k, s.prefix) {
|
||||
return nil, ormerrors.UnexpectedDecodePrefix
|
||||
}
|
||||
|
||||
x, err := s.DecodeValue(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &SeqEntry{
|
||||
TableName: s.messageType,
|
||||
Value: x,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s SeqCodec) EncodeEntry(entry Entry) (k, v []byte, err error) {
|
||||
seqEntry, ok := entry.(*SeqEntry)
|
||||
if !ok {
|
||||
return nil, nil, ormerrors.BadDecodeEntry
|
||||
}
|
||||
|
||||
if seqEntry.TableName != s.messageType {
|
||||
return nil, nil, ormerrors.BadDecodeEntry
|
||||
}
|
||||
|
||||
return s.prefix, s.EncodeValue(seqEntry.Value), nil
|
||||
}
|
||||
|
||||
func (s SeqCodec) Prefix() []byte {
|
||||
return s.prefix
|
||||
}
|
||||
|
||||
func (s SeqCodec) EncodeValue(seq uint64) (v []byte) {
|
||||
bz := make([]byte, binary.MaxVarintLen64)
|
||||
n := binary.PutUvarint(bz, seq)
|
||||
return bz[:n]
|
||||
}
|
||||
|
||||
func (s SeqCodec) DecodeValue(v []byte) (uint64, error) {
|
||||
if len(v) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
return binary.ReadUvarint(bytes.NewReader(v))
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
package ormkv_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"gotest.tools/v3/assert"
|
||||
"pgregory.net/rapid"
|
||||
|
||||
"cosmossdk.io/orm/encoding/ormkv"
|
||||
"cosmossdk.io/orm/internal/testpb"
|
||||
)
|
||||
|
||||
func TestSeqCodec(t *testing.T) {
|
||||
rapid.Check(t, func(t *rapid.T) {
|
||||
prefix := rapid.SliceOfN(rapid.Byte(), 0, 5).Draw(t, "prefix")
|
||||
typ := (&testpb.ExampleTable{}).ProtoReflect().Type()
|
||||
tableName := typ.Descriptor().FullName()
|
||||
cdc := ormkv.NewSeqCodec(typ, prefix)
|
||||
|
||||
seq, err := cdc.DecodeValue(nil)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, uint64(0), seq)
|
||||
|
||||
seq, err = cdc.DecodeValue([]byte{})
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, uint64(0), seq)
|
||||
|
||||
seq = rapid.Uint64().Draw(t, "seq")
|
||||
|
||||
v := cdc.EncodeValue(seq)
|
||||
seq2, err := cdc.DecodeValue(v)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, seq, seq2)
|
||||
|
||||
entry := &ormkv.SeqEntry{
|
||||
TableName: tableName,
|
||||
Value: seq,
|
||||
}
|
||||
k, v, err := cdc.EncodeEntry(entry)
|
||||
assert.NilError(t, err)
|
||||
entry2, err := cdc.DecodeEntry(k, v)
|
||||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t, entry, entry2)
|
||||
assert.Assert(t, bytes.Equal(cdc.Prefix(), k))
|
||||
})
|
||||
}
|
||||
@ -1,49 +0,0 @@
|
||||
Feature: inserting, updating and saving entities
|
||||
|
||||
Scenario: can't insert an entity with a duplicate primary key
|
||||
Given an existing entity
|
||||
"""
|
||||
{"name": "foo", "not_unique": "bar"}
|
||||
"""
|
||||
When I insert
|
||||
"""
|
||||
{"name": "foo", "not_unique": "baz"}
|
||||
"""
|
||||
Then expect a "already exists" error
|
||||
And expect grpc error code "ALREADY_EXISTS"
|
||||
|
||||
Scenario: can't update entity that doesn't exist
|
||||
When I update
|
||||
"""
|
||||
{"name":"foo"}
|
||||
"""
|
||||
Then expect a "not found" error
|
||||
And expect grpc error code "NOT_FOUND"
|
||||
#
|
||||
Scenario: can't violate unique constraint on insert
|
||||
Given an existing entity
|
||||
"""
|
||||
{"name": "foo", "unique": "bar"}
|
||||
"""
|
||||
When I insert
|
||||
"""
|
||||
{"name": "baz", "unique": "bar"}
|
||||
"""
|
||||
Then expect a "unique key violation" error
|
||||
And expect grpc error code "FAILED_PRECONDITION"
|
||||
|
||||
Scenario: can't violate unique constraint on update
|
||||
Given an existing entity
|
||||
"""
|
||||
{"name": "foo", "unique": "bar"}
|
||||
"""
|
||||
And an existing entity
|
||||
"""
|
||||
{"name": "baz", "unique": "bam"}
|
||||
"""
|
||||
When I update
|
||||
"""
|
||||
{"name": "baz", "unique": "bar"}
|
||||
"""
|
||||
Then expect a "unique key violation" error
|
||||
And expect grpc error code "FAILED_PRECONDITION"
|
||||
@ -1,17 +0,0 @@
|
||||
version: v1
|
||||
managed:
|
||||
enabled: true
|
||||
go_package_prefix:
|
||||
default: cosmossdk.io/orm/internal
|
||||
override:
|
||||
buf.build/cosmos/cosmos-sdk: cosmossdk.io/api
|
||||
plugins:
|
||||
- name: go
|
||||
out: .
|
||||
opt: paths=source_relative
|
||||
- name: go-grpc
|
||||
out: .
|
||||
opt: paths=source_relative
|
||||
- name: go-cosmos-orm
|
||||
out: .
|
||||
opt: paths=source_relative
|
||||
@ -1,11 +0,0 @@
|
||||
version: v1
|
||||
managed:
|
||||
enabled: true
|
||||
go_package_prefix:
|
||||
default: cosmossdk.io/orm/internal
|
||||
override:
|
||||
buf.build/cosmos/cosmos-sdk: cosmossdk.io/api
|
||||
plugins:
|
||||
- name: go-cosmos-orm-proto
|
||||
out: .
|
||||
opt: paths=source_relative
|
||||
@ -1,9 +0,0 @@
|
||||
version: v1
|
||||
lint:
|
||||
use:
|
||||
- DEFAULT
|
||||
except:
|
||||
- PACKAGE_VERSION_SUFFIX
|
||||
breaking:
|
||||
ignore:
|
||||
- testpb
|
||||
@ -1,91 +0,0 @@
|
||||
package codegen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/cosmos/cosmos-proto/generator"
|
||||
"google.golang.org/protobuf/compiler/protogen"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/types/pluginpb"
|
||||
|
||||
ormv1 "cosmossdk.io/api/cosmos/orm/v1"
|
||||
)
|
||||
|
||||
const (
|
||||
contextPkg = protogen.GoImportPath("context")
|
||||
ormListPkg = protogen.GoImportPath("cosmossdk.io/orm/model/ormlist")
|
||||
ormErrPkg = protogen.GoImportPath("cosmossdk.io/orm/types/ormerrors")
|
||||
ormTablePkg = protogen.GoImportPath("cosmossdk.io/orm/model/ormtable")
|
||||
)
|
||||
|
||||
func ORMPluginRunner(p *protogen.Plugin) error {
|
||||
p.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
|
||||
for _, f := range p.Files {
|
||||
if !f.Generate {
|
||||
continue
|
||||
}
|
||||
|
||||
if !hasTables(f) {
|
||||
continue
|
||||
}
|
||||
|
||||
gen := p.NewGeneratedFile(fmt.Sprintf("%s.cosmos_orm.go", f.GeneratedFilenamePrefix), f.GoImportPath)
|
||||
cgen := &generator.GeneratedFile{
|
||||
GeneratedFile: gen,
|
||||
LocalPackages: map[string]bool{},
|
||||
}
|
||||
fgen := fileGen{GeneratedFile: cgen, file: f}
|
||||
err := fgen.gen()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func QueryProtoPluginRunner(p *protogen.Plugin) error {
|
||||
p.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
|
||||
for _, f := range p.Files {
|
||||
if !f.Generate {
|
||||
continue
|
||||
}
|
||||
|
||||
if !hasTables(f) {
|
||||
continue
|
||||
}
|
||||
|
||||
out, err := os.OpenFile(fmt.Sprintf("%s_query.proto", f.GeneratedFilenamePrefix), os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = queryProtoGen{
|
||||
File: f,
|
||||
svc: newWriter(),
|
||||
msgs: newWriter(),
|
||||
outFile: out,
|
||||
imports: map[string]bool{},
|
||||
}.gen()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func hasTables(file *protogen.File) bool {
|
||||
for _, message := range file.Messages {
|
||||
if proto.GetExtension(message.Desc.Options(), ormv1.E_Table).(*ormv1.TableDescriptor) != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
if proto.GetExtension(message.Desc.Options(), ormv1.E_Singleton).(*ormv1.SingletonDescriptor) != nil {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
@ -1,85 +0,0 @@
|
||||
package codegen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/protobuf/compiler/protogen"
|
||||
"google.golang.org/protobuf/types/dynamicpb"
|
||||
|
||||
ormv1 "cosmossdk.io/api/cosmos/orm/v1"
|
||||
"cosmossdk.io/orm/model/ormtable"
|
||||
)
|
||||
|
||||
type singletonGen struct {
|
||||
fileGen
|
||||
msg *protogen.Message
|
||||
table *ormv1.SingletonDescriptor
|
||||
ormTable ormtable.Table
|
||||
}
|
||||
|
||||
func newSingletonGen(fileGen fileGen, msg *protogen.Message, table *ormv1.SingletonDescriptor) (*singletonGen, error) {
|
||||
s := &singletonGen{fileGen: fileGen, msg: msg, table: table}
|
||||
var err error
|
||||
s.ormTable, err = ormtable.Build(ormtable.Options{
|
||||
MessageType: dynamicpb.NewMessageType(msg.Desc),
|
||||
SingletonDescriptor: table,
|
||||
})
|
||||
return s, err
|
||||
}
|
||||
|
||||
func (s singletonGen) gen() {
|
||||
s.genInterface()
|
||||
s.genStruct()
|
||||
s.genInterfaceGuard()
|
||||
s.genMethods()
|
||||
s.genConstructor()
|
||||
}
|
||||
|
||||
func (s singletonGen) genInterface() {
|
||||
s.P("// singleton store")
|
||||
s.P("type ", s.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("}")
|
||||
s.P()
|
||||
}
|
||||
|
||||
func (s singletonGen) genStruct() {
|
||||
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.messageTableInterfaceName(s.msg), " = ", s.messageTableReceiverName(s.msg), "{}")
|
||||
}
|
||||
|
||||
func (s singletonGen) genMethods() {
|
||||
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) {")
|
||||
s.P(varName, " := &", s.msg.GoIdent.GoName, "{}")
|
||||
s.P("_, err := x.table.Get(ctx, ", varName, ")")
|
||||
s.P("return ", varName, ", err")
|
||||
s.P("}")
|
||||
s.P()
|
||||
|
||||
// Save
|
||||
s.P(receiver, "Save(ctx ", contextPkg.Ident("Context"), ", ", varName, " *", s.msg.GoIdent.GoName, ") error {")
|
||||
s.P("return x.table.Save(ctx, ", varName, ")")
|
||||
s.P("}")
|
||||
s.P()
|
||||
}
|
||||
|
||||
func (s singletonGen) genConstructor() {
|
||||
iface := s.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.messageTableReceiverName(s.msg), "{table}, nil")
|
||||
s.P("}")
|
||||
}
|
||||
@ -1,304 +0,0 @@
|
||||
//nolint:unused // ignore unused code linting
|
||||
package codegen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"google.golang.org/protobuf/compiler/protogen"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/types/dynamicpb"
|
||||
|
||||
ormv1 "cosmossdk.io/api/cosmos/orm/v1"
|
||||
"cosmossdk.io/orm/internal/fieldnames"
|
||||
"cosmossdk.io/orm/model/ormtable"
|
||||
)
|
||||
|
||||
type tableGen struct {
|
||||
fileGen
|
||||
msg *protogen.Message
|
||||
table *ormv1.TableDescriptor
|
||||
primaryKeyFields fieldnames.FieldNames
|
||||
fields map[protoreflect.Name]*protogen.Field
|
||||
uniqueIndexes []*ormv1.SecondaryIndexDescriptor
|
||||
ormTable ormtable.Table
|
||||
}
|
||||
|
||||
const notFoundDocs = " returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found."
|
||||
|
||||
func newTableGen(fileGen fileGen, msg *protogen.Message, table *ormv1.TableDescriptor) (*tableGen, error) {
|
||||
t := &tableGen{fileGen: fileGen, msg: msg, table: table, fields: map[protoreflect.Name]*protogen.Field{}}
|
||||
t.primaryKeyFields = fieldnames.CommaSeparatedFieldNames(table.PrimaryKey.Fields)
|
||||
for _, field := range msg.Fields {
|
||||
t.fields[field.Desc.Name()] = field
|
||||
}
|
||||
uniqIndexes := make([]*ormv1.SecondaryIndexDescriptor, 0)
|
||||
for _, idx := range t.table.Index {
|
||||
if idx.Unique {
|
||||
uniqIndexes = append(uniqIndexes, idx)
|
||||
}
|
||||
}
|
||||
t.uniqueIndexes = uniqIndexes
|
||||
var err error
|
||||
t.ormTable, err = ormtable.Build(ormtable.Options{
|
||||
MessageType: dynamicpb.NewMessageType(msg.Desc),
|
||||
TableDescriptor: table,
|
||||
})
|
||||
return t, err
|
||||
}
|
||||
|
||||
func (t tableGen) gen() {
|
||||
t.getTableInterface()
|
||||
t.genIterator()
|
||||
t.genIndexKeys()
|
||||
t.genStruct()
|
||||
t.genTableImpl()
|
||||
t.genTableImplGuard()
|
||||
t.genConstructor()
|
||||
}
|
||||
|
||||
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("InsertReturning", fieldsToCamelCase(t.table.PrimaryKey.Fields), "(ctx ", contextPkg.Ident("Context"), ", ", t.param(t.msg.GoIdent.GoName), " *", t.QualifiedGoIdent(t.msg.GoIdent), ") (uint64, error)")
|
||||
t.P("LastInsertedSequence(ctx ", contextPkg.Ident("Context"), ") (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")
|
||||
t.P("Delete(ctx ", contextPkg.Ident("Context"), ", ", t.param(t.msg.GoIdent.GoName), " *", t.QualifiedGoIdent(t.msg.GoIdent), ") error")
|
||||
t.P("Has(ctx ", contextPkg.Ident("Context"), ", ", t.fieldsArgs(t.primaryKeyFields.Names()), ") (found bool, err error)")
|
||||
t.P("// Get", notFoundDocs)
|
||||
t.P("Get(ctx ", contextPkg.Ident("Context"), ", ", t.fieldsArgs(t.primaryKeyFields.Names()), ") (*", t.QualifiedGoIdent(t.msg.GoIdent), ", error)")
|
||||
|
||||
for _, idx := range t.uniqueIndexes {
|
||||
t.genUniqueIndexSig(idx)
|
||||
}
|
||||
t.P("List(ctx ", contextPkg.Ident("Context"), ", prefixKey ", t.indexKeyInterfaceName(), ", opts ...", ormListPkg.Ident("Option"), ") ", "(", t.iteratorName(), ", error)")
|
||||
t.P("ListRange(ctx ", contextPkg.Ident("Context"), ", from, to ", t.indexKeyInterfaceName(), ", opts ...", ormListPkg.Ident("Option"), ") ", "(", t.iteratorName(), ", error)")
|
||||
t.P("DeleteBy(ctx ", contextPkg.Ident("Context"), ", prefixKey ", t.indexKeyInterfaceName(), ") error")
|
||||
t.P("DeleteRange(ctx ", contextPkg.Ident("Context"), ", from, to ", t.indexKeyInterfaceName(), ") error")
|
||||
t.P()
|
||||
t.P("doNotImplement()")
|
||||
t.P("}")
|
||||
t.P()
|
||||
}
|
||||
|
||||
// returns the has and get (in that order) function signature for unique indexes.
|
||||
func (t tableGen) uniqueIndexSig(idxFields string) (string, string, string) {
|
||||
fieldsSlc := strings.Split(idxFields, ",")
|
||||
camelFields := fieldsToCamelCase(idxFields)
|
||||
|
||||
hasFuncName := "HasBy" + camelFields
|
||||
getFuncName := "GetBy" + camelFields
|
||||
args := t.fieldArgsFromStringSlice(fieldsSlc)
|
||||
|
||||
hasFuncSig := fmt.Sprintf("%s (ctx context.Context, %s) (found bool, err error)", hasFuncName, args)
|
||||
getFuncSig := fmt.Sprintf("%s (ctx context.Context, %s) (*%s, error)", getFuncName, args, t.msg.GoIdent.GoName)
|
||||
return hasFuncSig, getFuncSig, getFuncName
|
||||
}
|
||||
|
||||
func (t tableGen) genUniqueIndexSig(idx *ormv1.SecondaryIndexDescriptor) {
|
||||
hasSig, getSig, getFuncName := t.uniqueIndexSig(idx.Fields)
|
||||
t.P(hasSig)
|
||||
t.P("// ", getFuncName, notFoundDocs)
|
||||
t.P(getSig)
|
||||
}
|
||||
|
||||
func (t tableGen) iteratorName() string {
|
||||
return t.msg.GoIdent.GoName + "Iterator"
|
||||
}
|
||||
|
||||
func (t tableGen) getSig() string {
|
||||
res := "Get" + t.msg.GoIdent.GoName + "("
|
||||
res += t.fieldsArgs(t.primaryKeyFields.Names())
|
||||
res += ") (*" + t.QualifiedGoIdent(t.msg.GoIdent) + ", error)"
|
||||
return res
|
||||
}
|
||||
|
||||
func (t tableGen) hasSig() string {
|
||||
t.P("Has(ctx ", contextPkg.Ident("Context"), ", ", t.fieldsArgs(t.primaryKeyFields.Names()), ") (found bool, err error)")
|
||||
return ""
|
||||
}
|
||||
|
||||
func (t tableGen) listSig() string {
|
||||
res := "List" + t.msg.GoIdent.GoName + "("
|
||||
res += t.indexKeyInterfaceName()
|
||||
res += ") ("
|
||||
res += t.iteratorName()
|
||||
res += ", error)"
|
||||
return res
|
||||
}
|
||||
|
||||
func (t tableGen) fieldArgsFromStringSlice(names []string) string {
|
||||
args := make([]string, len(names))
|
||||
for i, name := range names {
|
||||
args[i] = t.fieldArg(protoreflect.Name(name))
|
||||
}
|
||||
return strings.Join(args, ",")
|
||||
}
|
||||
|
||||
func (t tableGen) fieldsArgs(names []protoreflect.Name) string {
|
||||
var params []string
|
||||
for _, name := range names {
|
||||
params = append(params, t.fieldArg(name))
|
||||
}
|
||||
return strings.Join(params, ",")
|
||||
}
|
||||
|
||||
func (t tableGen) fieldArg(name protoreflect.Name) string {
|
||||
typ, pointer := t.GeneratedFile.FieldGoType(t.fields[name])
|
||||
if pointer {
|
||||
typ = "*" + typ
|
||||
}
|
||||
return string(name) + " " + typ
|
||||
}
|
||||
|
||||
func (t tableGen) genStruct() {
|
||||
t.P("type ", t.messageTableReceiverName(t.msg), " struct {")
|
||||
if t.table.PrimaryKey.AutoIncrement {
|
||||
t.P("table ", ormTablePkg.Ident("AutoIncrementTable"))
|
||||
} else {
|
||||
t.P("table ", ormTablePkg.Ident("Table"))
|
||||
}
|
||||
t.P("}")
|
||||
t.storeStructName()
|
||||
}
|
||||
|
||||
func (t tableGen) genTableImpl() {
|
||||
receiverVar := "this"
|
||||
receiver := fmt.Sprintf("func (%s %s) ", receiverVar, t.messageTableReceiverName(t.msg))
|
||||
varName := t.param(t.msg.GoIdent.GoName)
|
||||
varTypeName := t.QualifiedGoIdent(t.msg.GoIdent)
|
||||
|
||||
// these methods all have the same impl sans their names. so we can just loop and replace.
|
||||
methods := []string{"Insert", "Update", "Save", "Delete"}
|
||||
for _, method := range methods {
|
||||
t.P(receiver, method, "(ctx ", contextPkg.Ident("Context"), ", ", varName, " *", varTypeName, ") error {")
|
||||
t.P("return ", receiverVar, ".table.", method, "(ctx, ", varName, ")")
|
||||
t.P("}")
|
||||
t.P()
|
||||
}
|
||||
|
||||
if t.table.PrimaryKey.AutoIncrement {
|
||||
t.P(receiver, "InsertReturning", 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()
|
||||
|
||||
t.P(receiver, "LastInsertedSequence(ctx ", contextPkg.Ident("Context"), ") (uint64, error) {")
|
||||
t.P("return ", receiverVar, ".table.LastInsertedSequence(ctx)")
|
||||
t.P("}")
|
||||
t.P()
|
||||
}
|
||||
|
||||
// Has
|
||||
t.P(receiver, "Has(ctx ", contextPkg.Ident("Context"), ", ", t.fieldsArgs(t.primaryKeyFields.Names()), ") (found bool, err error) {")
|
||||
t.P("return ", receiverVar, ".table.PrimaryKey().Has(ctx, ", t.primaryKeyFields.String(), ")")
|
||||
t.P("}")
|
||||
t.P()
|
||||
|
||||
// Get
|
||||
t.P(receiver, "Get(ctx ", contextPkg.Ident("Context"), ", ", t.fieldsArgs(t.primaryKeyFields.Names()), ") (*", varTypeName, ", error) {")
|
||||
t.P("var ", varName, " ", varTypeName)
|
||||
t.P("found, err := ", receiverVar, ".table.PrimaryKey().Get(ctx, &", varName, ", ", t.primaryKeyFields.String(), ")")
|
||||
t.P("if err != nil {")
|
||||
t.P("return nil, err")
|
||||
t.P("}")
|
||||
t.P("if !found {")
|
||||
t.P("return nil, ", ormErrPkg.Ident("NotFound"))
|
||||
t.P("}")
|
||||
t.P("return &", varName, ", nil")
|
||||
t.P("}")
|
||||
t.P()
|
||||
|
||||
for _, idx := range t.uniqueIndexes {
|
||||
fields := strings.Split(idx.Fields, ",")
|
||||
hasName, getName, _ := t.uniqueIndexSig(idx.Fields)
|
||||
|
||||
// has
|
||||
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 {
|
||||
t.P(field, ",")
|
||||
}
|
||||
t.P(")")
|
||||
t.P("}")
|
||||
t.P()
|
||||
|
||||
// get
|
||||
varName := t.param(t.msg.GoIdent.GoName)
|
||||
varTypeName := t.msg.GoIdent.GoName
|
||||
t.P("func (", receiverVar, " ", t.messageTableReceiverName(t.msg), ") ", getName, "{")
|
||||
t.P("var ", varName, " ", varTypeName)
|
||||
t.P("found, err := ", receiverVar, ".table.GetIndexByID(", idx.Id, ").(",
|
||||
ormTablePkg.Ident("UniqueIndex"), ").Get(ctx, &", varName, ",")
|
||||
for _, field := range fields {
|
||||
t.P(field, ",")
|
||||
}
|
||||
t.P(")")
|
||||
t.P("if err != nil {")
|
||||
t.P("return nil, err")
|
||||
t.P("}")
|
||||
t.P("if !found {")
|
||||
t.P("return nil, ", ormErrPkg.Ident("NotFound"))
|
||||
t.P("}")
|
||||
t.P("return &", varName, ", nil")
|
||||
t.P("}")
|
||||
t.P()
|
||||
}
|
||||
|
||||
// List
|
||||
t.P(receiver, "List(ctx ", contextPkg.Ident("Context"), ", prefixKey ", t.indexKeyInterfaceName(), ", opts ...", ormListPkg.Ident("Option"), ") (", t.iteratorName(), ", error) {")
|
||||
t.P("it, err := ", receiverVar, ".table.GetIndexByID(prefixKey.id()).List(ctx, prefixKey.values(), opts...)")
|
||||
t.P("return ", t.iteratorName(), "{it}, err")
|
||||
t.P("}")
|
||||
t.P()
|
||||
|
||||
// ListRange
|
||||
t.P(receiver, "ListRange(ctx ", contextPkg.Ident("Context"), ", from, to ", t.indexKeyInterfaceName(), ", opts ...", ormListPkg.Ident("Option"), ") (", t.iteratorName(), ", error) {")
|
||||
t.P("it, err := ", receiverVar, ".table.GetIndexByID(from.id()).ListRange(ctx, from.values(), to.values(), opts...)")
|
||||
t.P("return ", t.iteratorName(), "{it}, err")
|
||||
t.P("}")
|
||||
t.P()
|
||||
|
||||
// DeleteBy
|
||||
t.P(receiver, "DeleteBy(ctx ", contextPkg.Ident("Context"), ", prefixKey ", t.indexKeyInterfaceName(), ") error {")
|
||||
t.P("return ", receiverVar, ".table.GetIndexByID(prefixKey.id()).DeleteBy(ctx, prefixKey.values()...)")
|
||||
t.P("}")
|
||||
t.P()
|
||||
t.P()
|
||||
|
||||
// DeleteRange
|
||||
t.P(receiver, "DeleteRange(ctx ", contextPkg.Ident("Context"), ", from, to ", t.indexKeyInterfaceName(), ") error {")
|
||||
t.P("return ", receiverVar, ".table.GetIndexByID(from.id()).DeleteRange(ctx, from.values(), to.values())")
|
||||
t.P("}")
|
||||
t.P()
|
||||
t.P()
|
||||
|
||||
t.P(receiver, "doNotImplement() {}")
|
||||
t.P()
|
||||
}
|
||||
|
||||
func (t tableGen) genTableImplGuard() {
|
||||
t.P("var _ ", t.messageTableInterfaceName(t.msg), " = ", t.messageTableReceiverName(t.msg), "{}")
|
||||
}
|
||||
|
||||
func (t tableGen) genConstructor() {
|
||||
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 {")
|
||||
t.P("return nil,", ormErrPkg.Ident("TableNotFound.Wrap"), "(string((&", t.msg.GoIdent.GoName, "{}).ProtoReflect().Descriptor().FullName()))")
|
||||
t.P("}")
|
||||
if t.table.PrimaryKey.AutoIncrement {
|
||||
t.P(
|
||||
"return ", t.messageTableReceiverName(t.msg), "{table.(",
|
||||
ormTablePkg.Ident("AutoIncrementTable"), ")}, nil",
|
||||
)
|
||||
} else {
|
||||
t.P("return ", t.messageTableReceiverName(t.msg), "{table}, nil")
|
||||
}
|
||||
t.P("}")
|
||||
}
|
||||
@ -1,55 +0,0 @@
|
||||
package fieldnames
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
)
|
||||
|
||||
// FieldNames abstractly represents a list of fields with a comparable type which
|
||||
// can be used as a map key. It is used primarily to lookup indexes.
|
||||
type FieldNames struct {
|
||||
fields string
|
||||
}
|
||||
|
||||
// CommaSeparatedFieldNames creates a FieldNames instance from a list of comma-separated
|
||||
// fields.
|
||||
func CommaSeparatedFieldNames(fields string) FieldNames {
|
||||
// normalize cases where there are spaces
|
||||
if strings.IndexByte(fields, ' ') >= 0 {
|
||||
parts := strings.Split(fields, ",")
|
||||
for i, part := range parts {
|
||||
parts[i] = strings.TrimSpace(part)
|
||||
}
|
||||
fields = strings.Join(parts, ",")
|
||||
}
|
||||
return FieldNames{fields: fields}
|
||||
}
|
||||
|
||||
// FieldsFromNames creates a FieldNames instance from an array of field
|
||||
// names.
|
||||
func FieldsFromNames(fnames []protoreflect.Name) FieldNames {
|
||||
var names []string
|
||||
for _, name := range fnames {
|
||||
names = append(names, string(name))
|
||||
}
|
||||
return FieldNames{fields: strings.Join(names, ",")}
|
||||
}
|
||||
|
||||
// Names returns the array of names this FieldNames instance represents.
|
||||
func (f FieldNames) Names() []protoreflect.Name {
|
||||
if f.fields == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
fields := strings.Split(f.fields, ",")
|
||||
names := make([]protoreflect.Name, len(fields))
|
||||
for i, field := range fields {
|
||||
names[i] = protoreflect.Name(field)
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
func (f FieldNames) String() string {
|
||||
return f.fields
|
||||
}
|
||||
@ -1,42 +0,0 @@
|
||||
package fieldnames
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"gotest.tools/v3/assert"
|
||||
)
|
||||
|
||||
func TestFieldNames(t *testing.T) {
|
||||
names := []protoreflect.Name{"a", "b", "c"}
|
||||
|
||||
abc := "a,b,c"
|
||||
f := CommaSeparatedFieldNames(abc)
|
||||
assert.Equal(t, FieldNames{abc}, f)
|
||||
assert.DeepEqual(t, names, f.Names())
|
||||
assert.Equal(t, abc, f.String())
|
||||
|
||||
f = CommaSeparatedFieldNames("a, b ,c")
|
||||
assert.Equal(t, FieldNames{abc}, f)
|
||||
assert.DeepEqual(t, names, f.Names())
|
||||
assert.Equal(t, abc, f.String())
|
||||
|
||||
// empty okay
|
||||
f = CommaSeparatedFieldNames("")
|
||||
assert.Equal(t, FieldNames{""}, f)
|
||||
assert.Equal(t, 0, len(f.Names()))
|
||||
assert.Equal(t, "", f.String())
|
||||
|
||||
f = FieldsFromNames(names)
|
||||
assert.Equal(t, FieldNames{abc}, f)
|
||||
assert.DeepEqual(t, names, f.Names())
|
||||
assert.Equal(t, abc, f.String())
|
||||
|
||||
// empty okay
|
||||
f = FieldsFromNames([]protoreflect.Name{})
|
||||
assert.Equal(t, FieldNames{""}, f)
|
||||
f = FieldsFromNames(nil)
|
||||
assert.Equal(t, FieldNames{""}, f)
|
||||
assert.Equal(t, 0, len(f.Names()))
|
||||
assert.Equal(t, "", f.String())
|
||||
}
|
||||
@ -1,93 +0,0 @@
|
||||
package stablejson
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/reflect/protopath"
|
||||
"google.golang.org/protobuf/reflect/protorange"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
)
|
||||
|
||||
// Marshal marshals the provided message to JSON with a stable ordering based
|
||||
// on ascending field numbers.
|
||||
func Marshal(message proto.Message) ([]byte, error) {
|
||||
buf := &bytes.Buffer{}
|
||||
firstStack := []bool{true}
|
||||
err := protorange.Options{
|
||||
Stable: true,
|
||||
}.Range(message.ProtoReflect(),
|
||||
func(p protopath.Values) error {
|
||||
// Starting printing the value.
|
||||
if !firstStack[len(firstStack)-1] {
|
||||
_, _ = fmt.Fprintf(buf, ",")
|
||||
}
|
||||
firstStack[len(firstStack)-1] = false
|
||||
|
||||
// Print the key.
|
||||
var fd protoreflect.FieldDescriptor
|
||||
last := p.Index(-1)
|
||||
beforeLast := p.Index(-2)
|
||||
switch last.Step.Kind() {
|
||||
case protopath.FieldAccessStep:
|
||||
fd = last.Step.FieldDescriptor()
|
||||
_, _ = fmt.Fprintf(buf, "%q:", fd.Name())
|
||||
case protopath.ListIndexStep:
|
||||
fd = beforeLast.Step.FieldDescriptor() // lists always appear in the context of a repeated field
|
||||
case protopath.MapIndexStep:
|
||||
fd = beforeLast.Step.FieldDescriptor() // maps always appear in the context of a repeated field
|
||||
_, _ = fmt.Fprintf(buf, "%v:", last.Step.MapIndex().Interface())
|
||||
case protopath.AnyExpandStep:
|
||||
_, _ = fmt.Fprintf(buf, `"@type":%q`, last.Value.Message().Descriptor().FullName())
|
||||
return nil
|
||||
case protopath.UnknownAccessStep:
|
||||
_, _ = fmt.Fprintf(buf, "?: ")
|
||||
}
|
||||
|
||||
switch v := last.Value.Interface().(type) {
|
||||
case protoreflect.Message:
|
||||
_, _ = fmt.Fprintf(buf, "{")
|
||||
firstStack = append(firstStack, true)
|
||||
case protoreflect.List:
|
||||
_, _ = fmt.Fprintf(buf, "[")
|
||||
firstStack = append(firstStack, true)
|
||||
case protoreflect.Map:
|
||||
_, _ = fmt.Fprintf(buf, "{")
|
||||
firstStack = append(firstStack, true)
|
||||
case protoreflect.EnumNumber:
|
||||
var ev protoreflect.EnumValueDescriptor
|
||||
if fd != nil {
|
||||
ev = fd.Enum().Values().ByNumber(v)
|
||||
}
|
||||
if ev != nil {
|
||||
_, _ = fmt.Fprintf(buf, "%v", ev.Name())
|
||||
} else {
|
||||
_, _ = fmt.Fprintf(buf, "%v", v)
|
||||
}
|
||||
case string, []byte:
|
||||
_, _ = fmt.Fprintf(buf, "%q", v)
|
||||
default:
|
||||
_, _ = fmt.Fprintf(buf, "%v", v)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
func(p protopath.Values) error {
|
||||
last := p.Index(-1)
|
||||
switch last.Value.Interface().(type) {
|
||||
case protoreflect.Message:
|
||||
if last.Step.Kind() != protopath.AnyExpandStep {
|
||||
_, _ = fmt.Fprintf(buf, "}")
|
||||
}
|
||||
case protoreflect.List:
|
||||
_, _ = fmt.Fprintf(buf, "]")
|
||||
firstStack = firstStack[:len(firstStack)-1]
|
||||
case protoreflect.Map:
|
||||
_, _ = fmt.Fprintf(buf, "}")
|
||||
firstStack = firstStack[:len(firstStack)-1]
|
||||
}
|
||||
return nil
|
||||
},
|
||||
)
|
||||
return buf.Bytes(), err
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
package stablejson_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-proto/anyutil"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
|
||||
bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1"
|
||||
basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1"
|
||||
txv1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1"
|
||||
"cosmossdk.io/orm/internal/stablejson"
|
||||
)
|
||||
|
||||
func TestStableJSON(t *testing.T) {
|
||||
msg, err := anyutil.New(&bankv1beta1.MsgSend{
|
||||
FromAddress: "foo213325",
|
||||
ToAddress: "foo32t5sdfh",
|
||||
Amount: []*basev1beta1.Coin{
|
||||
{
|
||||
Denom: "bar",
|
||||
Amount: "1234",
|
||||
},
|
||||
{
|
||||
Denom: "baz",
|
||||
Amount: "321",
|
||||
},
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
bz, err := stablejson.Marshal(&txv1beta1.TxBody{Messages: []*anypb.Any{msg}})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t,
|
||||
`{"messages":[{"@type":"cosmos.bank.v1beta1.MsgSend","from_address":"foo213325","to_address":"foo32t5sdfh","amount":[{"denom":"bar","amount":"1234"},{"denom":"baz","amount":"321"}]}]}`,
|
||||
string(bz))
|
||||
}
|
||||
@ -1,297 +0,0 @@
|
||||
// Code generated by protoc-gen-go-cosmos-orm. DO NOT EDIT.
|
||||
|
||||
package testpb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
ormlist "cosmossdk.io/orm/model/ormlist"
|
||||
ormtable "cosmossdk.io/orm/model/ormtable"
|
||||
ormerrors "cosmossdk.io/orm/types/ormerrors"
|
||||
)
|
||||
|
||||
type BalanceTable interface {
|
||||
Insert(ctx context.Context, balance *Balance) error
|
||||
Update(ctx context.Context, balance *Balance) error
|
||||
Save(ctx context.Context, balance *Balance) error
|
||||
Delete(ctx context.Context, balance *Balance) error
|
||||
Has(ctx context.Context, address string, denom string) (found bool, err error)
|
||||
// Get returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found.
|
||||
Get(ctx context.Context, address string, denom string) (*Balance, error)
|
||||
List(ctx context.Context, prefixKey BalanceIndexKey, opts ...ormlist.Option) (BalanceIterator, error)
|
||||
ListRange(ctx context.Context, from, to BalanceIndexKey, opts ...ormlist.Option) (BalanceIterator, error)
|
||||
DeleteBy(ctx context.Context, prefixKey BalanceIndexKey) error
|
||||
DeleteRange(ctx context.Context, from, to BalanceIndexKey) error
|
||||
|
||||
doNotImplement()
|
||||
}
|
||||
|
||||
type BalanceIterator struct {
|
||||
ormtable.Iterator
|
||||
}
|
||||
|
||||
func (i BalanceIterator) Value() (*Balance, error) {
|
||||
var balance Balance
|
||||
err := i.UnmarshalMessage(&balance)
|
||||
return &balance, err
|
||||
}
|
||||
|
||||
type BalanceIndexKey interface {
|
||||
id() uint32
|
||||
values() []interface{}
|
||||
balanceIndexKey()
|
||||
}
|
||||
|
||||
// primary key starting index..
|
||||
type BalancePrimaryKey = BalanceAddressDenomIndexKey
|
||||
|
||||
type BalanceAddressDenomIndexKey struct {
|
||||
vs []interface{}
|
||||
}
|
||||
|
||||
func (x BalanceAddressDenomIndexKey) id() uint32 { return 0 }
|
||||
func (x BalanceAddressDenomIndexKey) values() []interface{} { return x.vs }
|
||||
func (x BalanceAddressDenomIndexKey) balanceIndexKey() {}
|
||||
|
||||
func (this BalanceAddressDenomIndexKey) WithAddress(address string) BalanceAddressDenomIndexKey {
|
||||
this.vs = []interface{}{address}
|
||||
return this
|
||||
}
|
||||
|
||||
func (this BalanceAddressDenomIndexKey) WithAddressDenom(address string, denom string) BalanceAddressDenomIndexKey {
|
||||
this.vs = []interface{}{address, denom}
|
||||
return this
|
||||
}
|
||||
|
||||
type BalanceDenomIndexKey struct {
|
||||
vs []interface{}
|
||||
}
|
||||
|
||||
func (x BalanceDenomIndexKey) id() uint32 { return 1 }
|
||||
func (x BalanceDenomIndexKey) values() []interface{} { return x.vs }
|
||||
func (x BalanceDenomIndexKey) balanceIndexKey() {}
|
||||
|
||||
func (this BalanceDenomIndexKey) WithDenom(denom string) BalanceDenomIndexKey {
|
||||
this.vs = []interface{}{denom}
|
||||
return this
|
||||
}
|
||||
|
||||
type balanceTable struct {
|
||||
table ormtable.Table
|
||||
}
|
||||
|
||||
func (this balanceTable) Insert(ctx context.Context, balance *Balance) error {
|
||||
return this.table.Insert(ctx, balance)
|
||||
}
|
||||
|
||||
func (this balanceTable) Update(ctx context.Context, balance *Balance) error {
|
||||
return this.table.Update(ctx, balance)
|
||||
}
|
||||
|
||||
func (this balanceTable) Save(ctx context.Context, balance *Balance) error {
|
||||
return this.table.Save(ctx, balance)
|
||||
}
|
||||
|
||||
func (this balanceTable) Delete(ctx context.Context, balance *Balance) error {
|
||||
return this.table.Delete(ctx, balance)
|
||||
}
|
||||
|
||||
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 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 {
|
||||
return nil, err
|
||||
}
|
||||
if !found {
|
||||
return nil, ormerrors.NotFound
|
||||
}
|
||||
return &balance, nil
|
||||
}
|
||||
|
||||
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 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 balanceTable) DeleteBy(ctx context.Context, prefixKey BalanceIndexKey) error {
|
||||
return this.table.GetIndexByID(prefixKey.id()).DeleteBy(ctx, prefixKey.values()...)
|
||||
}
|
||||
|
||||
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 balanceTable) doNotImplement() {}
|
||||
|
||||
var _ BalanceTable = balanceTable{}
|
||||
|
||||
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 balanceTable{table}, nil
|
||||
}
|
||||
|
||||
type SupplyTable interface {
|
||||
Insert(ctx context.Context, supply *Supply) error
|
||||
Update(ctx context.Context, supply *Supply) error
|
||||
Save(ctx context.Context, supply *Supply) error
|
||||
Delete(ctx context.Context, supply *Supply) error
|
||||
Has(ctx context.Context, denom string) (found bool, err error)
|
||||
// Get returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found.
|
||||
Get(ctx context.Context, denom string) (*Supply, error)
|
||||
List(ctx context.Context, prefixKey SupplyIndexKey, opts ...ormlist.Option) (SupplyIterator, error)
|
||||
ListRange(ctx context.Context, from, to SupplyIndexKey, opts ...ormlist.Option) (SupplyIterator, error)
|
||||
DeleteBy(ctx context.Context, prefixKey SupplyIndexKey) error
|
||||
DeleteRange(ctx context.Context, from, to SupplyIndexKey) error
|
||||
|
||||
doNotImplement()
|
||||
}
|
||||
|
||||
type SupplyIterator struct {
|
||||
ormtable.Iterator
|
||||
}
|
||||
|
||||
func (i SupplyIterator) Value() (*Supply, error) {
|
||||
var supply Supply
|
||||
err := i.UnmarshalMessage(&supply)
|
||||
return &supply, err
|
||||
}
|
||||
|
||||
type SupplyIndexKey interface {
|
||||
id() uint32
|
||||
values() []interface{}
|
||||
supplyIndexKey()
|
||||
}
|
||||
|
||||
// primary key starting index..
|
||||
type SupplyPrimaryKey = SupplyDenomIndexKey
|
||||
|
||||
type SupplyDenomIndexKey struct {
|
||||
vs []interface{}
|
||||
}
|
||||
|
||||
func (x SupplyDenomIndexKey) id() uint32 { return 0 }
|
||||
func (x SupplyDenomIndexKey) values() []interface{} { return x.vs }
|
||||
func (x SupplyDenomIndexKey) supplyIndexKey() {}
|
||||
|
||||
func (this SupplyDenomIndexKey) WithDenom(denom string) SupplyDenomIndexKey {
|
||||
this.vs = []interface{}{denom}
|
||||
return this
|
||||
}
|
||||
|
||||
type supplyTable struct {
|
||||
table ormtable.Table
|
||||
}
|
||||
|
||||
func (this supplyTable) Insert(ctx context.Context, supply *Supply) error {
|
||||
return this.table.Insert(ctx, supply)
|
||||
}
|
||||
|
||||
func (this supplyTable) Update(ctx context.Context, supply *Supply) error {
|
||||
return this.table.Update(ctx, supply)
|
||||
}
|
||||
|
||||
func (this supplyTable) Save(ctx context.Context, supply *Supply) error {
|
||||
return this.table.Save(ctx, supply)
|
||||
}
|
||||
|
||||
func (this supplyTable) Delete(ctx context.Context, supply *Supply) error {
|
||||
return this.table.Delete(ctx, supply)
|
||||
}
|
||||
|
||||
func (this supplyTable) Has(ctx context.Context, denom string) (found bool, err error) {
|
||||
return this.table.PrimaryKey().Has(ctx, denom)
|
||||
}
|
||||
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
if !found {
|
||||
return nil, ormerrors.NotFound
|
||||
}
|
||||
return &supply, nil
|
||||
}
|
||||
|
||||
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 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 supplyTable) DeleteBy(ctx context.Context, prefixKey SupplyIndexKey) error {
|
||||
return this.table.GetIndexByID(prefixKey.id()).DeleteBy(ctx, prefixKey.values()...)
|
||||
}
|
||||
|
||||
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 supplyTable) doNotImplement() {}
|
||||
|
||||
var _ SupplyTable = supplyTable{}
|
||||
|
||||
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 supplyTable{table}, nil
|
||||
}
|
||||
|
||||
type BankStore interface {
|
||||
BalanceTable() BalanceTable
|
||||
SupplyTable() SupplyTable
|
||||
|
||||
doNotImplement()
|
||||
}
|
||||
|
||||
type bankStore struct {
|
||||
balance BalanceTable
|
||||
supply SupplyTable
|
||||
}
|
||||
|
||||
func (x bankStore) BalanceTable() BalanceTable {
|
||||
return x.balance
|
||||
}
|
||||
|
||||
func (x bankStore) SupplyTable() SupplyTable {
|
||||
return x.supply
|
||||
}
|
||||
|
||||
func (bankStore) doNotImplement() {}
|
||||
|
||||
var _ BankStore = bankStore{}
|
||||
|
||||
func NewBankStore(db ormtable.Schema) (BankStore, error) {
|
||||
balanceTable, err := NewBalanceTable(db)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
supplyTable, err := NewSupplyTable(db)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return bankStore{
|
||||
balanceTable,
|
||||
supplyTable,
|
||||
}, nil
|
||||
}
|
||||
@ -1,308 +0,0 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.28.1
|
||||
// protoc (unknown)
|
||||
// source: testpb/bank.proto
|
||||
|
||||
package testpb
|
||||
|
||||
import (
|
||||
_ "cosmossdk.io/api/cosmos/app/v1alpha1"
|
||||
_ "cosmossdk.io/api/cosmos/orm/v1"
|
||||
_ "cosmossdk.io/api/cosmos/orm/v1alpha1"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
// Module is a test module for demonstrating how to use the ORM with appconfig.
|
||||
type Module struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
}
|
||||
|
||||
func (x *Module) Reset() {
|
||||
*x = Module{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_testpb_bank_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Module) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Module) ProtoMessage() {}
|
||||
|
||||
func (x *Module) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_testpb_bank_proto_msgTypes[0]
|
||||
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)
|
||||
}
|
||||
|
||||
// Deprecated: Use Module.ProtoReflect.Descriptor instead.
|
||||
func (*Module) Descriptor() ([]byte, []int) {
|
||||
return file_testpb_bank_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
type Balance struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"`
|
||||
Denom string `protobuf:"bytes,2,opt,name=denom,proto3" json:"denom,omitempty"`
|
||||
Amount uint64 `protobuf:"varint,3,opt,name=amount,proto3" json:"amount,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Balance) Reset() {
|
||||
*x = Balance{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_testpb_bank_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Balance) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Balance) ProtoMessage() {}
|
||||
|
||||
func (x *Balance) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_testpb_bank_proto_msgTypes[1]
|
||||
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)
|
||||
}
|
||||
|
||||
// Deprecated: Use Balance.ProtoReflect.Descriptor instead.
|
||||
func (*Balance) Descriptor() ([]byte, []int) {
|
||||
return file_testpb_bank_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *Balance) GetAddress() string {
|
||||
if x != nil {
|
||||
return x.Address
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Balance) GetDenom() string {
|
||||
if x != nil {
|
||||
return x.Denom
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Balance) GetAmount() uint64 {
|
||||
if x != nil {
|
||||
return x.Amount
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type Supply struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"`
|
||||
Amount uint64 `protobuf:"varint,2,opt,name=amount,proto3" json:"amount,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Supply) Reset() {
|
||||
*x = Supply{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_testpb_bank_proto_msgTypes[2]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Supply) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Supply) ProtoMessage() {}
|
||||
|
||||
func (x *Supply) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_testpb_bank_proto_msgTypes[2]
|
||||
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)
|
||||
}
|
||||
|
||||
// Deprecated: Use Supply.ProtoReflect.Descriptor instead.
|
||||
func (*Supply) Descriptor() ([]byte, []int) {
|
||||
return file_testpb_bank_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
func (x *Supply) GetDenom() string {
|
||||
if x != nil {
|
||||
return x.Denom
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Supply) GetAmount() uint64 {
|
||||
if x != nil {
|
||||
return x.Amount
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
var File_testpb_bank_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_testpb_bank_proto_rawDesc = []byte{
|
||||
0x0a, 0x11, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x62, 0x61, 0x6e, 0x6b, 0x2e, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x12, 0x06, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x1a, 0x17, 0x63, 0x6f, 0x73,
|
||||
0x6d, 0x6f, 0x73, 0x2f, 0x6f, 0x72, 0x6d, 0x2f, 0x76, 0x31, 0x2f, 0x6f, 0x72, 0x6d, 0x2e, 0x70,
|
||||
0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x20, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x6f, 0x72, 0x6d,
|
||||
0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61,
|
||||
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x20, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x61,
|
||||
0x70, 0x70, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x6d, 0x6f, 0x64, 0x75,
|
||||
0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x50, 0x0a, 0x06, 0x4d, 0x6f, 0x64, 0x75,
|
||||
0x6c, 0x65, 0x3a, 0x46, 0xba, 0xc0, 0x96, 0xda, 0x01, 0x23, 0x0a, 0x21, 0x67, 0x69, 0x74, 0x68,
|
||||
0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x6f, 0x72,
|
||||
0x6d, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2f, 0x6f, 0x72, 0x6d, 0x64, 0x62, 0x82, 0x9f, 0xd3,
|
||||
0x8e, 0x03, 0x17, 0x0a, 0x15, 0x08, 0x01, 0x12, 0x11, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f,
|
||||
0x62, 0x61, 0x6e, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x77, 0x0a, 0x07, 0x42, 0x61,
|
||||
0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12,
|
||||
0x14, 0x0a, 0x05, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05,
|
||||
0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18,
|
||||
0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x3a, 0x24, 0xf2,
|
||||
0x9e, 0xd3, 0x8e, 0x03, 0x1e, 0x0a, 0x0f, 0x0a, 0x0d, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73,
|
||||
0x2c, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x12, 0x09, 0x0a, 0x05, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x10,
|
||||
0x01, 0x18, 0x01, 0x22, 0x49, 0x0a, 0x06, 0x53, 0x75, 0x70, 0x70, 0x6c, 0x79, 0x12, 0x14, 0x0a,
|
||||
0x05, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x64, 0x65,
|
||||
0x6e, 0x6f, 0x6d, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20,
|
||||
0x01, 0x28, 0x04, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x3a, 0x11, 0xf2, 0x9e, 0xd3,
|
||||
0x8e, 0x03, 0x0b, 0x0a, 0x07, 0x0a, 0x05, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x18, 0x02, 0x42, 0x71,
|
||||
0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x42, 0x09, 0x42, 0x61,
|
||||
0x6e, 0x6b, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x20, 0x63, 0x6f, 0x73, 0x6d, 0x6f,
|
||||
0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x6f, 0x72, 0x6d, 0x2f, 0x69, 0x6e, 0x74, 0x65,
|
||||
0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0xa2, 0x02, 0x03, 0x54, 0x58,
|
||||
0x58, 0xaa, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xca, 0x02, 0x06, 0x54, 0x65, 0x73,
|
||||
0x74, 0x70, 0x62, 0xe2, 0x02, 0x12, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x5c, 0x47, 0x50, 0x42,
|
||||
0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70,
|
||||
0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_testpb_bank_proto_rawDescOnce sync.Once
|
||||
file_testpb_bank_proto_rawDescData = file_testpb_bank_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_testpb_bank_proto_rawDescGZIP() []byte {
|
||||
file_testpb_bank_proto_rawDescOnce.Do(func() {
|
||||
file_testpb_bank_proto_rawDescData = protoimpl.X.CompressGZIP(file_testpb_bank_proto_rawDescData)
|
||||
})
|
||||
return file_testpb_bank_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_testpb_bank_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
|
||||
var file_testpb_bank_proto_goTypes = []interface{}{
|
||||
(*Module)(nil), // 0: testpb.Module
|
||||
(*Balance)(nil), // 1: testpb.Balance
|
||||
(*Supply)(nil), // 2: testpb.Supply
|
||||
}
|
||||
var file_testpb_bank_proto_depIdxs = []int32{
|
||||
0, // [0:0] is the sub-list for method output_type
|
||||
0, // [0:0] is the sub-list for method input_type
|
||||
0, // [0:0] is the sub-list for extension type_name
|
||||
0, // [0:0] is the sub-list for extension extendee
|
||||
0, // [0:0] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_testpb_bank_proto_init() }
|
||||
func file_testpb_bank_proto_init() {
|
||||
if File_testpb_bank_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_testpb_bank_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Module); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_testpb_bank_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Balance); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_testpb_bank_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Supply); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_testpb_bank_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 3,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
GoTypes: file_testpb_bank_proto_goTypes,
|
||||
DependencyIndexes: file_testpb_bank_proto_depIdxs,
|
||||
MessageInfos: file_testpb_bank_proto_msgTypes,
|
||||
}.Build()
|
||||
File_testpb_bank_proto = out.File
|
||||
file_testpb_bank_proto_rawDesc = nil
|
||||
file_testpb_bank_proto_goTypes = nil
|
||||
file_testpb_bank_proto_depIdxs = nil
|
||||
}
|
||||
@ -1,50 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package testpb;
|
||||
|
||||
import "cosmos/orm/v1/orm.proto";
|
||||
import "cosmos/orm/v1alpha1/schema.proto";
|
||||
import "cosmos/app/v1alpha1/module.proto";
|
||||
|
||||
// This is a simulated bank schema used for testing.
|
||||
|
||||
// Module is a test module for demonstrating how to use the ORM with appconfig.
|
||||
message Module {
|
||||
option (cosmos.app.v1alpha1.module) = {
|
||||
go_import: "github.com/cosmos/orm/model/ormdb"
|
||||
};
|
||||
option (cosmos.orm.v1alpha1.module_schema) = {
|
||||
schema_file: {id: 1 proto_file_name: "testpb/bank.proto"}
|
||||
};
|
||||
}
|
||||
|
||||
message Balance {
|
||||
option (cosmos.orm.v1.table) = {
|
||||
id: 1;
|
||||
primary_key: {
|
||||
fields:
|
||||
"address,denom"
|
||||
}
|
||||
index: {
|
||||
id:
|
||||
1 fields: "denom"
|
||||
}
|
||||
};
|
||||
|
||||
string address = 1;
|
||||
string denom = 2;
|
||||
uint64 amount = 3;
|
||||
}
|
||||
|
||||
message Supply {
|
||||
option (cosmos.orm.v1.table) = {
|
||||
id: 2;
|
||||
primary_key: {
|
||||
fields:
|
||||
"denom"
|
||||
}
|
||||
};
|
||||
|
||||
string denom = 1;
|
||||
uint64 amount = 2;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,149 +0,0 @@
|
||||
// Code generated by protoc-gen-go-cosmos-orm-proto. DO NOT EDIT.
|
||||
syntax = "proto3";
|
||||
package testpb;
|
||||
|
||||
import "cosmos/base/query/v1beta1/pagination.proto";
|
||||
import "testpb/bank.proto";
|
||||
|
||||
// BankQueryService queries the state of the tables specified by testpb/bank.proto.
|
||||
service BankQueryService {
|
||||
// Get queries the Balance table by its primary key.
|
||||
rpc GetBalance(GetBalanceRequest) returns (GetBalanceResponse) {}
|
||||
// ListBalance queries the Balance table using prefix and range queries against defined indexes.
|
||||
rpc ListBalance(ListBalanceRequest) returns (ListBalanceResponse) {}
|
||||
// Get queries the Supply table by its primary key.
|
||||
rpc GetSupply(GetSupplyRequest) returns (GetSupplyResponse) {}
|
||||
// ListSupply queries the Supply table using prefix and range queries against defined indexes.
|
||||
rpc ListSupply(ListSupplyRequest) returns (ListSupplyResponse) {}
|
||||
}
|
||||
|
||||
// GetBalanceRequest is the BankQuery/GetBalanceRequest request type.
|
||||
message GetBalanceRequest {
|
||||
// address specifies the value of the address field in the primary key.
|
||||
string address = 1;
|
||||
// denom specifies the value of the denom field in the primary key.
|
||||
string denom = 2;
|
||||
}
|
||||
|
||||
// GetBalanceResponse is the BankQuery/GetBalanceResponse response type.
|
||||
message GetBalanceResponse {
|
||||
// value is the response value.
|
||||
Balance value = 1;
|
||||
}
|
||||
|
||||
// ListBalanceRequest is the BankQuery/ListBalanceRequest request type.
|
||||
message ListBalanceRequest {
|
||||
// IndexKey specifies the value of an index key to use in prefix and range queries.
|
||||
message IndexKey {
|
||||
// key specifies the index key value.
|
||||
oneof key {
|
||||
// address_denom specifies the value of the AddressDenom index key to use in the query.
|
||||
AddressDenom address_denom = 1;
|
||||
// denom specifies the value of the Denom index key to use in the query.
|
||||
Denom denom = 2;
|
||||
}
|
||||
|
||||
message AddressDenom {
|
||||
// address is the value of the address field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional string address = 1;
|
||||
// denom is the value of the denom field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional string denom = 2;
|
||||
}
|
||||
|
||||
message Denom {
|
||||
// denom is the value of the denom field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional string denom = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// query specifies the type of query - either a prefix or range query.
|
||||
oneof query {
|
||||
// prefix_query specifies the index key value to use for the prefix query.
|
||||
IndexKey prefix_query = 1;
|
||||
// range_query specifies the index key from/to values to use for the range query.
|
||||
RangeQuery range_query = 2;
|
||||
}
|
||||
// pagination specifies optional pagination parameters.
|
||||
cosmos.base.query.v1beta1.PageRequest pagination = 3;
|
||||
|
||||
// RangeQuery specifies the from/to index keys for a range query.
|
||||
message RangeQuery {
|
||||
// from is the index key to use for the start of the range query.
|
||||
// To query from the start of an index, specify an index key for that index with empty values.
|
||||
IndexKey from = 1;
|
||||
// to is the index key to use for the end of the range query.
|
||||
// The index key type MUST be the same as the index key type used for from.
|
||||
// To query from to the end of an index it can be omitted.
|
||||
IndexKey to = 2;
|
||||
}
|
||||
}
|
||||
|
||||
// ListBalanceResponse is the BankQuery/ListBalanceResponse response type.
|
||||
message ListBalanceResponse {
|
||||
// values are the results of the query.
|
||||
repeated Balance values = 1;
|
||||
// pagination is the pagination response.
|
||||
cosmos.base.query.v1beta1.PageResponse pagination = 2;
|
||||
}
|
||||
|
||||
// GetSupplyRequest is the BankQuery/GetSupplyRequest request type.
|
||||
message GetSupplyRequest {
|
||||
// denom specifies the value of the denom field in the primary key.
|
||||
string denom = 1;
|
||||
}
|
||||
|
||||
// GetSupplyResponse is the BankQuery/GetSupplyResponse response type.
|
||||
message GetSupplyResponse {
|
||||
// value is the response value.
|
||||
Supply value = 1;
|
||||
}
|
||||
|
||||
// ListSupplyRequest is the BankQuery/ListSupplyRequest request type.
|
||||
message ListSupplyRequest {
|
||||
// IndexKey specifies the value of an index key to use in prefix and range queries.
|
||||
message IndexKey {
|
||||
// key specifies the index key value.
|
||||
oneof key {
|
||||
// denom specifies the value of the Denom index key to use in the query.
|
||||
Denom denom = 1;
|
||||
}
|
||||
|
||||
message Denom {
|
||||
// denom is the value of the denom field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional string denom = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// query specifies the type of query - either a prefix or range query.
|
||||
oneof query {
|
||||
// prefix_query specifies the index key value to use for the prefix query.
|
||||
IndexKey prefix_query = 1;
|
||||
// range_query specifies the index key from/to values to use for the range query.
|
||||
RangeQuery range_query = 2;
|
||||
}
|
||||
// pagination specifies optional pagination parameters.
|
||||
cosmos.base.query.v1beta1.PageRequest pagination = 3;
|
||||
|
||||
// RangeQuery specifies the from/to index keys for a range query.
|
||||
message RangeQuery {
|
||||
// from is the index key to use for the start of the range query.
|
||||
// To query from the start of an index, specify an index key for that index with empty values.
|
||||
IndexKey from = 1;
|
||||
// to is the index key to use for the end of the range query.
|
||||
// The index key type MUST be the same as the index key type used for from.
|
||||
// To query from to the end of an index it can be omitted.
|
||||
IndexKey to = 2;
|
||||
}
|
||||
}
|
||||
|
||||
// ListSupplyResponse is the BankQuery/ListSupplyResponse response type.
|
||||
message ListSupplyResponse {
|
||||
// values are the results of the query.
|
||||
repeated Supply values = 1;
|
||||
// pagination is the pagination response.
|
||||
cosmos.base.query.v1beta1.PageResponse pagination = 2;
|
||||
}
|
||||
@ -1,230 +0,0 @@
|
||||
// Code generated by protoc-gen-go-cosmos-orm-proto. DO NOT EDIT.
|
||||
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.3.0
|
||||
// - protoc (unknown)
|
||||
// source: testpb/bank_query.proto
|
||||
|
||||
package testpb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
// Requires gRPC-Go v1.32.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion7
|
||||
|
||||
const (
|
||||
BankQueryService_GetBalance_FullMethodName = "/testpb.BankQueryService/GetBalance"
|
||||
BankQueryService_ListBalance_FullMethodName = "/testpb.BankQueryService/ListBalance"
|
||||
BankQueryService_GetSupply_FullMethodName = "/testpb.BankQueryService/GetSupply"
|
||||
BankQueryService_ListSupply_FullMethodName = "/testpb.BankQueryService/ListSupply"
|
||||
)
|
||||
|
||||
// BankQueryServiceClient is the client API for BankQueryService service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type BankQueryServiceClient interface {
|
||||
// Get queries the Balance table by its primary key.
|
||||
GetBalance(ctx context.Context, in *GetBalanceRequest, opts ...grpc.CallOption) (*GetBalanceResponse, error)
|
||||
// ListBalance queries the Balance table using prefix and range queries against defined indexes.
|
||||
ListBalance(ctx context.Context, in *ListBalanceRequest, opts ...grpc.CallOption) (*ListBalanceResponse, error)
|
||||
// Get queries the Supply table by its primary key.
|
||||
GetSupply(ctx context.Context, in *GetSupplyRequest, opts ...grpc.CallOption) (*GetSupplyResponse, error)
|
||||
// ListSupply queries the Supply table using prefix and range queries against defined indexes.
|
||||
ListSupply(ctx context.Context, in *ListSupplyRequest, opts ...grpc.CallOption) (*ListSupplyResponse, error)
|
||||
}
|
||||
|
||||
type bankQueryServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewBankQueryServiceClient(cc grpc.ClientConnInterface) BankQueryServiceClient {
|
||||
return &bankQueryServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *bankQueryServiceClient) GetBalance(ctx context.Context, in *GetBalanceRequest, opts ...grpc.CallOption) (*GetBalanceResponse, error) {
|
||||
out := new(GetBalanceResponse)
|
||||
err := c.cc.Invoke(ctx, BankQueryService_GetBalance_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *bankQueryServiceClient) ListBalance(ctx context.Context, in *ListBalanceRequest, opts ...grpc.CallOption) (*ListBalanceResponse, error) {
|
||||
out := new(ListBalanceResponse)
|
||||
err := c.cc.Invoke(ctx, BankQueryService_ListBalance_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *bankQueryServiceClient) GetSupply(ctx context.Context, in *GetSupplyRequest, opts ...grpc.CallOption) (*GetSupplyResponse, error) {
|
||||
out := new(GetSupplyResponse)
|
||||
err := c.cc.Invoke(ctx, BankQueryService_GetSupply_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *bankQueryServiceClient) ListSupply(ctx context.Context, in *ListSupplyRequest, opts ...grpc.CallOption) (*ListSupplyResponse, error) {
|
||||
out := new(ListSupplyResponse)
|
||||
err := c.cc.Invoke(ctx, BankQueryService_ListSupply_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// BankQueryServiceServer is the server API for BankQueryService service.
|
||||
// All implementations must embed UnimplementedBankQueryServiceServer
|
||||
// for forward compatibility
|
||||
type BankQueryServiceServer interface {
|
||||
// Get queries the Balance table by its primary key.
|
||||
GetBalance(context.Context, *GetBalanceRequest) (*GetBalanceResponse, error)
|
||||
// ListBalance queries the Balance table using prefix and range queries against defined indexes.
|
||||
ListBalance(context.Context, *ListBalanceRequest) (*ListBalanceResponse, error)
|
||||
// Get queries the Supply table by its primary key.
|
||||
GetSupply(context.Context, *GetSupplyRequest) (*GetSupplyResponse, error)
|
||||
// ListSupply queries the Supply table using prefix and range queries against defined indexes.
|
||||
ListSupply(context.Context, *ListSupplyRequest) (*ListSupplyResponse, error)
|
||||
mustEmbedUnimplementedBankQueryServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedBankQueryServiceServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedBankQueryServiceServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedBankQueryServiceServer) GetBalance(context.Context, *GetBalanceRequest) (*GetBalanceResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetBalance not implemented")
|
||||
}
|
||||
func (UnimplementedBankQueryServiceServer) ListBalance(context.Context, *ListBalanceRequest) (*ListBalanceResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListBalance not implemented")
|
||||
}
|
||||
func (UnimplementedBankQueryServiceServer) GetSupply(context.Context, *GetSupplyRequest) (*GetSupplyResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetSupply not implemented")
|
||||
}
|
||||
func (UnimplementedBankQueryServiceServer) ListSupply(context.Context, *ListSupplyRequest) (*ListSupplyResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListSupply not implemented")
|
||||
}
|
||||
func (UnimplementedBankQueryServiceServer) mustEmbedUnimplementedBankQueryServiceServer() {}
|
||||
|
||||
// UnsafeBankQueryServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to BankQueryServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeBankQueryServiceServer interface {
|
||||
mustEmbedUnimplementedBankQueryServiceServer()
|
||||
}
|
||||
|
||||
func RegisterBankQueryServiceServer(s grpc.ServiceRegistrar, srv BankQueryServiceServer) {
|
||||
s.RegisterService(&BankQueryService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _BankQueryService_GetBalance_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetBalanceRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(BankQueryServiceServer).GetBalance(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: BankQueryService_GetBalance_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(BankQueryServiceServer).GetBalance(ctx, req.(*GetBalanceRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _BankQueryService_ListBalance_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListBalanceRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(BankQueryServiceServer).ListBalance(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: BankQueryService_ListBalance_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(BankQueryServiceServer).ListBalance(ctx, req.(*ListBalanceRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _BankQueryService_GetSupply_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetSupplyRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(BankQueryServiceServer).GetSupply(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: BankQueryService_GetSupply_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(BankQueryServiceServer).GetSupply(ctx, req.(*GetSupplyRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _BankQueryService_ListSupply_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListSupplyRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(BankQueryServiceServer).ListSupply(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: BankQueryService_ListSupply_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(BankQueryServiceServer).ListSupply(ctx, req.(*ListSupplyRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// BankQueryService_ServiceDesc is the grpc.ServiceDesc for BankQueryService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var BankQueryService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "testpb.BankQueryService",
|
||||
HandlerType: (*BankQueryServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "GetBalance",
|
||||
Handler: _BankQueryService_GetBalance_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListBalance",
|
||||
Handler: _BankQueryService_ListBalance_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetSupply",
|
||||
Handler: _BankQueryService_GetSupply_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListSupply",
|
||||
Handler: _BankQueryService_ListSupply_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "testpb/bank_query.proto",
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,999 +0,0 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.28.1
|
||||
// protoc (unknown)
|
||||
// source: testpb/test_schema.proto
|
||||
|
||||
package testpb
|
||||
|
||||
import (
|
||||
_ "cosmossdk.io/api/cosmos/orm/v1"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
durationpb "google.golang.org/protobuf/types/known/durationpb"
|
||||
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
type Enum int32
|
||||
|
||||
const (
|
||||
Enum_ENUM_UNSPECIFIED Enum = 0
|
||||
Enum_ENUM_ONE Enum = 1
|
||||
Enum_ENUM_TWO Enum = 2
|
||||
Enum_ENUM_FIVE Enum = 5
|
||||
Enum_ENUM_NEG_THREE Enum = -3
|
||||
)
|
||||
|
||||
// Enum value maps for Enum.
|
||||
var (
|
||||
Enum_name = map[int32]string{
|
||||
0: "ENUM_UNSPECIFIED",
|
||||
1: "ENUM_ONE",
|
||||
2: "ENUM_TWO",
|
||||
5: "ENUM_FIVE",
|
||||
-3: "ENUM_NEG_THREE",
|
||||
}
|
||||
Enum_value = map[string]int32{
|
||||
"ENUM_UNSPECIFIED": 0,
|
||||
"ENUM_ONE": 1,
|
||||
"ENUM_TWO": 2,
|
||||
"ENUM_FIVE": 5,
|
||||
"ENUM_NEG_THREE": -3,
|
||||
}
|
||||
)
|
||||
|
||||
func (x Enum) Enum() *Enum {
|
||||
p := new(Enum)
|
||||
*p = x
|
||||
return p
|
||||
}
|
||||
|
||||
func (x Enum) String() string {
|
||||
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
|
||||
}
|
||||
|
||||
func (Enum) Descriptor() protoreflect.EnumDescriptor {
|
||||
return file_testpb_test_schema_proto_enumTypes[0].Descriptor()
|
||||
}
|
||||
|
||||
func (Enum) Type() protoreflect.EnumType {
|
||||
return &file_testpb_test_schema_proto_enumTypes[0]
|
||||
}
|
||||
|
||||
func (x Enum) Number() protoreflect.EnumNumber {
|
||||
return protoreflect.EnumNumber(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Enum.Descriptor instead.
|
||||
func (Enum) EnumDescriptor() ([]byte, []int) {
|
||||
return file_testpb_test_schema_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
type ExampleTable struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
// Valid key fields:
|
||||
U32 uint32 `protobuf:"varint,1,opt,name=u32,proto3" json:"u32,omitempty"`
|
||||
U64 uint64 `protobuf:"varint,2,opt,name=u64,proto3" json:"u64,omitempty"`
|
||||
Str string `protobuf:"bytes,3,opt,name=str,proto3" json:"str,omitempty"`
|
||||
Bz []byte `protobuf:"bytes,4,opt,name=bz,proto3" json:"bz,omitempty"`
|
||||
Ts *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=ts,proto3" json:"ts,omitempty"`
|
||||
Dur *durationpb.Duration `protobuf:"bytes,6,opt,name=dur,proto3" json:"dur,omitempty"`
|
||||
I32 int32 `protobuf:"varint,7,opt,name=i32,proto3" json:"i32,omitempty"`
|
||||
S32 int32 `protobuf:"zigzag32,8,opt,name=s32,proto3" json:"s32,omitempty"`
|
||||
Sf32 int32 `protobuf:"fixed32,9,opt,name=sf32,proto3" json:"sf32,omitempty"`
|
||||
I64 int64 `protobuf:"varint,10,opt,name=i64,proto3" json:"i64,omitempty"`
|
||||
S64 int64 `protobuf:"zigzag64,11,opt,name=s64,proto3" json:"s64,omitempty"`
|
||||
Sf64 int64 `protobuf:"fixed64,12,opt,name=sf64,proto3" json:"sf64,omitempty"`
|
||||
F32 uint32 `protobuf:"fixed32,13,opt,name=f32,proto3" json:"f32,omitempty"`
|
||||
F64 uint64 `protobuf:"fixed64,14,opt,name=f64,proto3" json:"f64,omitempty"`
|
||||
B bool `protobuf:"varint,15,opt,name=b,proto3" json:"b,omitempty"`
|
||||
E Enum `protobuf:"varint,16,opt,name=e,proto3,enum=testpb.Enum" json:"e,omitempty"`
|
||||
// Invalid key fields:
|
||||
Repeated []uint32 `protobuf:"varint,17,rep,packed,name=repeated,proto3" json:"repeated,omitempty"`
|
||||
Map map[string]uint32 `protobuf:"bytes,18,rep,name=map,proto3" json:"map,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"`
|
||||
Msg *ExampleTable_ExampleMessage `protobuf:"bytes,19,opt,name=msg,proto3" json:"msg,omitempty"`
|
||||
// Types that are assignable to Sum:
|
||||
//
|
||||
// *ExampleTable_Oneof
|
||||
Sum isExampleTable_Sum `protobuf_oneof:"sum"`
|
||||
}
|
||||
|
||||
func (x *ExampleTable) Reset() {
|
||||
*x = ExampleTable{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_testpb_test_schema_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *ExampleTable) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ExampleTable) ProtoMessage() {}
|
||||
|
||||
func (x *ExampleTable) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_testpb_test_schema_proto_msgTypes[0]
|
||||
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)
|
||||
}
|
||||
|
||||
// Deprecated: Use ExampleTable.ProtoReflect.Descriptor instead.
|
||||
func (*ExampleTable) Descriptor() ([]byte, []int) {
|
||||
return file_testpb_test_schema_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *ExampleTable) GetU32() uint32 {
|
||||
if x != nil {
|
||||
return x.U32
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ExampleTable) GetU64() uint64 {
|
||||
if x != nil {
|
||||
return x.U64
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ExampleTable) GetStr() string {
|
||||
if x != nil {
|
||||
return x.Str
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *ExampleTable) GetBz() []byte {
|
||||
if x != nil {
|
||||
return x.Bz
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *ExampleTable) GetTs() *timestamppb.Timestamp {
|
||||
if x != nil {
|
||||
return x.Ts
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *ExampleTable) GetDur() *durationpb.Duration {
|
||||
if x != nil {
|
||||
return x.Dur
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *ExampleTable) GetI32() int32 {
|
||||
if x != nil {
|
||||
return x.I32
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ExampleTable) GetS32() int32 {
|
||||
if x != nil {
|
||||
return x.S32
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ExampleTable) GetSf32() int32 {
|
||||
if x != nil {
|
||||
return x.Sf32
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ExampleTable) GetI64() int64 {
|
||||
if x != nil {
|
||||
return x.I64
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ExampleTable) GetS64() int64 {
|
||||
if x != nil {
|
||||
return x.S64
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ExampleTable) GetSf64() int64 {
|
||||
if x != nil {
|
||||
return x.Sf64
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ExampleTable) GetF32() uint32 {
|
||||
if x != nil {
|
||||
return x.F32
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ExampleTable) GetF64() uint64 {
|
||||
if x != nil {
|
||||
return x.F64
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ExampleTable) GetB() bool {
|
||||
if x != nil {
|
||||
return x.B
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *ExampleTable) GetE() Enum {
|
||||
if x != nil {
|
||||
return x.E
|
||||
}
|
||||
return Enum_ENUM_UNSPECIFIED
|
||||
}
|
||||
|
||||
func (x *ExampleTable) GetRepeated() []uint32 {
|
||||
if x != nil {
|
||||
return x.Repeated
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *ExampleTable) GetMap() map[string]uint32 {
|
||||
if x != nil {
|
||||
return x.Map
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *ExampleTable) GetMsg() *ExampleTable_ExampleMessage {
|
||||
if x != nil {
|
||||
return x.Msg
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ExampleTable) GetSum() isExampleTable_Sum {
|
||||
if m != nil {
|
||||
return m.Sum
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *ExampleTable) GetOneof() uint32 {
|
||||
if x, ok := x.GetSum().(*ExampleTable_Oneof); ok {
|
||||
return x.Oneof
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type isExampleTable_Sum interface {
|
||||
isExampleTable_Sum()
|
||||
}
|
||||
|
||||
type ExampleTable_Oneof struct {
|
||||
Oneof uint32 `protobuf:"varint,20,opt,name=oneof,proto3,oneof"`
|
||||
}
|
||||
|
||||
func (*ExampleTable_Oneof) isExampleTable_Sum() {}
|
||||
|
||||
type ExampleAutoIncrementTable struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
X string `protobuf:"bytes,2,opt,name=x,proto3" json:"x,omitempty"`
|
||||
Y int32 `protobuf:"varint,3,opt,name=y,proto3" json:"y,omitempty"`
|
||||
}
|
||||
|
||||
func (x *ExampleAutoIncrementTable) Reset() {
|
||||
*x = ExampleAutoIncrementTable{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_testpb_test_schema_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *ExampleAutoIncrementTable) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ExampleAutoIncrementTable) ProtoMessage() {}
|
||||
|
||||
func (x *ExampleAutoIncrementTable) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_testpb_test_schema_proto_msgTypes[1]
|
||||
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)
|
||||
}
|
||||
|
||||
// Deprecated: Use ExampleAutoIncrementTable.ProtoReflect.Descriptor instead.
|
||||
func (*ExampleAutoIncrementTable) Descriptor() ([]byte, []int) {
|
||||
return file_testpb_test_schema_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *ExampleAutoIncrementTable) GetId() uint64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ExampleAutoIncrementTable) GetX() string {
|
||||
if x != nil {
|
||||
return x.X
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *ExampleAutoIncrementTable) GetY() int32 {
|
||||
if x != nil {
|
||||
return x.Y
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type ExampleSingleton struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Foo string `protobuf:"bytes,1,opt,name=foo,proto3" json:"foo,omitempty"`
|
||||
Bar int32 `protobuf:"varint,2,opt,name=bar,proto3" json:"bar,omitempty"`
|
||||
}
|
||||
|
||||
func (x *ExampleSingleton) Reset() {
|
||||
*x = ExampleSingleton{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_testpb_test_schema_proto_msgTypes[2]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *ExampleSingleton) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ExampleSingleton) ProtoMessage() {}
|
||||
|
||||
func (x *ExampleSingleton) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_testpb_test_schema_proto_msgTypes[2]
|
||||
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)
|
||||
}
|
||||
|
||||
// Deprecated: Use ExampleSingleton.ProtoReflect.Descriptor instead.
|
||||
func (*ExampleSingleton) Descriptor() ([]byte, []int) {
|
||||
return file_testpb_test_schema_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
func (x *ExampleSingleton) GetFoo() string {
|
||||
if x != nil {
|
||||
return x.Foo
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *ExampleSingleton) GetBar() int32 {
|
||||
if x != nil {
|
||||
return x.Bar
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type ExampleTimestamp struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
|
||||
Ts *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=ts,proto3" json:"ts,omitempty"`
|
||||
}
|
||||
|
||||
func (x *ExampleTimestamp) Reset() {
|
||||
*x = ExampleTimestamp{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_testpb_test_schema_proto_msgTypes[3]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *ExampleTimestamp) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ExampleTimestamp) ProtoMessage() {}
|
||||
|
||||
func (x *ExampleTimestamp) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_testpb_test_schema_proto_msgTypes[3]
|
||||
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)
|
||||
}
|
||||
|
||||
// Deprecated: Use ExampleTimestamp.ProtoReflect.Descriptor instead.
|
||||
func (*ExampleTimestamp) Descriptor() ([]byte, []int) {
|
||||
return file_testpb_test_schema_proto_rawDescGZIP(), []int{3}
|
||||
}
|
||||
|
||||
func (x *ExampleTimestamp) GetId() uint64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ExampleTimestamp) GetName() string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *ExampleTimestamp) GetTs() *timestamppb.Timestamp {
|
||||
if x != nil {
|
||||
return x.Ts
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type ExampleDuration struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
|
||||
Dur *durationpb.Duration `protobuf:"bytes,3,opt,name=dur,proto3" json:"dur,omitempty"`
|
||||
}
|
||||
|
||||
func (x *ExampleDuration) Reset() {
|
||||
*x = ExampleDuration{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_testpb_test_schema_proto_msgTypes[4]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *ExampleDuration) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ExampleDuration) ProtoMessage() {}
|
||||
|
||||
func (x *ExampleDuration) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_testpb_test_schema_proto_msgTypes[4]
|
||||
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)
|
||||
}
|
||||
|
||||
// Deprecated: Use ExampleDuration.ProtoReflect.Descriptor instead.
|
||||
func (*ExampleDuration) Descriptor() ([]byte, []int) {
|
||||
return file_testpb_test_schema_proto_rawDescGZIP(), []int{4}
|
||||
}
|
||||
|
||||
func (x *ExampleDuration) GetId() uint64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ExampleDuration) GetName() string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *ExampleDuration) GetDur() *durationpb.Duration {
|
||||
if x != nil {
|
||||
return x.Dur
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type SimpleExample struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
||||
Unique string `protobuf:"bytes,2,opt,name=unique,proto3" json:"unique,omitempty"`
|
||||
NotUnique string `protobuf:"bytes,3,opt,name=not_unique,json=notUnique,proto3" json:"not_unique,omitempty"`
|
||||
}
|
||||
|
||||
func (x *SimpleExample) Reset() {
|
||||
*x = SimpleExample{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_testpb_test_schema_proto_msgTypes[5]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *SimpleExample) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*SimpleExample) ProtoMessage() {}
|
||||
|
||||
func (x *SimpleExample) ProtoReflect() 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)
|
||||
}
|
||||
|
||||
// Deprecated: Use SimpleExample.ProtoReflect.Descriptor instead.
|
||||
func (*SimpleExample) Descriptor() ([]byte, []int) {
|
||||
return file_testpb_test_schema_proto_rawDescGZIP(), []int{5}
|
||||
}
|
||||
|
||||
func (x *SimpleExample) GetName() string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *SimpleExample) GetUnique() string {
|
||||
if x != nil {
|
||||
return x.Unique
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *SimpleExample) GetNotUnique() string {
|
||||
if x != nil {
|
||||
return x.NotUnique
|
||||
}
|
||||
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[6]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *ExampleAutoIncFieldName) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ExampleAutoIncFieldName) ProtoMessage() {}
|
||||
|
||||
func (x *ExampleAutoIncFieldName) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_testpb_test_schema_proto_msgTypes[6]
|
||||
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)
|
||||
}
|
||||
|
||||
// Deprecated: Use ExampleAutoIncFieldName.ProtoReflect.Descriptor instead.
|
||||
func (*ExampleAutoIncFieldName) Descriptor() ([]byte, []int) {
|
||||
return file_testpb_test_schema_proto_rawDescGZIP(), []int{6}
|
||||
}
|
||||
|
||||
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
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Foo string `protobuf:"bytes,1,opt,name=foo,proto3" json:"foo,omitempty"`
|
||||
Bar int32 `protobuf:"varint,2,opt,name=bar,proto3" json:"bar,omitempty"`
|
||||
}
|
||||
|
||||
func (x *ExampleTable_ExampleMessage) Reset() {
|
||||
*x = ExampleTable_ExampleMessage{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_testpb_test_schema_proto_msgTypes[8]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *ExampleTable_ExampleMessage) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ExampleTable_ExampleMessage) ProtoMessage() {}
|
||||
|
||||
func (x *ExampleTable_ExampleMessage) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_testpb_test_schema_proto_msgTypes[8]
|
||||
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)
|
||||
}
|
||||
|
||||
// Deprecated: Use ExampleTable_ExampleMessage.ProtoReflect.Descriptor instead.
|
||||
func (*ExampleTable_ExampleMessage) Descriptor() ([]byte, []int) {
|
||||
return file_testpb_test_schema_proto_rawDescGZIP(), []int{0, 1}
|
||||
}
|
||||
|
||||
func (x *ExampleTable_ExampleMessage) GetFoo() string {
|
||||
if x != nil {
|
||||
return x.Foo
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *ExampleTable_ExampleMessage) GetBar() int32 {
|
||||
if x != nil {
|
||||
return x.Bar
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
var File_testpb_test_schema_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_testpb_test_schema_proto_rawDesc = []byte{
|
||||
0x0a, 0x18, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x73, 0x63,
|
||||
0x68, 0x65, 0x6d, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x74, 0x65, 0x73, 0x74,
|
||||
0x70, 0x62, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||
0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x1a, 0x17, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x6f, 0x72, 0x6d, 0x2f,
|
||||
0x76, 0x31, 0x2f, 0x6f, 0x72, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xbd, 0x05, 0x0a,
|
||||
0x0c, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x10, 0x0a,
|
||||
0x03, 0x75, 0x33, 0x32, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x03, 0x75, 0x33, 0x32, 0x12,
|
||||
0x10, 0x0a, 0x03, 0x75, 0x36, 0x34, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x75, 0x36,
|
||||
0x34, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x74, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03,
|
||||
0x73, 0x74, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x62, 0x7a, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52,
|
||||
0x02, 0x62, 0x7a, 0x12, 0x2a, 0x0a, 0x02, 0x74, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32,
|
||||
0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75,
|
||||
0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x02, 0x74, 0x73, 0x12,
|
||||
0x2b, 0x0a, 0x03, 0x64, 0x75, 0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67,
|
||||
0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44,
|
||||
0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x03, 0x64, 0x75, 0x72, 0x12, 0x10, 0x0a, 0x03,
|
||||
0x69, 0x33, 0x32, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x69, 0x33, 0x32, 0x12, 0x10,
|
||||
0x0a, 0x03, 0x73, 0x33, 0x32, 0x18, 0x08, 0x20, 0x01, 0x28, 0x11, 0x52, 0x03, 0x73, 0x33, 0x32,
|
||||
0x12, 0x12, 0x0a, 0x04, 0x73, 0x66, 0x33, 0x32, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0f, 0x52, 0x04,
|
||||
0x73, 0x66, 0x33, 0x32, 0x12, 0x10, 0x0a, 0x03, 0x69, 0x36, 0x34, 0x18, 0x0a, 0x20, 0x01, 0x28,
|
||||
0x03, 0x52, 0x03, 0x69, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x36, 0x34, 0x18, 0x0b, 0x20,
|
||||
0x01, 0x28, 0x12, 0x52, 0x03, 0x73, 0x36, 0x34, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x66, 0x36, 0x34,
|
||||
0x18, 0x0c, 0x20, 0x01, 0x28, 0x10, 0x52, 0x04, 0x73, 0x66, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03,
|
||||
0x66, 0x33, 0x32, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x07, 0x52, 0x03, 0x66, 0x33, 0x32, 0x12, 0x10,
|
||||
0x0a, 0x03, 0x66, 0x36, 0x34, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x06, 0x52, 0x03, 0x66, 0x36, 0x34,
|
||||
0x12, 0x0c, 0x0a, 0x01, 0x62, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x08, 0x52, 0x01, 0x62, 0x12, 0x1a,
|
||||
0x0a, 0x01, 0x65, 0x18, 0x10, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x74, 0x65, 0x73, 0x74,
|
||||
0x70, 0x62, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x52, 0x01, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65,
|
||||
0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x18, 0x11, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x08, 0x72, 0x65,
|
||||
0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x2f, 0x0a, 0x03, 0x6d, 0x61, 0x70, 0x18, 0x12, 0x20,
|
||||
0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x45, 0x78, 0x61,
|
||||
0x6d, 0x70, 0x6c, 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74,
|
||||
0x72, 0x79, 0x52, 0x03, 0x6d, 0x61, 0x70, 0x12, 0x35, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x13,
|
||||
0x20, 0x01, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x45, 0x78,
|
||||
0x61, 0x6d, 0x70, 0x6c, 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x45, 0x78, 0x61, 0x6d, 0x70,
|
||||
0x6c, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x12, 0x16,
|
||||
0x0a, 0x05, 0x6f, 0x6e, 0x65, 0x6f, 0x66, 0x18, 0x14, 0x20, 0x01, 0x28, 0x0d, 0x48, 0x00, 0x52,
|
||||
0x05, 0x6f, 0x6e, 0x65, 0x6f, 0x66, 0x1a, 0x36, 0x0a, 0x08, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74,
|
||||
0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20,
|
||||
0x01, 0x28, 0x0d, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x34,
|
||||
0x0a, 0x0e, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
|
||||
0x12, 0x10, 0x0a, 0x03, 0x66, 0x6f, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x66,
|
||||
0x6f, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x61, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52,
|
||||
0x03, 0x62, 0x61, 0x72, 0x3a, 0x3f, 0xf2, 0x9e, 0xd3, 0x8e, 0x03, 0x39, 0x0a, 0x0d, 0x0a, 0x0b,
|
||||
0x75, 0x33, 0x32, 0x2c, 0x69, 0x36, 0x34, 0x2c, 0x73, 0x74, 0x72, 0x12, 0x0d, 0x0a, 0x07, 0x75,
|
||||
0x36, 0x34, 0x2c, 0x73, 0x74, 0x72, 0x10, 0x01, 0x18, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x73, 0x74,
|
||||
0x72, 0x2c, 0x75, 0x33, 0x32, 0x10, 0x02, 0x12, 0x0a, 0x0a, 0x06, 0x62, 0x7a, 0x2c, 0x73, 0x74,
|
||||
0x72, 0x10, 0x03, 0x18, 0x01, 0x42, 0x05, 0x0a, 0x03, 0x73, 0x75, 0x6d, 0x22, 0x62, 0x0a, 0x19,
|
||||
0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x41, 0x75, 0x74, 0x6f, 0x49, 0x6e, 0x63, 0x72, 0x65,
|
||||
0x6d, 0x65, 0x6e, 0x74, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18,
|
||||
0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x02, 0x69, 0x64, 0x12, 0x0c, 0x0a, 0x01, 0x78, 0x18, 0x02,
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x01, 0x78, 0x12, 0x0c, 0x0a, 0x01, 0x79, 0x18, 0x03, 0x20, 0x01,
|
||||
0x28, 0x05, 0x52, 0x01, 0x79, 0x3a, 0x19, 0xf2, 0x9e, 0xd3, 0x8e, 0x03, 0x13, 0x0a, 0x06, 0x0a,
|
||||
0x02, 0x69, 0x64, 0x10, 0x01, 0x12, 0x07, 0x0a, 0x01, 0x78, 0x10, 0x01, 0x18, 0x01, 0x18, 0x03,
|
||||
0x22, 0x40, 0x0a, 0x10, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x53, 0x69, 0x6e, 0x67, 0x6c,
|
||||
0x65, 0x74, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x66, 0x6f, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x61, 0x72, 0x18, 0x02, 0x20,
|
||||
0x01, 0x28, 0x05, 0x52, 0x03, 0x62, 0x61, 0x72, 0x3a, 0x08, 0xfa, 0x9e, 0xd3, 0x8e, 0x03, 0x02,
|
||||
0x08, 0x02, 0x22, 0x7c, 0x0a, 0x10, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x54, 0x69, 0x6d,
|
||||
0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01,
|
||||
0x28, 0x04, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02,
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2a, 0x0a, 0x02, 0x74, 0x73,
|
||||
0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61,
|
||||
0x6d, 0x70, 0x52, 0x02, 0x74, 0x73, 0x3a, 0x18, 0xf2, 0x9e, 0xd3, 0x8e, 0x03, 0x12, 0x0a, 0x06,
|
||||
0x0a, 0x02, 0x69, 0x64, 0x10, 0x01, 0x12, 0x06, 0x0a, 0x02, 0x74, 0x73, 0x10, 0x01, 0x18, 0x04,
|
||||
0x22, 0x7d, 0x0a, 0x0f, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x44, 0x75, 0x72, 0x61, 0x74,
|
||||
0x69, 0x6f, 0x6e, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52,
|
||||
0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2b, 0x0a, 0x03, 0x64, 0x75, 0x72, 0x18, 0x03,
|
||||
0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52,
|
||||
0x03, 0x64, 0x75, 0x72, 0x3a, 0x19, 0xf2, 0x9e, 0xd3, 0x8e, 0x03, 0x13, 0x0a, 0x06, 0x0a, 0x02,
|
||||
0x69, 0x64, 0x10, 0x01, 0x12, 0x07, 0x0a, 0x03, 0x64, 0x75, 0x72, 0x10, 0x01, 0x18, 0x04, 0x22,
|
||||
0x7a, 0x0a, 0x0d, 0x53, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65,
|
||||
0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
|
||||
0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x18, 0x02,
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x12, 0x1d, 0x0a, 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, 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, 0x77, 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, 0x20, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e,
|
||||
0x69, 0x6f, 0x2f, 0x6f, 0x72, 0x6d, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f,
|
||||
0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0xa2, 0x02, 0x03, 0x54, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x54,
|
||||
0x65, 0x73, 0x74, 0x70, 0x62, 0xca, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xe2, 0x02,
|
||||
0x12, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64,
|
||||
0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_testpb_test_schema_proto_rawDescOnce sync.Once
|
||||
file_testpb_test_schema_proto_rawDescData = file_testpb_test_schema_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_testpb_test_schema_proto_rawDescGZIP() []byte {
|
||||
file_testpb_test_schema_proto_rawDescOnce.Do(func() {
|
||||
file_testpb_test_schema_proto_rawDescData = protoimpl.X.CompressGZIP(file_testpb_test_schema_proto_rawDescData)
|
||||
})
|
||||
return file_testpb_test_schema_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_testpb_test_schema_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
||||
var file_testpb_test_schema_proto_msgTypes = make([]protoimpl.MessageInfo, 9)
|
||||
var file_testpb_test_schema_proto_goTypes = []interface{}{
|
||||
(Enum)(0), // 0: testpb.Enum
|
||||
(*ExampleTable)(nil), // 1: testpb.ExampleTable
|
||||
(*ExampleAutoIncrementTable)(nil), // 2: testpb.ExampleAutoIncrementTable
|
||||
(*ExampleSingleton)(nil), // 3: testpb.ExampleSingleton
|
||||
(*ExampleTimestamp)(nil), // 4: testpb.ExampleTimestamp
|
||||
(*ExampleDuration)(nil), // 5: testpb.ExampleDuration
|
||||
(*SimpleExample)(nil), // 6: testpb.SimpleExample
|
||||
(*ExampleAutoIncFieldName)(nil), // 7: testpb.ExampleAutoIncFieldName
|
||||
nil, // 8: testpb.ExampleTable.MapEntry
|
||||
(*ExampleTable_ExampleMessage)(nil), // 9: testpb.ExampleTable.ExampleMessage
|
||||
(*timestamppb.Timestamp)(nil), // 10: google.protobuf.Timestamp
|
||||
(*durationpb.Duration)(nil), // 11: google.protobuf.Duration
|
||||
}
|
||||
var file_testpb_test_schema_proto_depIdxs = []int32{
|
||||
10, // 0: testpb.ExampleTable.ts:type_name -> google.protobuf.Timestamp
|
||||
11, // 1: testpb.ExampleTable.dur:type_name -> google.protobuf.Duration
|
||||
0, // 2: testpb.ExampleTable.e:type_name -> testpb.Enum
|
||||
8, // 3: testpb.ExampleTable.map:type_name -> testpb.ExampleTable.MapEntry
|
||||
9, // 4: testpb.ExampleTable.msg:type_name -> testpb.ExampleTable.ExampleMessage
|
||||
10, // 5: testpb.ExampleTimestamp.ts:type_name -> google.protobuf.Timestamp
|
||||
11, // 6: testpb.ExampleDuration.dur:type_name -> google.protobuf.Duration
|
||||
7, // [7:7] is the sub-list for method output_type
|
||||
7, // [7:7] is the sub-list for method input_type
|
||||
7, // [7:7] is the sub-list for extension type_name
|
||||
7, // [7:7] is the sub-list for extension extendee
|
||||
0, // [0:7] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_testpb_test_schema_proto_init() }
|
||||
func file_testpb_test_schema_proto_init() {
|
||||
if File_testpb_test_schema_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_testpb_test_schema_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ExampleTable); 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[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ExampleAutoIncrementTable); 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[2].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ExampleSingleton); 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[3].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ExampleTimestamp); 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[4].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ExampleDuration); 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[5].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*SimpleExample); 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[6].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[8].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ExampleTable_ExampleMessage); 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[0].OneofWrappers = []interface{}{
|
||||
(*ExampleTable_Oneof)(nil),
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_testpb_test_schema_proto_rawDesc,
|
||||
NumEnums: 1,
|
||||
NumMessages: 9,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
GoTypes: file_testpb_test_schema_proto_goTypes,
|
||||
DependencyIndexes: file_testpb_test_schema_proto_depIdxs,
|
||||
EnumInfos: file_testpb_test_schema_proto_enumTypes,
|
||||
MessageInfos: file_testpb_test_schema_proto_msgTypes,
|
||||
}.Build()
|
||||
File_testpb_test_schema_proto = out.File
|
||||
file_testpb_test_schema_proto_rawDesc = nil
|
||||
file_testpb_test_schema_proto_goTypes = nil
|
||||
file_testpb_test_schema_proto_depIdxs = nil
|
||||
}
|
||||
@ -1,142 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package testpb;
|
||||
|
||||
import "google/protobuf/timestamp.proto";
|
||||
import "google/protobuf/duration.proto";
|
||||
import "cosmos/orm/v1/orm.proto";
|
||||
|
||||
message ExampleTable {
|
||||
// clang-format off
|
||||
option (cosmos.orm.v1.table) = {
|
||||
id: 1;
|
||||
primary_key: {
|
||||
fields:
|
||||
"u32,i64,str"
|
||||
}
|
||||
index: {
|
||||
id:
|
||||
1;
|
||||
fields:
|
||||
"u64,str" unique: true
|
||||
}
|
||||
index: {
|
||||
id:
|
||||
2;
|
||||
fields:
|
||||
"str,u32"
|
||||
}
|
||||
index: {
|
||||
id:
|
||||
3;
|
||||
fields:
|
||||
"bz,str"
|
||||
}
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
// Valid key fields:
|
||||
uint32 u32 = 1;
|
||||
uint64 u64 = 2;
|
||||
string str = 3;
|
||||
bytes bz = 4;
|
||||
google.protobuf.Timestamp ts = 5;
|
||||
google.protobuf.Duration dur = 6;
|
||||
int32 i32 = 7;
|
||||
sint32 s32 = 8;
|
||||
sfixed32 sf32 = 9;
|
||||
int64 i64 = 10;
|
||||
sint64 s64 = 11;
|
||||
sfixed64 sf64 = 12;
|
||||
fixed32 f32 = 13;
|
||||
fixed64 f64 = 14;
|
||||
bool b = 15;
|
||||
Enum e = 16;
|
||||
|
||||
// Invalid key fields:
|
||||
repeated uint32 repeated = 17;
|
||||
map<string, uint32> map = 18;
|
||||
ExampleMessage msg = 19;
|
||||
oneof sum {
|
||||
uint32 oneof = 20;
|
||||
}
|
||||
|
||||
message ExampleMessage {
|
||||
string foo = 1;
|
||||
int32 bar = 2;
|
||||
}
|
||||
}
|
||||
|
||||
enum Enum {
|
||||
ENUM_UNSPECIFIED = 0;
|
||||
ENUM_ONE = 1;
|
||||
ENUM_TWO = 2;
|
||||
ENUM_FIVE = 5;
|
||||
ENUM_NEG_THREE = -3;
|
||||
}
|
||||
|
||||
message ExampleAutoIncrementTable {
|
||||
option (cosmos.orm.v1.table) = {
|
||||
id: 3
|
||||
primary_key: {fields: "id" auto_increment: true}
|
||||
index: {id: 1 fields: "x" unique: true}
|
||||
};
|
||||
|
||||
uint64 id = 1;
|
||||
string x = 2;
|
||||
int32 y = 3;
|
||||
}
|
||||
|
||||
message ExampleSingleton {
|
||||
option (cosmos.orm.v1.singleton) = {
|
||||
id: 2
|
||||
};
|
||||
string foo = 1;
|
||||
int32 bar = 2;
|
||||
}
|
||||
|
||||
message ExampleTimestamp {
|
||||
option (cosmos.orm.v1.table) = {
|
||||
id: 4
|
||||
primary_key: {fields: "id" auto_increment: true}
|
||||
index: {id: 1 fields: "ts"}
|
||||
};
|
||||
|
||||
uint64 id = 1;
|
||||
string name = 2;
|
||||
google.protobuf.Timestamp ts = 3;
|
||||
}
|
||||
|
||||
message ExampleDuration {
|
||||
option (cosmos.orm.v1.table) = {
|
||||
id: 4
|
||||
primary_key: {fields: "id" auto_increment: true}
|
||||
index: {id: 1 fields: "dur"}
|
||||
};
|
||||
|
||||
uint64 id = 1;
|
||||
string name = 2;
|
||||
google.protobuf.Duration dur = 3;
|
||||
}
|
||||
|
||||
message SimpleExample {
|
||||
option (cosmos.orm.v1.table) = {
|
||||
id: 5
|
||||
primary_key: {fields: "name"}
|
||||
index: {id: 1, fields: "unique", unique: true}
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,517 +0,0 @@
|
||||
// Code generated by protoc-gen-go-cosmos-orm-proto. DO NOT EDIT.
|
||||
syntax = "proto3";
|
||||
package testpb;
|
||||
|
||||
import "cosmos/base/query/v1beta1/pagination.proto";
|
||||
import "google/protobuf/duration.proto";
|
||||
import "google/protobuf/timestamp.proto";
|
||||
import "testpb/test_schema.proto";
|
||||
|
||||
// TestSchemaQueryService queries the state of the tables specified by testpb/test_schema.proto.
|
||||
service TestSchemaQueryService {
|
||||
// Get queries the ExampleTable table by its primary key.
|
||||
rpc GetExampleTable(GetExampleTableRequest) returns (GetExampleTableResponse) {}
|
||||
// GetExampleTableByU64Str queries the ExampleTable table by its U64Str index
|
||||
rpc GetExampleTableByU64Str(GetExampleTableByU64StrRequest) returns (GetExampleTableByU64StrResponse) {}
|
||||
// ListExampleTable queries the ExampleTable table using prefix and range queries against defined indexes.
|
||||
rpc ListExampleTable(ListExampleTableRequest) returns (ListExampleTableResponse) {}
|
||||
// Get queries the ExampleAutoIncrementTable table by its primary key.
|
||||
rpc GetExampleAutoIncrementTable(GetExampleAutoIncrementTableRequest) returns (GetExampleAutoIncrementTableResponse) {
|
||||
}
|
||||
// GetExampleAutoIncrementTableByX queries the ExampleAutoIncrementTable table by its X index
|
||||
rpc GetExampleAutoIncrementTableByX(GetExampleAutoIncrementTableByXRequest)
|
||||
returns (GetExampleAutoIncrementTableByXResponse) {}
|
||||
// ListExampleAutoIncrementTable queries the ExampleAutoIncrementTable table using prefix and range queries against
|
||||
// defined indexes.
|
||||
rpc ListExampleAutoIncrementTable(ListExampleAutoIncrementTableRequest)
|
||||
returns (ListExampleAutoIncrementTableResponse) {}
|
||||
// GetExampleSingleton queries the ExampleSingleton singleton.
|
||||
rpc GetExampleSingleton(GetExampleSingletonRequest) returns (GetExampleSingletonResponse) {}
|
||||
// Get queries the ExampleTimestamp table by its primary key.
|
||||
rpc GetExampleTimestamp(GetExampleTimestampRequest) returns (GetExampleTimestampResponse) {}
|
||||
// ListExampleTimestamp queries the ExampleTimestamp table using prefix and range queries against defined indexes.
|
||||
rpc ListExampleTimestamp(ListExampleTimestampRequest) returns (ListExampleTimestampResponse) {}
|
||||
// Get queries the ExampleDuration table by its primary key.
|
||||
rpc GetExampleDuration(GetExampleDurationRequest) returns (GetExampleDurationResponse) {}
|
||||
// ListExampleDuration queries the ExampleDuration table using prefix and range queries against defined indexes.
|
||||
rpc ListExampleDuration(ListExampleDurationRequest) returns (ListExampleDurationResponse) {}
|
||||
// Get queries the SimpleExample table by its primary key.
|
||||
rpc GetSimpleExample(GetSimpleExampleRequest) returns (GetSimpleExampleResponse) {}
|
||||
// GetSimpleExampleByUnique queries the SimpleExample table by its Unique index
|
||||
rpc GetSimpleExampleByUnique(GetSimpleExampleByUniqueRequest) returns (GetSimpleExampleByUniqueResponse) {}
|
||||
// ListSimpleExample queries the SimpleExample table using prefix and range queries against defined indexes.
|
||||
rpc ListSimpleExample(ListSimpleExampleRequest) returns (ListSimpleExampleResponse) {}
|
||||
// Get queries the ExampleAutoIncFieldName table by its primary key.
|
||||
rpc GetExampleAutoIncFieldName(GetExampleAutoIncFieldNameRequest) returns (GetExampleAutoIncFieldNameResponse) {}
|
||||
// ListExampleAutoIncFieldName queries the ExampleAutoIncFieldName table using prefix and range queries against
|
||||
// defined indexes.
|
||||
rpc ListExampleAutoIncFieldName(ListExampleAutoIncFieldNameRequest) returns (ListExampleAutoIncFieldNameResponse) {}
|
||||
}
|
||||
|
||||
// GetExampleTableRequest is the TestSchemaQuery/GetExampleTableRequest request type.
|
||||
message GetExampleTableRequest {
|
||||
// u32 specifies the value of the u32 field in the primary key.
|
||||
uint32 u32 = 1;
|
||||
// i64 specifies the value of the i64 field in the primary key.
|
||||
int64 i64 = 2;
|
||||
// str specifies the value of the str field in the primary key.
|
||||
string str = 3;
|
||||
}
|
||||
|
||||
// GetExampleTableResponse is the TestSchemaQuery/GetExampleTableResponse response type.
|
||||
message GetExampleTableResponse {
|
||||
// value is the response value.
|
||||
ExampleTable value = 1;
|
||||
}
|
||||
|
||||
// GetExampleTableByU64StrRequest is the TestSchemaQuery/GetExampleTableByU64StrRequest request type.
|
||||
message GetExampleTableByU64StrRequest {
|
||||
uint64 u64 = 1;
|
||||
string str = 2;
|
||||
}
|
||||
|
||||
// GetExampleTableByU64StrResponse is the TestSchemaQuery/GetExampleTableByU64StrResponse response type.
|
||||
message GetExampleTableByU64StrResponse {
|
||||
ExampleTable value = 1;
|
||||
}
|
||||
|
||||
// ListExampleTableRequest is the TestSchemaQuery/ListExampleTableRequest request type.
|
||||
message ListExampleTableRequest {
|
||||
// IndexKey specifies the value of an index key to use in prefix and range queries.
|
||||
message IndexKey {
|
||||
// key specifies the index key value.
|
||||
oneof key {
|
||||
// u_32_i_64_str specifies the value of the U32I64Str index key to use in the query.
|
||||
U32I64Str u_32_i_64_str = 1;
|
||||
// u_64_str specifies the value of the U64Str index key to use in the query.
|
||||
U64Str u_64_str = 2;
|
||||
// str_u_32 specifies the value of the StrU32 index key to use in the query.
|
||||
StrU32 str_u_32 = 3;
|
||||
// bz_str specifies the value of the BzStr index key to use in the query.
|
||||
BzStr bz_str = 4;
|
||||
}
|
||||
|
||||
message U32I64Str {
|
||||
// u32 is the value of the u32 field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional uint32 u32 = 1;
|
||||
// i64 is the value of the i64 field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional int64 i64 = 2;
|
||||
// str is the value of the str field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional string str = 3;
|
||||
}
|
||||
|
||||
message U64Str {
|
||||
// u64 is the value of the u64 field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional uint64 u64 = 1;
|
||||
// str is the value of the str field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional string str = 2;
|
||||
}
|
||||
|
||||
message StrU32 {
|
||||
// str is the value of the str field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional string str = 1;
|
||||
// u32 is the value of the u32 field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional uint32 u32 = 2;
|
||||
}
|
||||
|
||||
message BzStr {
|
||||
// bz is the value of the bz field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional bytes bz = 1;
|
||||
// str is the value of the str field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional string str = 2;
|
||||
}
|
||||
}
|
||||
|
||||
// query specifies the type of query - either a prefix or range query.
|
||||
oneof query {
|
||||
// prefix_query specifies the index key value to use for the prefix query.
|
||||
IndexKey prefix_query = 1;
|
||||
// range_query specifies the index key from/to values to use for the range query.
|
||||
RangeQuery range_query = 2;
|
||||
}
|
||||
// pagination specifies optional pagination parameters.
|
||||
cosmos.base.query.v1beta1.PageRequest pagination = 3;
|
||||
|
||||
// RangeQuery specifies the from/to index keys for a range query.
|
||||
message RangeQuery {
|
||||
// from is the index key to use for the start of the range query.
|
||||
// To query from the start of an index, specify an index key for that index with empty values.
|
||||
IndexKey from = 1;
|
||||
// to is the index key to use for the end of the range query.
|
||||
// The index key type MUST be the same as the index key type used for from.
|
||||
// To query from to the end of an index it can be omitted.
|
||||
IndexKey to = 2;
|
||||
}
|
||||
}
|
||||
|
||||
// ListExampleTableResponse is the TestSchemaQuery/ListExampleTableResponse response type.
|
||||
message ListExampleTableResponse {
|
||||
// values are the results of the query.
|
||||
repeated ExampleTable values = 1;
|
||||
// pagination is the pagination response.
|
||||
cosmos.base.query.v1beta1.PageResponse pagination = 2;
|
||||
}
|
||||
|
||||
// GetExampleAutoIncrementTableRequest is the TestSchemaQuery/GetExampleAutoIncrementTableRequest request type.
|
||||
message GetExampleAutoIncrementTableRequest {
|
||||
// id specifies the value of the id field in the primary key.
|
||||
uint64 id = 1;
|
||||
}
|
||||
|
||||
// GetExampleAutoIncrementTableResponse is the TestSchemaQuery/GetExampleAutoIncrementTableResponse response type.
|
||||
message GetExampleAutoIncrementTableResponse {
|
||||
// value is the response value.
|
||||
ExampleAutoIncrementTable value = 1;
|
||||
}
|
||||
|
||||
// GetExampleAutoIncrementTableByXRequest is the TestSchemaQuery/GetExampleAutoIncrementTableByXRequest request type.
|
||||
message GetExampleAutoIncrementTableByXRequest {
|
||||
string x = 1;
|
||||
}
|
||||
|
||||
// GetExampleAutoIncrementTableByXResponse is the TestSchemaQuery/GetExampleAutoIncrementTableByXResponse response type.
|
||||
message GetExampleAutoIncrementTableByXResponse {
|
||||
ExampleAutoIncrementTable value = 1;
|
||||
}
|
||||
|
||||
// ListExampleAutoIncrementTableRequest is the TestSchemaQuery/ListExampleAutoIncrementTableRequest request type.
|
||||
message ListExampleAutoIncrementTableRequest {
|
||||
// IndexKey specifies the value of an index key to use in prefix and range queries.
|
||||
message IndexKey {
|
||||
// key specifies the index key value.
|
||||
oneof key {
|
||||
// id specifies the value of the Id index key to use in the query.
|
||||
Id id = 1;
|
||||
// x specifies the value of the X index key to use in the query.
|
||||
X x = 2;
|
||||
}
|
||||
|
||||
message Id {
|
||||
// id is the value of the id field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional uint64 id = 1;
|
||||
}
|
||||
|
||||
message X {
|
||||
// x is the value of the x field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional string x = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// query specifies the type of query - either a prefix or range query.
|
||||
oneof query {
|
||||
// prefix_query specifies the index key value to use for the prefix query.
|
||||
IndexKey prefix_query = 1;
|
||||
// range_query specifies the index key from/to values to use for the range query.
|
||||
RangeQuery range_query = 2;
|
||||
}
|
||||
// pagination specifies optional pagination parameters.
|
||||
cosmos.base.query.v1beta1.PageRequest pagination = 3;
|
||||
|
||||
// RangeQuery specifies the from/to index keys for a range query.
|
||||
message RangeQuery {
|
||||
// from is the index key to use for the start of the range query.
|
||||
// To query from the start of an index, specify an index key for that index with empty values.
|
||||
IndexKey from = 1;
|
||||
// to is the index key to use for the end of the range query.
|
||||
// The index key type MUST be the same as the index key type used for from.
|
||||
// To query from to the end of an index it can be omitted.
|
||||
IndexKey to = 2;
|
||||
}
|
||||
}
|
||||
|
||||
// ListExampleAutoIncrementTableResponse is the TestSchemaQuery/ListExampleAutoIncrementTableResponse response type.
|
||||
message ListExampleAutoIncrementTableResponse {
|
||||
// values are the results of the query.
|
||||
repeated ExampleAutoIncrementTable values = 1;
|
||||
// pagination is the pagination response.
|
||||
cosmos.base.query.v1beta1.PageResponse pagination = 2;
|
||||
}
|
||||
|
||||
// GetExampleSingletonRequest is the TestSchemaQuery/GetExampleSingletonRequest request type.
|
||||
message GetExampleSingletonRequest {}
|
||||
|
||||
// GetExampleSingletonResponse is the TestSchemaQuery/GetExampleSingletonResponse request type.
|
||||
message GetExampleSingletonResponse {
|
||||
ExampleSingleton value = 1;
|
||||
}
|
||||
|
||||
// GetExampleTimestampRequest is the TestSchemaQuery/GetExampleTimestampRequest request type.
|
||||
message GetExampleTimestampRequest {
|
||||
// id specifies the value of the id field in the primary key.
|
||||
uint64 id = 1;
|
||||
}
|
||||
|
||||
// GetExampleTimestampResponse is the TestSchemaQuery/GetExampleTimestampResponse response type.
|
||||
message GetExampleTimestampResponse {
|
||||
// value is the response value.
|
||||
ExampleTimestamp value = 1;
|
||||
}
|
||||
|
||||
// ListExampleTimestampRequest is the TestSchemaQuery/ListExampleTimestampRequest request type.
|
||||
message ListExampleTimestampRequest {
|
||||
// IndexKey specifies the value of an index key to use in prefix and range queries.
|
||||
message IndexKey {
|
||||
// key specifies the index key value.
|
||||
oneof key {
|
||||
// id specifies the value of the Id index key to use in the query.
|
||||
Id id = 1;
|
||||
// ts specifies the value of the Ts index key to use in the query.
|
||||
Ts ts = 2;
|
||||
}
|
||||
|
||||
message Id {
|
||||
// id is the value of the id field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional uint64 id = 1;
|
||||
}
|
||||
|
||||
message Ts {
|
||||
// ts is the value of the ts field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional google.protobuf.Timestamp ts = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// query specifies the type of query - either a prefix or range query.
|
||||
oneof query {
|
||||
// prefix_query specifies the index key value to use for the prefix query.
|
||||
IndexKey prefix_query = 1;
|
||||
// range_query specifies the index key from/to values to use for the range query.
|
||||
RangeQuery range_query = 2;
|
||||
}
|
||||
// pagination specifies optional pagination parameters.
|
||||
cosmos.base.query.v1beta1.PageRequest pagination = 3;
|
||||
|
||||
// RangeQuery specifies the from/to index keys for a range query.
|
||||
message RangeQuery {
|
||||
// from is the index key to use for the start of the range query.
|
||||
// To query from the start of an index, specify an index key for that index with empty values.
|
||||
IndexKey from = 1;
|
||||
// to is the index key to use for the end of the range query.
|
||||
// The index key type MUST be the same as the index key type used for from.
|
||||
// To query from to the end of an index it can be omitted.
|
||||
IndexKey to = 2;
|
||||
}
|
||||
}
|
||||
|
||||
// ListExampleTimestampResponse is the TestSchemaQuery/ListExampleTimestampResponse response type.
|
||||
message ListExampleTimestampResponse {
|
||||
// values are the results of the query.
|
||||
repeated ExampleTimestamp values = 1;
|
||||
// pagination is the pagination response.
|
||||
cosmos.base.query.v1beta1.PageResponse pagination = 2;
|
||||
}
|
||||
|
||||
// GetExampleDurationRequest is the TestSchemaQuery/GetExampleDurationRequest request type.
|
||||
message GetExampleDurationRequest {
|
||||
// id specifies the value of the id field in the primary key.
|
||||
uint64 id = 1;
|
||||
}
|
||||
|
||||
// GetExampleDurationResponse is the TestSchemaQuery/GetExampleDurationResponse response type.
|
||||
message GetExampleDurationResponse {
|
||||
// value is the response value.
|
||||
ExampleDuration value = 1;
|
||||
}
|
||||
|
||||
// ListExampleDurationRequest is the TestSchemaQuery/ListExampleDurationRequest request type.
|
||||
message ListExampleDurationRequest {
|
||||
// IndexKey specifies the value of an index key to use in prefix and range queries.
|
||||
message IndexKey {
|
||||
// key specifies the index key value.
|
||||
oneof key {
|
||||
// id specifies the value of the Id index key to use in the query.
|
||||
Id id = 1;
|
||||
// dur specifies the value of the Dur index key to use in the query.
|
||||
Dur dur = 2;
|
||||
}
|
||||
|
||||
message Id {
|
||||
// id is the value of the id field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional uint64 id = 1;
|
||||
}
|
||||
|
||||
message Dur {
|
||||
// dur is the value of the dur field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional google.protobuf.Duration dur = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// query specifies the type of query - either a prefix or range query.
|
||||
oneof query {
|
||||
// prefix_query specifies the index key value to use for the prefix query.
|
||||
IndexKey prefix_query = 1;
|
||||
// range_query specifies the index key from/to values to use for the range query.
|
||||
RangeQuery range_query = 2;
|
||||
}
|
||||
// pagination specifies optional pagination parameters.
|
||||
cosmos.base.query.v1beta1.PageRequest pagination = 3;
|
||||
|
||||
// RangeQuery specifies the from/to index keys for a range query.
|
||||
message RangeQuery {
|
||||
// from is the index key to use for the start of the range query.
|
||||
// To query from the start of an index, specify an index key for that index with empty values.
|
||||
IndexKey from = 1;
|
||||
// to is the index key to use for the end of the range query.
|
||||
// The index key type MUST be the same as the index key type used for from.
|
||||
// To query from to the end of an index it can be omitted.
|
||||
IndexKey to = 2;
|
||||
}
|
||||
}
|
||||
|
||||
// ListExampleDurationResponse is the TestSchemaQuery/ListExampleDurationResponse response type.
|
||||
message ListExampleDurationResponse {
|
||||
// values are the results of the query.
|
||||
repeated ExampleDuration values = 1;
|
||||
// pagination is the pagination response.
|
||||
cosmos.base.query.v1beta1.PageResponse pagination = 2;
|
||||
}
|
||||
|
||||
// GetSimpleExampleRequest is the TestSchemaQuery/GetSimpleExampleRequest request type.
|
||||
message GetSimpleExampleRequest {
|
||||
// name specifies the value of the name field in the primary key.
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
// GetSimpleExampleResponse is the TestSchemaQuery/GetSimpleExampleResponse response type.
|
||||
message GetSimpleExampleResponse {
|
||||
// value is the response value.
|
||||
SimpleExample value = 1;
|
||||
}
|
||||
|
||||
// GetSimpleExampleByUniqueRequest is the TestSchemaQuery/GetSimpleExampleByUniqueRequest request type.
|
||||
message GetSimpleExampleByUniqueRequest {
|
||||
string unique = 1;
|
||||
}
|
||||
|
||||
// GetSimpleExampleByUniqueResponse is the TestSchemaQuery/GetSimpleExampleByUniqueResponse response type.
|
||||
message GetSimpleExampleByUniqueResponse {
|
||||
SimpleExample value = 1;
|
||||
}
|
||||
|
||||
// ListSimpleExampleRequest is the TestSchemaQuery/ListSimpleExampleRequest request type.
|
||||
message ListSimpleExampleRequest {
|
||||
// IndexKey specifies the value of an index key to use in prefix and range queries.
|
||||
message IndexKey {
|
||||
// key specifies the index key value.
|
||||
oneof key {
|
||||
// name specifies the value of the Name index key to use in the query.
|
||||
Name name = 1;
|
||||
// unique specifies the value of the Unique index key to use in the query.
|
||||
Unique unique = 2;
|
||||
}
|
||||
|
||||
message Name {
|
||||
// name is the value of the name field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional string name = 1;
|
||||
}
|
||||
|
||||
message Unique {
|
||||
// unique is the value of the unique field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional string unique = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// query specifies the type of query - either a prefix or range query.
|
||||
oneof query {
|
||||
// prefix_query specifies the index key value to use for the prefix query.
|
||||
IndexKey prefix_query = 1;
|
||||
// range_query specifies the index key from/to values to use for the range query.
|
||||
RangeQuery range_query = 2;
|
||||
}
|
||||
// pagination specifies optional pagination parameters.
|
||||
cosmos.base.query.v1beta1.PageRequest pagination = 3;
|
||||
|
||||
// RangeQuery specifies the from/to index keys for a range query.
|
||||
message RangeQuery {
|
||||
// from is the index key to use for the start of the range query.
|
||||
// To query from the start of an index, specify an index key for that index with empty values.
|
||||
IndexKey from = 1;
|
||||
// to is the index key to use for the end of the range query.
|
||||
// The index key type MUST be the same as the index key type used for from.
|
||||
// To query from to the end of an index it can be omitted.
|
||||
IndexKey to = 2;
|
||||
}
|
||||
}
|
||||
|
||||
// ListSimpleExampleResponse is the TestSchemaQuery/ListSimpleExampleResponse response type.
|
||||
message ListSimpleExampleResponse {
|
||||
// values are the results of the query.
|
||||
repeated SimpleExample values = 1;
|
||||
// pagination is the pagination response.
|
||||
cosmos.base.query.v1beta1.PageResponse pagination = 2;
|
||||
}
|
||||
|
||||
// GetExampleAutoIncFieldNameRequest is the TestSchemaQuery/GetExampleAutoIncFieldNameRequest request type.
|
||||
message GetExampleAutoIncFieldNameRequest {
|
||||
// foo specifies the value of the foo field in the primary key.
|
||||
uint64 foo = 1;
|
||||
}
|
||||
|
||||
// GetExampleAutoIncFieldNameResponse is the TestSchemaQuery/GetExampleAutoIncFieldNameResponse response type.
|
||||
message GetExampleAutoIncFieldNameResponse {
|
||||
// value is the response value.
|
||||
ExampleAutoIncFieldName value = 1;
|
||||
}
|
||||
|
||||
// ListExampleAutoIncFieldNameRequest is the TestSchemaQuery/ListExampleAutoIncFieldNameRequest request type.
|
||||
message ListExampleAutoIncFieldNameRequest {
|
||||
// IndexKey specifies the value of an index key to use in prefix and range queries.
|
||||
message IndexKey {
|
||||
// key specifies the index key value.
|
||||
oneof key {
|
||||
// foo specifies the value of the Foo index key to use in the query.
|
||||
Foo foo = 1;
|
||||
}
|
||||
|
||||
message Foo {
|
||||
// foo is the value of the foo field in the index.
|
||||
// It can be omitted to query for all valid values of that field in this segment of the index.
|
||||
optional uint64 foo = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// query specifies the type of query - either a prefix or range query.
|
||||
oneof query {
|
||||
// prefix_query specifies the index key value to use for the prefix query.
|
||||
IndexKey prefix_query = 1;
|
||||
// range_query specifies the index key from/to values to use for the range query.
|
||||
RangeQuery range_query = 2;
|
||||
}
|
||||
// pagination specifies optional pagination parameters.
|
||||
cosmos.base.query.v1beta1.PageRequest pagination = 3;
|
||||
|
||||
// RangeQuery specifies the from/to index keys for a range query.
|
||||
message RangeQuery {
|
||||
// from is the index key to use for the start of the range query.
|
||||
// To query from the start of an index, specify an index key for that index with empty values.
|
||||
IndexKey from = 1;
|
||||
// to is the index key to use for the end of the range query.
|
||||
// The index key type MUST be the same as the index key type used for from.
|
||||
// To query from to the end of an index it can be omitted.
|
||||
IndexKey to = 2;
|
||||
}
|
||||
}
|
||||
|
||||
// ListExampleAutoIncFieldNameResponse is the TestSchemaQuery/ListExampleAutoIncFieldNameResponse response type.
|
||||
message ListExampleAutoIncFieldNameResponse {
|
||||
// values are the results of the query.
|
||||
repeated ExampleAutoIncFieldName values = 1;
|
||||
// pagination is the pagination response.
|
||||
cosmos.base.query.v1beta1.PageResponse pagination = 2;
|
||||
}
|
||||
@ -1,699 +0,0 @@
|
||||
// Code generated by protoc-gen-go-cosmos-orm-proto. DO NOT EDIT.
|
||||
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.3.0
|
||||
// - protoc (unknown)
|
||||
// source: testpb/test_schema_query.proto
|
||||
|
||||
package testpb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
// Requires gRPC-Go v1.32.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion7
|
||||
|
||||
const (
|
||||
TestSchemaQueryService_GetExampleTable_FullMethodName = "/testpb.TestSchemaQueryService/GetExampleTable"
|
||||
TestSchemaQueryService_GetExampleTableByU64Str_FullMethodName = "/testpb.TestSchemaQueryService/GetExampleTableByU64Str"
|
||||
TestSchemaQueryService_ListExampleTable_FullMethodName = "/testpb.TestSchemaQueryService/ListExampleTable"
|
||||
TestSchemaQueryService_GetExampleAutoIncrementTable_FullMethodName = "/testpb.TestSchemaQueryService/GetExampleAutoIncrementTable"
|
||||
TestSchemaQueryService_GetExampleAutoIncrementTableByX_FullMethodName = "/testpb.TestSchemaQueryService/GetExampleAutoIncrementTableByX"
|
||||
TestSchemaQueryService_ListExampleAutoIncrementTable_FullMethodName = "/testpb.TestSchemaQueryService/ListExampleAutoIncrementTable"
|
||||
TestSchemaQueryService_GetExampleSingleton_FullMethodName = "/testpb.TestSchemaQueryService/GetExampleSingleton"
|
||||
TestSchemaQueryService_GetExampleTimestamp_FullMethodName = "/testpb.TestSchemaQueryService/GetExampleTimestamp"
|
||||
TestSchemaQueryService_ListExampleTimestamp_FullMethodName = "/testpb.TestSchemaQueryService/ListExampleTimestamp"
|
||||
TestSchemaQueryService_GetExampleDuration_FullMethodName = "/testpb.TestSchemaQueryService/GetExampleDuration"
|
||||
TestSchemaQueryService_ListExampleDuration_FullMethodName = "/testpb.TestSchemaQueryService/ListExampleDuration"
|
||||
TestSchemaQueryService_GetSimpleExample_FullMethodName = "/testpb.TestSchemaQueryService/GetSimpleExample"
|
||||
TestSchemaQueryService_GetSimpleExampleByUnique_FullMethodName = "/testpb.TestSchemaQueryService/GetSimpleExampleByUnique"
|
||||
TestSchemaQueryService_ListSimpleExample_FullMethodName = "/testpb.TestSchemaQueryService/ListSimpleExample"
|
||||
TestSchemaQueryService_GetExampleAutoIncFieldName_FullMethodName = "/testpb.TestSchemaQueryService/GetExampleAutoIncFieldName"
|
||||
TestSchemaQueryService_ListExampleAutoIncFieldName_FullMethodName = "/testpb.TestSchemaQueryService/ListExampleAutoIncFieldName"
|
||||
)
|
||||
|
||||
// TestSchemaQueryServiceClient is the client API for TestSchemaQueryService service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type TestSchemaQueryServiceClient interface {
|
||||
// Get queries the ExampleTable table by its primary key.
|
||||
GetExampleTable(ctx context.Context, in *GetExampleTableRequest, opts ...grpc.CallOption) (*GetExampleTableResponse, error)
|
||||
// GetExampleTableByU64Str queries the ExampleTable table by its U64Str index
|
||||
GetExampleTableByU64Str(ctx context.Context, in *GetExampleTableByU64StrRequest, opts ...grpc.CallOption) (*GetExampleTableByU64StrResponse, error)
|
||||
// ListExampleTable queries the ExampleTable table using prefix and range queries against defined indexes.
|
||||
ListExampleTable(ctx context.Context, in *ListExampleTableRequest, opts ...grpc.CallOption) (*ListExampleTableResponse, error)
|
||||
// Get queries the ExampleAutoIncrementTable table by its primary key.
|
||||
GetExampleAutoIncrementTable(ctx context.Context, in *GetExampleAutoIncrementTableRequest, opts ...grpc.CallOption) (*GetExampleAutoIncrementTableResponse, error)
|
||||
// GetExampleAutoIncrementTableByX queries the ExampleAutoIncrementTable table by its X index
|
||||
GetExampleAutoIncrementTableByX(ctx context.Context, in *GetExampleAutoIncrementTableByXRequest, opts ...grpc.CallOption) (*GetExampleAutoIncrementTableByXResponse, error)
|
||||
// ListExampleAutoIncrementTable queries the ExampleAutoIncrementTable table using prefix and range queries against defined indexes.
|
||||
ListExampleAutoIncrementTable(ctx context.Context, in *ListExampleAutoIncrementTableRequest, opts ...grpc.CallOption) (*ListExampleAutoIncrementTableResponse, error)
|
||||
// GetExampleSingleton queries the ExampleSingleton singleton.
|
||||
GetExampleSingleton(ctx context.Context, in *GetExampleSingletonRequest, opts ...grpc.CallOption) (*GetExampleSingletonResponse, error)
|
||||
// Get queries the ExampleTimestamp table by its primary key.
|
||||
GetExampleTimestamp(ctx context.Context, in *GetExampleTimestampRequest, opts ...grpc.CallOption) (*GetExampleTimestampResponse, error)
|
||||
// ListExampleTimestamp queries the ExampleTimestamp table using prefix and range queries against defined indexes.
|
||||
ListExampleTimestamp(ctx context.Context, in *ListExampleTimestampRequest, opts ...grpc.CallOption) (*ListExampleTimestampResponse, error)
|
||||
// Get queries the ExampleDuration table by its primary key.
|
||||
GetExampleDuration(ctx context.Context, in *GetExampleDurationRequest, opts ...grpc.CallOption) (*GetExampleDurationResponse, error)
|
||||
// ListExampleDuration queries the ExampleDuration table using prefix and range queries against defined indexes.
|
||||
ListExampleDuration(ctx context.Context, in *ListExampleDurationRequest, opts ...grpc.CallOption) (*ListExampleDurationResponse, error)
|
||||
// Get queries the SimpleExample table by its primary key.
|
||||
GetSimpleExample(ctx context.Context, in *GetSimpleExampleRequest, opts ...grpc.CallOption) (*GetSimpleExampleResponse, error)
|
||||
// GetSimpleExampleByUnique queries the SimpleExample table by its Unique index
|
||||
GetSimpleExampleByUnique(ctx context.Context, in *GetSimpleExampleByUniqueRequest, opts ...grpc.CallOption) (*GetSimpleExampleByUniqueResponse, error)
|
||||
// ListSimpleExample queries the SimpleExample table using prefix and range queries against defined indexes.
|
||||
ListSimpleExample(ctx context.Context, in *ListSimpleExampleRequest, opts ...grpc.CallOption) (*ListSimpleExampleResponse, error)
|
||||
// Get queries the ExampleAutoIncFieldName table by its primary key.
|
||||
GetExampleAutoIncFieldName(ctx context.Context, in *GetExampleAutoIncFieldNameRequest, opts ...grpc.CallOption) (*GetExampleAutoIncFieldNameResponse, error)
|
||||
// ListExampleAutoIncFieldName queries the ExampleAutoIncFieldName table using prefix and range queries against defined indexes.
|
||||
ListExampleAutoIncFieldName(ctx context.Context, in *ListExampleAutoIncFieldNameRequest, opts ...grpc.CallOption) (*ListExampleAutoIncFieldNameResponse, error)
|
||||
}
|
||||
|
||||
type testSchemaQueryServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewTestSchemaQueryServiceClient(cc grpc.ClientConnInterface) TestSchemaQueryServiceClient {
|
||||
return &testSchemaQueryServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *testSchemaQueryServiceClient) GetExampleTable(ctx context.Context, in *GetExampleTableRequest, opts ...grpc.CallOption) (*GetExampleTableResponse, error) {
|
||||
out := new(GetExampleTableResponse)
|
||||
err := c.cc.Invoke(ctx, TestSchemaQueryService_GetExampleTable_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *testSchemaQueryServiceClient) GetExampleTableByU64Str(ctx context.Context, in *GetExampleTableByU64StrRequest, opts ...grpc.CallOption) (*GetExampleTableByU64StrResponse, error) {
|
||||
out := new(GetExampleTableByU64StrResponse)
|
||||
err := c.cc.Invoke(ctx, TestSchemaQueryService_GetExampleTableByU64Str_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *testSchemaQueryServiceClient) ListExampleTable(ctx context.Context, in *ListExampleTableRequest, opts ...grpc.CallOption) (*ListExampleTableResponse, error) {
|
||||
out := new(ListExampleTableResponse)
|
||||
err := c.cc.Invoke(ctx, TestSchemaQueryService_ListExampleTable_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *testSchemaQueryServiceClient) GetExampleAutoIncrementTable(ctx context.Context, in *GetExampleAutoIncrementTableRequest, opts ...grpc.CallOption) (*GetExampleAutoIncrementTableResponse, error) {
|
||||
out := new(GetExampleAutoIncrementTableResponse)
|
||||
err := c.cc.Invoke(ctx, TestSchemaQueryService_GetExampleAutoIncrementTable_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *testSchemaQueryServiceClient) GetExampleAutoIncrementTableByX(ctx context.Context, in *GetExampleAutoIncrementTableByXRequest, opts ...grpc.CallOption) (*GetExampleAutoIncrementTableByXResponse, error) {
|
||||
out := new(GetExampleAutoIncrementTableByXResponse)
|
||||
err := c.cc.Invoke(ctx, TestSchemaQueryService_GetExampleAutoIncrementTableByX_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *testSchemaQueryServiceClient) ListExampleAutoIncrementTable(ctx context.Context, in *ListExampleAutoIncrementTableRequest, opts ...grpc.CallOption) (*ListExampleAutoIncrementTableResponse, error) {
|
||||
out := new(ListExampleAutoIncrementTableResponse)
|
||||
err := c.cc.Invoke(ctx, TestSchemaQueryService_ListExampleAutoIncrementTable_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *testSchemaQueryServiceClient) GetExampleSingleton(ctx context.Context, in *GetExampleSingletonRequest, opts ...grpc.CallOption) (*GetExampleSingletonResponse, error) {
|
||||
out := new(GetExampleSingletonResponse)
|
||||
err := c.cc.Invoke(ctx, TestSchemaQueryService_GetExampleSingleton_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *testSchemaQueryServiceClient) GetExampleTimestamp(ctx context.Context, in *GetExampleTimestampRequest, opts ...grpc.CallOption) (*GetExampleTimestampResponse, error) {
|
||||
out := new(GetExampleTimestampResponse)
|
||||
err := c.cc.Invoke(ctx, TestSchemaQueryService_GetExampleTimestamp_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *testSchemaQueryServiceClient) ListExampleTimestamp(ctx context.Context, in *ListExampleTimestampRequest, opts ...grpc.CallOption) (*ListExampleTimestampResponse, error) {
|
||||
out := new(ListExampleTimestampResponse)
|
||||
err := c.cc.Invoke(ctx, TestSchemaQueryService_ListExampleTimestamp_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *testSchemaQueryServiceClient) GetExampleDuration(ctx context.Context, in *GetExampleDurationRequest, opts ...grpc.CallOption) (*GetExampleDurationResponse, error) {
|
||||
out := new(GetExampleDurationResponse)
|
||||
err := c.cc.Invoke(ctx, TestSchemaQueryService_GetExampleDuration_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *testSchemaQueryServiceClient) ListExampleDuration(ctx context.Context, in *ListExampleDurationRequest, opts ...grpc.CallOption) (*ListExampleDurationResponse, error) {
|
||||
out := new(ListExampleDurationResponse)
|
||||
err := c.cc.Invoke(ctx, TestSchemaQueryService_ListExampleDuration_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *testSchemaQueryServiceClient) GetSimpleExample(ctx context.Context, in *GetSimpleExampleRequest, opts ...grpc.CallOption) (*GetSimpleExampleResponse, error) {
|
||||
out := new(GetSimpleExampleResponse)
|
||||
err := c.cc.Invoke(ctx, TestSchemaQueryService_GetSimpleExample_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *testSchemaQueryServiceClient) GetSimpleExampleByUnique(ctx context.Context, in *GetSimpleExampleByUniqueRequest, opts ...grpc.CallOption) (*GetSimpleExampleByUniqueResponse, error) {
|
||||
out := new(GetSimpleExampleByUniqueResponse)
|
||||
err := c.cc.Invoke(ctx, TestSchemaQueryService_GetSimpleExampleByUnique_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *testSchemaQueryServiceClient) ListSimpleExample(ctx context.Context, in *ListSimpleExampleRequest, opts ...grpc.CallOption) (*ListSimpleExampleResponse, error) {
|
||||
out := new(ListSimpleExampleResponse)
|
||||
err := c.cc.Invoke(ctx, TestSchemaQueryService_ListSimpleExample_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *testSchemaQueryServiceClient) GetExampleAutoIncFieldName(ctx context.Context, in *GetExampleAutoIncFieldNameRequest, opts ...grpc.CallOption) (*GetExampleAutoIncFieldNameResponse, error) {
|
||||
out := new(GetExampleAutoIncFieldNameResponse)
|
||||
err := c.cc.Invoke(ctx, TestSchemaQueryService_GetExampleAutoIncFieldName_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *testSchemaQueryServiceClient) ListExampleAutoIncFieldName(ctx context.Context, in *ListExampleAutoIncFieldNameRequest, opts ...grpc.CallOption) (*ListExampleAutoIncFieldNameResponse, error) {
|
||||
out := new(ListExampleAutoIncFieldNameResponse)
|
||||
err := c.cc.Invoke(ctx, TestSchemaQueryService_ListExampleAutoIncFieldName_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// TestSchemaQueryServiceServer is the server API for TestSchemaQueryService service.
|
||||
// All implementations must embed UnimplementedTestSchemaQueryServiceServer
|
||||
// for forward compatibility
|
||||
type TestSchemaQueryServiceServer interface {
|
||||
// Get queries the ExampleTable table by its primary key.
|
||||
GetExampleTable(context.Context, *GetExampleTableRequest) (*GetExampleTableResponse, error)
|
||||
// GetExampleTableByU64Str queries the ExampleTable table by its U64Str index
|
||||
GetExampleTableByU64Str(context.Context, *GetExampleTableByU64StrRequest) (*GetExampleTableByU64StrResponse, error)
|
||||
// ListExampleTable queries the ExampleTable table using prefix and range queries against defined indexes.
|
||||
ListExampleTable(context.Context, *ListExampleTableRequest) (*ListExampleTableResponse, error)
|
||||
// Get queries the ExampleAutoIncrementTable table by its primary key.
|
||||
GetExampleAutoIncrementTable(context.Context, *GetExampleAutoIncrementTableRequest) (*GetExampleAutoIncrementTableResponse, error)
|
||||
// GetExampleAutoIncrementTableByX queries the ExampleAutoIncrementTable table by its X index
|
||||
GetExampleAutoIncrementTableByX(context.Context, *GetExampleAutoIncrementTableByXRequest) (*GetExampleAutoIncrementTableByXResponse, error)
|
||||
// ListExampleAutoIncrementTable queries the ExampleAutoIncrementTable table using prefix and range queries against defined indexes.
|
||||
ListExampleAutoIncrementTable(context.Context, *ListExampleAutoIncrementTableRequest) (*ListExampleAutoIncrementTableResponse, error)
|
||||
// GetExampleSingleton queries the ExampleSingleton singleton.
|
||||
GetExampleSingleton(context.Context, *GetExampleSingletonRequest) (*GetExampleSingletonResponse, error)
|
||||
// Get queries the ExampleTimestamp table by its primary key.
|
||||
GetExampleTimestamp(context.Context, *GetExampleTimestampRequest) (*GetExampleTimestampResponse, error)
|
||||
// ListExampleTimestamp queries the ExampleTimestamp table using prefix and range queries against defined indexes.
|
||||
ListExampleTimestamp(context.Context, *ListExampleTimestampRequest) (*ListExampleTimestampResponse, error)
|
||||
// Get queries the ExampleDuration table by its primary key.
|
||||
GetExampleDuration(context.Context, *GetExampleDurationRequest) (*GetExampleDurationResponse, error)
|
||||
// ListExampleDuration queries the ExampleDuration table using prefix and range queries against defined indexes.
|
||||
ListExampleDuration(context.Context, *ListExampleDurationRequest) (*ListExampleDurationResponse, error)
|
||||
// Get queries the SimpleExample table by its primary key.
|
||||
GetSimpleExample(context.Context, *GetSimpleExampleRequest) (*GetSimpleExampleResponse, error)
|
||||
// GetSimpleExampleByUnique queries the SimpleExample table by its Unique index
|
||||
GetSimpleExampleByUnique(context.Context, *GetSimpleExampleByUniqueRequest) (*GetSimpleExampleByUniqueResponse, error)
|
||||
// ListSimpleExample queries the SimpleExample table using prefix and range queries against defined indexes.
|
||||
ListSimpleExample(context.Context, *ListSimpleExampleRequest) (*ListSimpleExampleResponse, error)
|
||||
// Get queries the ExampleAutoIncFieldName table by its primary key.
|
||||
GetExampleAutoIncFieldName(context.Context, *GetExampleAutoIncFieldNameRequest) (*GetExampleAutoIncFieldNameResponse, error)
|
||||
// ListExampleAutoIncFieldName queries the ExampleAutoIncFieldName table using prefix and range queries against defined indexes.
|
||||
ListExampleAutoIncFieldName(context.Context, *ListExampleAutoIncFieldNameRequest) (*ListExampleAutoIncFieldNameResponse, error)
|
||||
mustEmbedUnimplementedTestSchemaQueryServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedTestSchemaQueryServiceServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedTestSchemaQueryServiceServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedTestSchemaQueryServiceServer) GetExampleTable(context.Context, *GetExampleTableRequest) (*GetExampleTableResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetExampleTable not implemented")
|
||||
}
|
||||
func (UnimplementedTestSchemaQueryServiceServer) GetExampleTableByU64Str(context.Context, *GetExampleTableByU64StrRequest) (*GetExampleTableByU64StrResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetExampleTableByU64Str not implemented")
|
||||
}
|
||||
func (UnimplementedTestSchemaQueryServiceServer) ListExampleTable(context.Context, *ListExampleTableRequest) (*ListExampleTableResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListExampleTable not implemented")
|
||||
}
|
||||
func (UnimplementedTestSchemaQueryServiceServer) GetExampleAutoIncrementTable(context.Context, *GetExampleAutoIncrementTableRequest) (*GetExampleAutoIncrementTableResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetExampleAutoIncrementTable not implemented")
|
||||
}
|
||||
func (UnimplementedTestSchemaQueryServiceServer) GetExampleAutoIncrementTableByX(context.Context, *GetExampleAutoIncrementTableByXRequest) (*GetExampleAutoIncrementTableByXResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetExampleAutoIncrementTableByX not implemented")
|
||||
}
|
||||
func (UnimplementedTestSchemaQueryServiceServer) ListExampleAutoIncrementTable(context.Context, *ListExampleAutoIncrementTableRequest) (*ListExampleAutoIncrementTableResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListExampleAutoIncrementTable not implemented")
|
||||
}
|
||||
func (UnimplementedTestSchemaQueryServiceServer) GetExampleSingleton(context.Context, *GetExampleSingletonRequest) (*GetExampleSingletonResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetExampleSingleton not implemented")
|
||||
}
|
||||
func (UnimplementedTestSchemaQueryServiceServer) GetExampleTimestamp(context.Context, *GetExampleTimestampRequest) (*GetExampleTimestampResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetExampleTimestamp not implemented")
|
||||
}
|
||||
func (UnimplementedTestSchemaQueryServiceServer) ListExampleTimestamp(context.Context, *ListExampleTimestampRequest) (*ListExampleTimestampResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListExampleTimestamp not implemented")
|
||||
}
|
||||
func (UnimplementedTestSchemaQueryServiceServer) GetExampleDuration(context.Context, *GetExampleDurationRequest) (*GetExampleDurationResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetExampleDuration not implemented")
|
||||
}
|
||||
func (UnimplementedTestSchemaQueryServiceServer) ListExampleDuration(context.Context, *ListExampleDurationRequest) (*ListExampleDurationResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListExampleDuration not implemented")
|
||||
}
|
||||
func (UnimplementedTestSchemaQueryServiceServer) GetSimpleExample(context.Context, *GetSimpleExampleRequest) (*GetSimpleExampleResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetSimpleExample not implemented")
|
||||
}
|
||||
func (UnimplementedTestSchemaQueryServiceServer) GetSimpleExampleByUnique(context.Context, *GetSimpleExampleByUniqueRequest) (*GetSimpleExampleByUniqueResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetSimpleExampleByUnique not implemented")
|
||||
}
|
||||
func (UnimplementedTestSchemaQueryServiceServer) ListSimpleExample(context.Context, *ListSimpleExampleRequest) (*ListSimpleExampleResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListSimpleExample not implemented")
|
||||
}
|
||||
func (UnimplementedTestSchemaQueryServiceServer) GetExampleAutoIncFieldName(context.Context, *GetExampleAutoIncFieldNameRequest) (*GetExampleAutoIncFieldNameResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetExampleAutoIncFieldName not implemented")
|
||||
}
|
||||
func (UnimplementedTestSchemaQueryServiceServer) ListExampleAutoIncFieldName(context.Context, *ListExampleAutoIncFieldNameRequest) (*ListExampleAutoIncFieldNameResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListExampleAutoIncFieldName not implemented")
|
||||
}
|
||||
func (UnimplementedTestSchemaQueryServiceServer) mustEmbedUnimplementedTestSchemaQueryServiceServer() {
|
||||
}
|
||||
|
||||
// UnsafeTestSchemaQueryServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to TestSchemaQueryServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeTestSchemaQueryServiceServer interface {
|
||||
mustEmbedUnimplementedTestSchemaQueryServiceServer()
|
||||
}
|
||||
|
||||
func RegisterTestSchemaQueryServiceServer(s grpc.ServiceRegistrar, srv TestSchemaQueryServiceServer) {
|
||||
s.RegisterService(&TestSchemaQueryService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _TestSchemaQueryService_GetExampleTable_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetExampleTableRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(TestSchemaQueryServiceServer).GetExampleTable(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: TestSchemaQueryService_GetExampleTable_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(TestSchemaQueryServiceServer).GetExampleTable(ctx, req.(*GetExampleTableRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _TestSchemaQueryService_GetExampleTableByU64Str_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetExampleTableByU64StrRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(TestSchemaQueryServiceServer).GetExampleTableByU64Str(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: TestSchemaQueryService_GetExampleTableByU64Str_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(TestSchemaQueryServiceServer).GetExampleTableByU64Str(ctx, req.(*GetExampleTableByU64StrRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _TestSchemaQueryService_ListExampleTable_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListExampleTableRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(TestSchemaQueryServiceServer).ListExampleTable(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: TestSchemaQueryService_ListExampleTable_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(TestSchemaQueryServiceServer).ListExampleTable(ctx, req.(*ListExampleTableRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _TestSchemaQueryService_GetExampleAutoIncrementTable_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetExampleAutoIncrementTableRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(TestSchemaQueryServiceServer).GetExampleAutoIncrementTable(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: TestSchemaQueryService_GetExampleAutoIncrementTable_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(TestSchemaQueryServiceServer).GetExampleAutoIncrementTable(ctx, req.(*GetExampleAutoIncrementTableRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _TestSchemaQueryService_GetExampleAutoIncrementTableByX_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetExampleAutoIncrementTableByXRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(TestSchemaQueryServiceServer).GetExampleAutoIncrementTableByX(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: TestSchemaQueryService_GetExampleAutoIncrementTableByX_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(TestSchemaQueryServiceServer).GetExampleAutoIncrementTableByX(ctx, req.(*GetExampleAutoIncrementTableByXRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _TestSchemaQueryService_ListExampleAutoIncrementTable_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListExampleAutoIncrementTableRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(TestSchemaQueryServiceServer).ListExampleAutoIncrementTable(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: TestSchemaQueryService_ListExampleAutoIncrementTable_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(TestSchemaQueryServiceServer).ListExampleAutoIncrementTable(ctx, req.(*ListExampleAutoIncrementTableRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _TestSchemaQueryService_GetExampleSingleton_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetExampleSingletonRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(TestSchemaQueryServiceServer).GetExampleSingleton(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: TestSchemaQueryService_GetExampleSingleton_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(TestSchemaQueryServiceServer).GetExampleSingleton(ctx, req.(*GetExampleSingletonRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _TestSchemaQueryService_GetExampleTimestamp_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetExampleTimestampRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(TestSchemaQueryServiceServer).GetExampleTimestamp(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: TestSchemaQueryService_GetExampleTimestamp_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(TestSchemaQueryServiceServer).GetExampleTimestamp(ctx, req.(*GetExampleTimestampRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _TestSchemaQueryService_ListExampleTimestamp_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListExampleTimestampRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(TestSchemaQueryServiceServer).ListExampleTimestamp(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: TestSchemaQueryService_ListExampleTimestamp_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(TestSchemaQueryServiceServer).ListExampleTimestamp(ctx, req.(*ListExampleTimestampRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _TestSchemaQueryService_GetExampleDuration_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetExampleDurationRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(TestSchemaQueryServiceServer).GetExampleDuration(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: TestSchemaQueryService_GetExampleDuration_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(TestSchemaQueryServiceServer).GetExampleDuration(ctx, req.(*GetExampleDurationRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _TestSchemaQueryService_ListExampleDuration_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListExampleDurationRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(TestSchemaQueryServiceServer).ListExampleDuration(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: TestSchemaQueryService_ListExampleDuration_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(TestSchemaQueryServiceServer).ListExampleDuration(ctx, req.(*ListExampleDurationRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _TestSchemaQueryService_GetSimpleExample_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetSimpleExampleRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(TestSchemaQueryServiceServer).GetSimpleExample(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: TestSchemaQueryService_GetSimpleExample_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(TestSchemaQueryServiceServer).GetSimpleExample(ctx, req.(*GetSimpleExampleRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _TestSchemaQueryService_GetSimpleExampleByUnique_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetSimpleExampleByUniqueRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(TestSchemaQueryServiceServer).GetSimpleExampleByUnique(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: TestSchemaQueryService_GetSimpleExampleByUnique_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(TestSchemaQueryServiceServer).GetSimpleExampleByUnique(ctx, req.(*GetSimpleExampleByUniqueRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _TestSchemaQueryService_ListSimpleExample_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListSimpleExampleRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(TestSchemaQueryServiceServer).ListSimpleExample(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: TestSchemaQueryService_ListSimpleExample_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(TestSchemaQueryServiceServer).ListSimpleExample(ctx, req.(*ListSimpleExampleRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _TestSchemaQueryService_GetExampleAutoIncFieldName_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetExampleAutoIncFieldNameRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(TestSchemaQueryServiceServer).GetExampleAutoIncFieldName(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: TestSchemaQueryService_GetExampleAutoIncFieldName_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(TestSchemaQueryServiceServer).GetExampleAutoIncFieldName(ctx, req.(*GetExampleAutoIncFieldNameRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _TestSchemaQueryService_ListExampleAutoIncFieldName_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListExampleAutoIncFieldNameRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(TestSchemaQueryServiceServer).ListExampleAutoIncFieldName(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: TestSchemaQueryService_ListExampleAutoIncFieldName_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(TestSchemaQueryServiceServer).ListExampleAutoIncFieldName(ctx, req.(*ListExampleAutoIncFieldNameRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// TestSchemaQueryService_ServiceDesc is the grpc.ServiceDesc for TestSchemaQueryService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var TestSchemaQueryService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "testpb.TestSchemaQueryService",
|
||||
HandlerType: (*TestSchemaQueryServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "GetExampleTable",
|
||||
Handler: _TestSchemaQueryService_GetExampleTable_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetExampleTableByU64Str",
|
||||
Handler: _TestSchemaQueryService_GetExampleTableByU64Str_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListExampleTable",
|
||||
Handler: _TestSchemaQueryService_ListExampleTable_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetExampleAutoIncrementTable",
|
||||
Handler: _TestSchemaQueryService_GetExampleAutoIncrementTable_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetExampleAutoIncrementTableByX",
|
||||
Handler: _TestSchemaQueryService_GetExampleAutoIncrementTableByX_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListExampleAutoIncrementTable",
|
||||
Handler: _TestSchemaQueryService_ListExampleAutoIncrementTable_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetExampleSingleton",
|
||||
Handler: _TestSchemaQueryService_GetExampleSingleton_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetExampleTimestamp",
|
||||
Handler: _TestSchemaQueryService_GetExampleTimestamp_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListExampleTimestamp",
|
||||
Handler: _TestSchemaQueryService_ListExampleTimestamp_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetExampleDuration",
|
||||
Handler: _TestSchemaQueryService_GetExampleDuration_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListExampleDuration",
|
||||
Handler: _TestSchemaQueryService_ListExampleDuration_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetSimpleExample",
|
||||
Handler: _TestSchemaQueryService_GetSimpleExample_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetSimpleExampleByUnique",
|
||||
Handler: _TestSchemaQueryService_GetSimpleExampleByUnique_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListSimpleExample",
|
||||
Handler: _TestSchemaQueryService_ListSimpleExample_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetExampleAutoIncFieldName",
|
||||
Handler: _TestSchemaQueryService_GetExampleAutoIncFieldName_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListExampleAutoIncFieldName",
|
||||
Handler: _TestSchemaQueryService_ListExampleAutoIncFieldName_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "testpb/test_schema_query.proto",
|
||||
}
|
||||
@ -1,199 +0,0 @@
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/types/known/durationpb"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
"pgregory.net/rapid"
|
||||
|
||||
"cosmossdk.io/orm/encoding/ormfield"
|
||||
"cosmossdk.io/orm/encoding/ormkv"
|
||||
"cosmossdk.io/orm/internal/testpb"
|
||||
)
|
||||
|
||||
// TestFieldSpec defines a test field against the testpb.ExampleTable message.
|
||||
type TestFieldSpec struct {
|
||||
FieldName protoreflect.Name
|
||||
Gen *rapid.Generator[any]
|
||||
}
|
||||
|
||||
var TestFieldSpecs = []TestFieldSpec{
|
||||
{
|
||||
"u32",
|
||||
rapid.Uint32().AsAny(),
|
||||
},
|
||||
{
|
||||
"u64",
|
||||
rapid.Uint64().AsAny(),
|
||||
},
|
||||
{
|
||||
"str",
|
||||
rapid.String().Filter(func(x string) bool {
|
||||
// filter out null terminators
|
||||
return strings.IndexByte(x, 0) < 0
|
||||
}).AsAny(),
|
||||
},
|
||||
{
|
||||
"bz",
|
||||
rapid.SliceOfN(rapid.Byte(), 0, math.MaxUint32).AsAny(),
|
||||
},
|
||||
{
|
||||
"i32",
|
||||
rapid.Int32().AsAny(),
|
||||
},
|
||||
{
|
||||
"f32",
|
||||
rapid.Uint32().AsAny(),
|
||||
},
|
||||
{
|
||||
"s32",
|
||||
rapid.Int32().AsAny(),
|
||||
},
|
||||
{
|
||||
"sf32",
|
||||
rapid.Int32().AsAny(),
|
||||
},
|
||||
{
|
||||
"i64",
|
||||
rapid.Int64().AsAny(),
|
||||
},
|
||||
{
|
||||
"f64",
|
||||
rapid.Uint64().AsAny(),
|
||||
},
|
||||
{
|
||||
"s64",
|
||||
rapid.Int64().AsAny(),
|
||||
},
|
||||
{
|
||||
"sf64",
|
||||
rapid.Int64().AsAny(),
|
||||
},
|
||||
{
|
||||
"b",
|
||||
rapid.Bool().AsAny(),
|
||||
},
|
||||
{
|
||||
"ts",
|
||||
rapid.Custom(func(t *rapid.T) protoreflect.Message {
|
||||
isNil := rapid.Float32().Draw(t, "isNil")
|
||||
if isNil >= 0.95 { // draw a nil 5% of the time
|
||||
return nil
|
||||
}
|
||||
seconds := rapid.Int64Range(ormfield.TimestampSecondsMin, ormfield.TimestampSecondsMax).Draw(t, "seconds")
|
||||
nanos := rapid.Int32Range(0, ormfield.TimestampNanosMax).Draw(t, "nanos")
|
||||
return (×tamppb.Timestamp{
|
||||
Seconds: seconds,
|
||||
Nanos: nanos,
|
||||
}).ProtoReflect()
|
||||
}).AsAny(),
|
||||
},
|
||||
{
|
||||
"dur",
|
||||
rapid.Custom(func(t *rapid.T) protoreflect.Message {
|
||||
isNil := rapid.Float32().Draw(t, "isNil")
|
||||
if isNil >= 0.95 { // draw a nil 5% of the time
|
||||
return nil
|
||||
}
|
||||
seconds := rapid.Int64Range(ormfield.DurationNanosMin, ormfield.DurationNanosMax).Draw(t, "seconds")
|
||||
nanos := rapid.Int32Range(0, ormfield.DurationNanosMax).Draw(t, "nanos")
|
||||
if seconds < 0 {
|
||||
nanos = -nanos
|
||||
}
|
||||
return (&durationpb.Duration{
|
||||
Seconds: seconds,
|
||||
Nanos: nanos,
|
||||
}).ProtoReflect()
|
||||
}).AsAny(),
|
||||
},
|
||||
{
|
||||
"e",
|
||||
rapid.Map(rapid.Int32(), func(x int32) protoreflect.EnumNumber {
|
||||
return protoreflect.EnumNumber(x)
|
||||
}).AsAny(),
|
||||
},
|
||||
}
|
||||
|
||||
func MakeTestCodec(fname protoreflect.Name, nonTerminal bool) (ormfield.Codec, error) {
|
||||
field := GetTestField(fname)
|
||||
if field == nil {
|
||||
return nil, fmt.Errorf("can't find field %s", fname)
|
||||
}
|
||||
return ormfield.GetCodec(field, nonTerminal)
|
||||
}
|
||||
|
||||
func GetTestField(fname protoreflect.Name) protoreflect.FieldDescriptor {
|
||||
a := &testpb.ExampleTable{}
|
||||
return a.ProtoReflect().Descriptor().Fields().ByName(fname)
|
||||
}
|
||||
|
||||
type TestKeyCodec struct {
|
||||
KeySpecs []TestFieldSpec
|
||||
Codec *ormkv.KeyCodec
|
||||
}
|
||||
|
||||
func TestFieldSpecsGen(minLen, maxLen int) *rapid.Generator[[]TestFieldSpec] {
|
||||
return rapid.Custom(func(t *rapid.T) []TestFieldSpec {
|
||||
xs := rapid.SliceOfNDistinct(rapid.IntRange(0, len(TestFieldSpecs)-1), minLen, maxLen, func(i int) int { return i }).
|
||||
Draw(t, "fieldSpecIndexes")
|
||||
|
||||
var specs []TestFieldSpec
|
||||
|
||||
for _, x := range xs {
|
||||
spec := TestFieldSpecs[x]
|
||||
specs = append(specs, spec)
|
||||
}
|
||||
|
||||
return specs
|
||||
})
|
||||
}
|
||||
|
||||
func TestKeyCodecGen(minLen, maxLen int) *rapid.Generator[TestKeyCodec] {
|
||||
return rapid.Custom(func(t *rapid.T) TestKeyCodec {
|
||||
specs := TestFieldSpecsGen(minLen, maxLen).Draw(t, "fieldSpecs")
|
||||
|
||||
var fields []protoreflect.Name
|
||||
for _, spec := range specs {
|
||||
fields = append(fields, spec.FieldName)
|
||||
}
|
||||
|
||||
prefix := rapid.SliceOfN(rapid.Byte(), 0, 5).Draw(t, "prefix")
|
||||
|
||||
msgType := (&testpb.ExampleTable{}).ProtoReflect().Type()
|
||||
cdc, err := ormkv.NewKeyCodec(prefix, msgType, fields)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return TestKeyCodec{
|
||||
Codec: cdc,
|
||||
KeySpecs: specs,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (k TestKeyCodec) Draw(t *rapid.T, id string) []protoreflect.Value {
|
||||
n := len(k.KeySpecs)
|
||||
keyValues := make([]protoreflect.Value, n)
|
||||
for i, k := range k.KeySpecs {
|
||||
keyValues[i] = protoreflect.ValueOf(k.Gen.Draw(t, fmt.Sprintf("%s[%d]", id, i)))
|
||||
}
|
||||
return keyValues
|
||||
}
|
||||
|
||||
var GenA = rapid.Custom(func(t *rapid.T) *testpb.ExampleTable {
|
||||
a := &testpb.ExampleTable{}
|
||||
ref := a.ProtoReflect()
|
||||
for _, spec := range TestFieldSpecs {
|
||||
field := GetTestField(spec.FieldName)
|
||||
value := spec.Gen.Draw(t, string(spec.FieldName))
|
||||
if value != nil {
|
||||
ref.Set(field, protoreflect.ValueOf(value))
|
||||
}
|
||||
}
|
||||
return a
|
||||
})
|
||||
@ -1,3 +0,0 @@
|
||||
// Package model contains packages which define ORM data "model" types
|
||||
// such as tables, indexes, and schemas.
|
||||
package model
|
||||
@ -1,123 +0,0 @@
|
||||
package ormdb
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"math"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/reflect/protoregistry"
|
||||
|
||||
"cosmossdk.io/orm/encoding/encodeutil"
|
||||
"cosmossdk.io/orm/encoding/ormkv"
|
||||
"cosmossdk.io/orm/model/ormtable"
|
||||
"cosmossdk.io/orm/types/ormerrors"
|
||||
)
|
||||
|
||||
type fileDescriptorDBOptions struct {
|
||||
Prefix []byte
|
||||
ID uint32
|
||||
TypeResolver ormtable.TypeResolver
|
||||
JSONValidator func(proto.Message) error
|
||||
BackendResolver ormtable.BackendResolver
|
||||
}
|
||||
|
||||
type fileDescriptorDB struct {
|
||||
id uint32
|
||||
prefix []byte
|
||||
tablesByID map[uint32]ormtable.Table
|
||||
tablesByName map[protoreflect.FullName]ormtable.Table
|
||||
fileDescriptor protoreflect.FileDescriptor
|
||||
}
|
||||
|
||||
func newFileDescriptorDB(fileDescriptor protoreflect.FileDescriptor, options fileDescriptorDBOptions) (*fileDescriptorDB, error) {
|
||||
prefix := encodeutil.AppendVarUInt32(options.Prefix, options.ID)
|
||||
|
||||
schema := &fileDescriptorDB{
|
||||
id: options.ID,
|
||||
prefix: prefix,
|
||||
tablesByID: map[uint32]ormtable.Table{},
|
||||
tablesByName: map[protoreflect.FullName]ormtable.Table{},
|
||||
fileDescriptor: fileDescriptor,
|
||||
}
|
||||
|
||||
resolver := options.TypeResolver
|
||||
if resolver == nil {
|
||||
resolver = protoregistry.GlobalTypes
|
||||
}
|
||||
|
||||
messages := fileDescriptor.Messages()
|
||||
n := messages.Len()
|
||||
for i := 0; i < n; i++ {
|
||||
messageDescriptor := messages.Get(i)
|
||||
tableName := messageDescriptor.FullName()
|
||||
messageType, err := resolver.FindMessageByName(tableName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
table, err := ormtable.Build(ormtable.Options{
|
||||
Prefix: prefix,
|
||||
MessageType: messageType,
|
||||
TypeResolver: resolver,
|
||||
JSONValidator: options.JSONValidator,
|
||||
BackendResolver: options.BackendResolver,
|
||||
})
|
||||
if errors.Is(err, ormerrors.NoTableDescriptor) {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := table.ID()
|
||||
if _, ok := schema.tablesByID[id]; ok {
|
||||
return nil, ormerrors.InvalidTableId.Wrapf("duplicate ID %d for %s", id, tableName)
|
||||
}
|
||||
schema.tablesByID[id] = table
|
||||
|
||||
if _, ok := schema.tablesByName[tableName]; ok {
|
||||
return nil, ormerrors.InvalidTableDefinition.Wrapf("duplicate table %s", tableName)
|
||||
}
|
||||
schema.tablesByName[tableName] = table
|
||||
}
|
||||
|
||||
return schema, nil
|
||||
}
|
||||
|
||||
func (f fileDescriptorDB) DecodeEntry(k, v []byte) (ormkv.Entry, error) {
|
||||
r := bytes.NewReader(k)
|
||||
err := encodeutil.SkipPrefix(r, f.prefix)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id, err := binary.ReadUvarint(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if id > math.MaxUint32 {
|
||||
return nil, ormerrors.UnexpectedDecodePrefix.Wrapf("uint32 varint id out of range %d", id)
|
||||
}
|
||||
|
||||
table, ok := f.tablesByID[uint32(id)]
|
||||
if !ok {
|
||||
return nil, ormerrors.UnexpectedDecodePrefix.Wrapf("can't find table with id %d", id)
|
||||
}
|
||||
|
||||
return table.DecodeEntry(k, v)
|
||||
}
|
||||
|
||||
func (f fileDescriptorDB) EncodeEntry(entry ormkv.Entry) (k, v []byte, err error) {
|
||||
table, ok := f.tablesByName[entry.GetTableName()]
|
||||
if !ok {
|
||||
return nil, nil, ormerrors.BadDecodeEntry.Wrapf("can't find table %s", entry.GetTableName())
|
||||
}
|
||||
|
||||
return table.EncodeEntry(entry)
|
||||
}
|
||||
|
||||
var _ ormkv.EntryCodec = fileDescriptorDB{}
|
||||
64
orm/model/ormdb/testdata/bank_scenario.golden
vendored
64
orm/model/ormdb/testdata/bank_scenario.golden
vendored
@ -1,64 +0,0 @@
|
||||
GET 010200666f6f
|
||||
PK testpb.Supply foo -> {"denom":"foo"}
|
||||
GET 010200666f6f
|
||||
PK testpb.Supply foo -> {"denom":"foo"}
|
||||
ORM BEFORE INSERT testpb.Supply {"denom":"foo","amount":100}
|
||||
SET 010200666f6f 1064
|
||||
PK testpb.Supply foo -> {"denom":"foo","amount":100}
|
||||
ORM AFTER INSERT testpb.Supply {"denom":"foo","amount":100}
|
||||
GET 010100626f6200666f6f
|
||||
PK testpb.Balance bob/foo -> {"address":"bob","denom":"foo"}
|
||||
GET 010100626f6200666f6f
|
||||
PK testpb.Balance bob/foo -> {"address":"bob","denom":"foo"}
|
||||
ORM BEFORE INSERT testpb.Balance {"address":"bob","denom":"foo","amount":100}
|
||||
SET 010100626f6200666f6f 1864
|
||||
PK testpb.Balance bob/foo -> {"address":"bob","denom":"foo","amount":100}
|
||||
SET 010101666f6f00626f62
|
||||
IDX testpb.Balance denom/address : foo/bob -> bob/foo
|
||||
ORM AFTER INSERT testpb.Balance {"address":"bob","denom":"foo","amount":100}
|
||||
GET 010100626f6200666f6f 1864
|
||||
PK testpb.Balance bob/foo -> {"address":"bob","denom":"foo","amount":100}
|
||||
GET 010200666f6f 1064
|
||||
PK testpb.Supply foo -> {"denom":"foo","amount":100}
|
||||
GET 010100626f6200666f6f 1864
|
||||
PK testpb.Balance bob/foo -> {"address":"bob","denom":"foo","amount":100}
|
||||
GET 010100626f6200666f6f 1864
|
||||
PK testpb.Balance bob/foo -> {"address":"bob","denom":"foo","amount":100}
|
||||
ORM BEFORE UPDATE testpb.Balance {"address":"bob","denom":"foo","amount":100} -> {"address":"bob","denom":"foo","amount":70}
|
||||
SET 010100626f6200666f6f 1846
|
||||
PK testpb.Balance bob/foo -> {"address":"bob","denom":"foo","amount":70}
|
||||
ORM AFTER UPDATE testpb.Balance {"address":"bob","denom":"foo","amount":100} -> {"address":"bob","denom":"foo","amount":70}
|
||||
GET 01010073616c6c7900666f6f
|
||||
PK testpb.Balance sally/foo -> {"address":"sally","denom":"foo"}
|
||||
GET 01010073616c6c7900666f6f
|
||||
PK testpb.Balance sally/foo -> {"address":"sally","denom":"foo"}
|
||||
ORM BEFORE INSERT testpb.Balance {"address":"sally","denom":"foo","amount":30}
|
||||
SET 01010073616c6c7900666f6f 181e
|
||||
PK testpb.Balance sally/foo -> {"address":"sally","denom":"foo","amount":30}
|
||||
SET 010101666f6f0073616c6c79
|
||||
IDX testpb.Balance denom/address : foo/sally -> sally/foo
|
||||
ORM AFTER INSERT testpb.Balance {"address":"sally","denom":"foo","amount":30}
|
||||
GET 010100626f6200666f6f 1846
|
||||
PK testpb.Balance bob/foo -> {"address":"bob","denom":"foo","amount":70}
|
||||
GET 01010073616c6c7900666f6f 181e
|
||||
PK testpb.Balance sally/foo -> {"address":"sally","denom":"foo","amount":30}
|
||||
GET 010200666f6f 1064
|
||||
PK testpb.Supply foo -> {"denom":"foo","amount":100}
|
||||
GET 010200666f6f 1064
|
||||
PK testpb.Supply foo -> {"denom":"foo","amount":100}
|
||||
ORM BEFORE UPDATE testpb.Supply {"denom":"foo","amount":100} -> {"denom":"foo","amount":97}
|
||||
SET 010200666f6f 1061
|
||||
PK testpb.Supply foo -> {"denom":"foo","amount":97}
|
||||
ORM AFTER UPDATE testpb.Supply {"denom":"foo","amount":100} -> {"denom":"foo","amount":97}
|
||||
GET 01010073616c6c7900666f6f 181e
|
||||
PK testpb.Balance sally/foo -> {"address":"sally","denom":"foo","amount":30}
|
||||
GET 01010073616c6c7900666f6f 181e
|
||||
PK testpb.Balance sally/foo -> {"address":"sally","denom":"foo","amount":30}
|
||||
ORM BEFORE UPDATE testpb.Balance {"address":"sally","denom":"foo","amount":30} -> {"address":"sally","denom":"foo","amount":27}
|
||||
SET 01010073616c6c7900666f6f 181b
|
||||
PK testpb.Balance sally/foo -> {"address":"sally","denom":"foo","amount":27}
|
||||
ORM AFTER UPDATE testpb.Balance {"address":"sally","denom":"foo","amount":30} -> {"address":"sally","denom":"foo","amount":27}
|
||||
GET 01010073616c6c7900666f6f 181b
|
||||
PK testpb.Balance sally/foo -> {"address":"sally","denom":"foo","amount":27}
|
||||
GET 010200666f6f 1061
|
||||
PK testpb.Supply foo -> {"denom":"foo","amount":97}
|
||||
4
orm/model/ormdb/testdata/default_json.golden
vendored
4
orm/model/ormdb/testdata/default_json.golden
vendored
@ -1,4 +0,0 @@
|
||||
{
|
||||
"testpb.Balance": [],
|
||||
"testpb.Supply": []
|
||||
}
|
||||
@ -1,81 +0,0 @@
|
||||
// Package ormlist defines options for listing items from ORM indexes.
|
||||
package ormlist
|
||||
|
||||
import (
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
queryv1beta1 "cosmossdk.io/api/cosmos/base/query/v1beta1"
|
||||
"cosmossdk.io/orm/internal/listinternal"
|
||||
)
|
||||
|
||||
// Option represents a list option.
|
||||
type Option = listinternal.Option
|
||||
|
||||
// Reverse reverses the direction of iteration. If Reverse is
|
||||
// provided twice, iteration will happen in the forward direction.
|
||||
func Reverse() Option {
|
||||
return listinternal.FuncOption(func(options *listinternal.Options) {
|
||||
options.Reverse = !options.Reverse
|
||||
})
|
||||
}
|
||||
|
||||
// Filter returns an option which applies a filter function to each item
|
||||
// and skips over it when the filter function returns false.
|
||||
func Filter(filterFn func(message proto.Message) bool) Option {
|
||||
return listinternal.FuncOption(func(options *listinternal.Options) {
|
||||
options.Filter = filterFn
|
||||
})
|
||||
}
|
||||
|
||||
// Cursor specifies a cursor after which to restart iteration. Cursor values
|
||||
// are returned by iterators and in pagination results.
|
||||
func Cursor(cursor CursorT) Option {
|
||||
return listinternal.FuncOption(func(options *listinternal.Options) {
|
||||
options.Cursor = cursor
|
||||
})
|
||||
}
|
||||
|
||||
// Paginate paginates iterator output based on the provided page request.
|
||||
// The Iterator.PageRequest value on the returned iterator will be non-nil
|
||||
// after Iterator.Next() returns false when this option is provided.
|
||||
//
|
||||
// Care should be taken when using Paginate together with Reverse and/or Cursor.
|
||||
// In the case of combining Reverse and Paginate, if pageRequest.Reverse is
|
||||
// true then iteration will proceed in the forward direction. This allows
|
||||
// the default iteration direction for a query to be reverse with the option
|
||||
// to switch this (to forward in this case) using PageRequest. If Cursor
|
||||
// and Paginate are used together, whichever option is used first wins.
|
||||
// If pageRequest is nil, this option will be a no-op so the caller does not
|
||||
// need to do a nil check. This function defines no default limit, so if
|
||||
// the caller does not define a limit, this will return all results. To
|
||||
// specify a default limit use the DefaultLimit option.
|
||||
func Paginate(pageRequest *queryv1beta1.PageRequest) Option {
|
||||
return listinternal.FuncOption(func(options *listinternal.Options) {
|
||||
if pageRequest == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if pageRequest.Reverse {
|
||||
// if the reverse is true we invert the direction of iteration,
|
||||
// meaning if iteration was already reversed we set it forward.
|
||||
options.Reverse = !options.Reverse
|
||||
}
|
||||
|
||||
options.Cursor = pageRequest.Key
|
||||
options.Offset = pageRequest.Offset
|
||||
options.Limit = pageRequest.Limit
|
||||
options.CountTotal = pageRequest.CountTotal
|
||||
})
|
||||
}
|
||||
|
||||
// DefaultLimit specifies a default limit for iteration. This option can be
|
||||
// combined with Paginate to ensure that there is a default limit if none
|
||||
// is specified in PageRequest.
|
||||
func DefaultLimit(defaultLimit uint64) Option {
|
||||
return listinternal.FuncOption(func(options *listinternal.Options) {
|
||||
options.DefaultLimit = defaultLimit
|
||||
})
|
||||
}
|
||||
|
||||
// CursorT defines a cursor type.
|
||||
type CursorT []byte
|
||||
@ -1,250 +0,0 @@
|
||||
package ormtable
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
|
||||
"cosmossdk.io/orm/encoding/ormkv"
|
||||
"cosmossdk.io/orm/types/kv"
|
||||
"cosmossdk.io/orm/types/ormerrors"
|
||||
)
|
||||
|
||||
// autoIncrementTable is a Table implementation for tables with an
|
||||
// auto-incrementing uint64 primary key.
|
||||
type autoIncrementTable struct {
|
||||
*tableImpl
|
||||
autoIncField protoreflect.FieldDescriptor
|
||||
seqCodec *ormkv.SeqCodec
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
return t.save(ctx, backend, message, saveModeInsert)
|
||||
}
|
||||
|
||||
func (t autoIncrementTable) Save(ctx context.Context, message proto.Message) error {
|
||||
backend, err := t.getWriteBackend(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = t.save(ctx, backend, message, saveModeDefault)
|
||||
return err
|
||||
}
|
||||
|
||||
func (t autoIncrementTable) Insert(ctx context.Context, message proto.Message) error {
|
||||
backend, err := t.getWriteBackend(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = t.save(ctx, backend, message, saveModeInsert)
|
||||
return err
|
||||
}
|
||||
|
||||
func (t autoIncrementTable) Update(ctx context.Context, message proto.Message) error {
|
||||
backend, err := t.getWriteBackend(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = t.save(ctx, backend, message, saveModeUpdate)
|
||||
return err
|
||||
}
|
||||
|
||||
func (t autoIncrementTable) LastInsertedSequence(ctx context.Context) (uint64, error) {
|
||||
backend, err := t.getBackend(ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return t.curSeqValue(backend.IndexStoreReader())
|
||||
}
|
||||
|
||||
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)
|
||||
defer writer.Close()
|
||||
|
||||
if val == 0 {
|
||||
if mode == saveModeUpdate {
|
||||
return 0, ormerrors.PrimaryKeyInvalidOnUpdate
|
||||
}
|
||||
|
||||
mode = saveModeInsert
|
||||
newPK, err = t.nextSeqValue(writer.IndexStore())
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
messageRef.Set(t.autoIncField, protoreflect.ValueOfUint64(newPK))
|
||||
} else {
|
||||
if mode == saveModeInsert {
|
||||
return 0, ormerrors.AutoIncrementKeyAlreadySet
|
||||
}
|
||||
|
||||
mode = saveModeUpdate
|
||||
}
|
||||
|
||||
return newPK, t.tableImpl.doSave(ctx, writer, message, mode)
|
||||
}
|
||||
|
||||
func (t *autoIncrementTable) curSeqValue(kv kv.ReadonlyStore) (uint64, error) {
|
||||
bz, err := kv.Get(t.seqCodec.Prefix())
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return t.seqCodec.DecodeValue(bz)
|
||||
}
|
||||
|
||||
func (t *autoIncrementTable) nextSeqValue(kv kv.Store) (uint64, error) {
|
||||
seq, err := t.curSeqValue(kv)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
seq++
|
||||
return seq, t.setSeqValue(kv, seq)
|
||||
}
|
||||
|
||||
func (t *autoIncrementTable) setSeqValue(kv kv.Store, seq uint64) error {
|
||||
return kv.Set(t.seqCodec.Prefix(), t.seqCodec.EncodeValue(seq))
|
||||
}
|
||||
|
||||
func (t autoIncrementTable) EncodeEntry(entry ormkv.Entry) (k, v []byte, err error) {
|
||||
if _, ok := entry.(*ormkv.SeqEntry); ok {
|
||||
return t.seqCodec.EncodeEntry(entry)
|
||||
}
|
||||
return t.tableImpl.EncodeEntry(entry)
|
||||
}
|
||||
|
||||
func (t autoIncrementTable) ValidateJSON(reader io.Reader) error {
|
||||
return t.decodeAutoIncJSON(nil, reader, func(message proto.Message, maxSeq uint64) error {
|
||||
messageRef := message.ProtoReflect()
|
||||
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 {
|
||||
return t.customJSONValidator(message)
|
||||
}
|
||||
|
||||
return DefaultJSONValidator(message)
|
||||
})
|
||||
}
|
||||
|
||||
func (t autoIncrementTable) ImportJSON(ctx context.Context, reader io.Reader) error {
|
||||
backend, err := t.getWriteBackend(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return t.decodeAutoIncJSON(backend, reader, func(message proto.Message, maxSeq uint64) error {
|
||||
messageRef := message.ProtoReflect()
|
||||
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
|
||||
}
|
||||
|
||||
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 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 primary keys.
|
||||
return t.tableImpl.save(ctx, backend, message, saveModeInsert)
|
||||
})
|
||||
}
|
||||
|
||||
func (t autoIncrementTable) decodeAutoIncJSON(backend Backend, reader io.Reader, onMsg func(message proto.Message, maxID uint64) error) error {
|
||||
decoder, err := t.startDecodeJSON(reader)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var seq uint64
|
||||
|
||||
return t.doDecodeJSON(decoder,
|
||||
func(message json.RawMessage) bool {
|
||||
err = json.Unmarshal(message, &seq)
|
||||
if err == nil {
|
||||
// writer is nil during validation
|
||||
if backend != nil {
|
||||
writer := newBatchIndexCommitmentWriter(backend)
|
||||
defer writer.Close()
|
||||
err = t.setSeqValue(writer.IndexStore(), seq)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = writer.Write()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
},
|
||||
func(message proto.Message) error {
|
||||
return onMsg(message, seq)
|
||||
})
|
||||
}
|
||||
|
||||
func (t autoIncrementTable) ExportJSON(ctx context.Context, writer io.Writer) error {
|
||||
backend, err := t.getBackend(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = writer.Write([]byte("["))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
seq, err := t.curSeqValue(backend.IndexStoreReader())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
start := true
|
||||
if seq != 0 {
|
||||
start = false
|
||||
bz, err := json.Marshal(seq)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = writer.Write(bz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return t.doExportJSON(ctx, writer, start)
|
||||
}
|
||||
|
||||
func (t *autoIncrementTable) GetTable(message proto.Message) Table {
|
||||
if message.ProtoReflect().Descriptor().FullName() == t.MessageType().Descriptor().FullName() {
|
||||
return t
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ AutoIncrementTable = &autoIncrementTable{}
|
||||
@ -1,289 +0,0 @@
|
||||
package ormtable
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/reflect/protoregistry"
|
||||
|
||||
ormv1 "cosmossdk.io/api/cosmos/orm/v1"
|
||||
"cosmossdk.io/orm/encoding/encodeutil"
|
||||
"cosmossdk.io/orm/encoding/ormkv"
|
||||
"cosmossdk.io/orm/internal/fieldnames"
|
||||
"cosmossdk.io/orm/types/ormerrors"
|
||||
)
|
||||
|
||||
const (
|
||||
primaryKeyID uint32 = 0
|
||||
indexIDLimit uint32 = 32768
|
||||
seqID = indexIDLimit
|
||||
)
|
||||
|
||||
// Options are options for building a Table.
|
||||
type Options struct {
|
||||
// Prefix is an optional prefix used to build the table's prefix.
|
||||
Prefix []byte
|
||||
|
||||
// MessageType is the protobuf message type of the table.
|
||||
MessageType protoreflect.MessageType
|
||||
|
||||
// TableDescriptor is an optional table descriptor to be explicitly used
|
||||
// with the table. Generally this should be nil and the table descriptor
|
||||
// should be pulled from the table message option. TableDescriptor
|
||||
// cannot be used together with SingletonDescriptor.
|
||||
TableDescriptor *ormv1.TableDescriptor
|
||||
|
||||
// SingletonDescriptor is an optional singleton descriptor to be explicitly used.
|
||||
// Generally this should be nil and the table descriptor
|
||||
// should be pulled from the singleton message option. SingletonDescriptor
|
||||
// cannot be used together with TableDescriptor.
|
||||
SingletonDescriptor *ormv1.SingletonDescriptor
|
||||
|
||||
// TypeResolver is an optional type resolver to be used when unmarshaling
|
||||
// protobuf messages.
|
||||
TypeResolver TypeResolver
|
||||
|
||||
// JSONValidator is an optional validator that can be used for validating
|
||||
// messaging when using ValidateJSON. If it is nil, DefaultJSONValidator
|
||||
// will be used
|
||||
JSONValidator func(proto.Message) error
|
||||
|
||||
// BackendResolver is an optional function which retrieves a Backend from the context.
|
||||
// If it is nil, the default behavior will be to attempt to retrieve a
|
||||
// backend using the method that WrapContextDefault uses. This method
|
||||
// can be used to implement things like "store keys" which would allow a
|
||||
// table to only be used with a specific backend and to hide direct
|
||||
// access to the backend other than through the table interface.
|
||||
// Mutating operations will attempt to cast ReadBackend to Backend and
|
||||
// will return an error if that fails.
|
||||
BackendResolver BackendResolver
|
||||
}
|
||||
|
||||
// TypeResolver is an interface that can be used for the protoreflect.UnmarshalOptions.Resolver option.
|
||||
type TypeResolver interface {
|
||||
protoregistry.MessageTypeResolver
|
||||
protoregistry.ExtensionTypeResolver
|
||||
}
|
||||
|
||||
// Build builds a Table instance from the provided Options.
|
||||
func Build(options Options) (Table, error) {
|
||||
messageDescriptor := options.MessageType.Descriptor()
|
||||
|
||||
backendResolver := options.BackendResolver
|
||||
if backendResolver == nil {
|
||||
backendResolver = getBackendDefault
|
||||
}
|
||||
|
||||
table := &tableImpl{
|
||||
primaryKeyIndex: &primaryKeyIndex{
|
||||
indexers: []indexer{},
|
||||
getBackend: backendResolver,
|
||||
},
|
||||
indexes: []Index{},
|
||||
indexesByFields: map[fieldnames.FieldNames]concreteIndex{},
|
||||
uniqueIndexesByFields: map[fieldnames.FieldNames]UniqueIndex{},
|
||||
entryCodecsByID: map[uint32]ormkv.EntryCodec{},
|
||||
indexesByID: map[uint32]Index{},
|
||||
typeResolver: options.TypeResolver,
|
||||
customJSONValidator: options.JSONValidator,
|
||||
}
|
||||
|
||||
pkIndex := table.primaryKeyIndex
|
||||
|
||||
tableDesc := options.TableDescriptor
|
||||
if tableDesc == nil {
|
||||
tableDesc = proto.GetExtension(messageDescriptor.Options(), ormv1.E_Table).(*ormv1.TableDescriptor)
|
||||
}
|
||||
|
||||
singletonDesc := options.SingletonDescriptor
|
||||
if singletonDesc == nil {
|
||||
singletonDesc = proto.GetExtension(messageDescriptor.Options(), ormv1.E_Singleton).(*ormv1.SingletonDescriptor)
|
||||
}
|
||||
|
||||
switch {
|
||||
case tableDesc != nil:
|
||||
if singletonDesc != nil {
|
||||
return nil, ormerrors.InvalidTableDefinition.Wrapf("message %s cannot be declared as both a table and a singleton", messageDescriptor.FullName())
|
||||
}
|
||||
case singletonDesc != nil:
|
||||
if singletonDesc.Id == 0 {
|
||||
return nil, ormerrors.InvalidTableId.Wrapf("%s", messageDescriptor.FullName())
|
||||
}
|
||||
|
||||
prefix := encodeutil.AppendVarUInt32(options.Prefix, singletonDesc.Id)
|
||||
pkCodec, err := ormkv.NewPrimaryKeyCodec(
|
||||
prefix,
|
||||
options.MessageType,
|
||||
nil,
|
||||
proto.UnmarshalOptions{Resolver: options.TypeResolver},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pkIndex.PrimaryKeyCodec = pkCodec
|
||||
table.tablePrefix = prefix
|
||||
table.tableID = singletonDesc.Id
|
||||
|
||||
return &singleton{table}, nil
|
||||
default:
|
||||
return nil, ormerrors.NoTableDescriptor.Wrapf("missing table descriptor for %s", messageDescriptor.FullName())
|
||||
}
|
||||
|
||||
tableID := tableDesc.Id
|
||||
if tableID == 0 {
|
||||
return nil, ormerrors.InvalidTableId.Wrapf("table %s", messageDescriptor.FullName())
|
||||
}
|
||||
|
||||
prefix := options.Prefix
|
||||
prefix = encodeutil.AppendVarUInt32(prefix, tableID)
|
||||
table.tablePrefix = prefix
|
||||
table.tableID = tableID
|
||||
|
||||
if tableDesc.PrimaryKey == nil {
|
||||
return nil, ormerrors.MissingPrimaryKey.Wrap(string(messageDescriptor.FullName()))
|
||||
}
|
||||
|
||||
pkFields := fieldnames.CommaSeparatedFieldNames(tableDesc.PrimaryKey.Fields)
|
||||
table.primaryKeyIndex.fields = pkFields
|
||||
pkFieldNames := pkFields.Names()
|
||||
if len(pkFieldNames) == 0 {
|
||||
return nil, ormerrors.InvalidTableDefinition.Wrapf("empty primary key fields for %s", messageDescriptor.FullName())
|
||||
}
|
||||
|
||||
pkPrefix := encodeutil.AppendVarUInt32(prefix, primaryKeyID)
|
||||
pkCodec, err := ormkv.NewPrimaryKeyCodec(
|
||||
pkPrefix,
|
||||
options.MessageType,
|
||||
pkFieldNames,
|
||||
proto.UnmarshalOptions{Resolver: options.TypeResolver},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pkIndex.PrimaryKeyCodec = pkCodec
|
||||
table.indexesByFields[pkFields] = pkIndex
|
||||
table.uniqueIndexesByFields[pkFields] = pkIndex
|
||||
table.entryCodecsByID[primaryKeyID] = pkIndex
|
||||
table.indexesByID[primaryKeyID] = pkIndex
|
||||
table.indexes = append(table.indexes, pkIndex)
|
||||
|
||||
for _, idxDesc := range tableDesc.Index {
|
||||
id := idxDesc.Id
|
||||
if id == 0 || id >= indexIDLimit {
|
||||
return nil, ormerrors.InvalidIndexId.Wrapf("index on table %s with fields %s, invalid id %d", messageDescriptor.FullName(), idxDesc.Fields, id)
|
||||
}
|
||||
|
||||
if _, ok := table.entryCodecsByID[id]; ok {
|
||||
return nil, ormerrors.DuplicateIndexId.Wrapf("id %d on table %s", id, messageDescriptor.FullName())
|
||||
}
|
||||
|
||||
idxFields := fieldnames.CommaSeparatedFieldNames(idxDesc.Fields)
|
||||
idxPrefix := encodeutil.AppendVarUInt32(prefix, id)
|
||||
var index concreteIndex
|
||||
|
||||
// altNames contains all the alternative "names" of this index
|
||||
altNames := map[fieldnames.FieldNames]bool{idxFields: true}
|
||||
|
||||
if idxDesc.Unique && isNonTrivialUniqueKey(idxFields.Names(), pkFieldNames) {
|
||||
uniqCdc, err := ormkv.NewUniqueKeyCodec(
|
||||
idxPrefix,
|
||||
options.MessageType,
|
||||
idxFields.Names(),
|
||||
pkFieldNames,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
uniqIdx := &uniqueKeyIndex{
|
||||
UniqueKeyCodec: uniqCdc,
|
||||
fields: idxFields,
|
||||
primaryKey: pkIndex,
|
||||
getReadBackend: backendResolver,
|
||||
}
|
||||
table.uniqueIndexesByFields[idxFields] = uniqIdx
|
||||
index = uniqIdx
|
||||
} else {
|
||||
idxCdc, err := ormkv.NewIndexKeyCodec(
|
||||
idxPrefix,
|
||||
options.MessageType,
|
||||
idxFields.Names(),
|
||||
pkFieldNames,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
index = &indexKeyIndex{
|
||||
IndexKeyCodec: idxCdc,
|
||||
fields: idxFields,
|
||||
primaryKey: pkIndex,
|
||||
getReadBackend: backendResolver,
|
||||
}
|
||||
|
||||
// non-unique indexes can sometimes be named by several sub-lists of
|
||||
// fields and we need to handle all of them. For example consider,
|
||||
// a primary key for fields "a,b,c" and an index on field "c". Because the
|
||||
// rest of the primary key gets appended to the index key, the index for "c"
|
||||
// is actually stored as "c,a,b". So this index can be referred to
|
||||
// by the fields "c", "c,a", or "c,a,b".
|
||||
allFields := index.GetFieldNames()
|
||||
allFieldNames := fieldnames.FieldsFromNames(allFields)
|
||||
altNames[allFieldNames] = true
|
||||
for i := 1; i < len(allFields); i++ {
|
||||
altName := fieldnames.FieldsFromNames(allFields[:i])
|
||||
if altNames[altName] {
|
||||
continue
|
||||
}
|
||||
|
||||
// we check by generating a codec for each sub-list of fields,
|
||||
// then we see if the full list of fields matches.
|
||||
altIdxCdc, err := ormkv.NewIndexKeyCodec(
|
||||
idxPrefix,
|
||||
options.MessageType,
|
||||
allFields[:i],
|
||||
pkFieldNames,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if fieldnames.FieldsFromNames(altIdxCdc.GetFieldNames()) == allFieldNames {
|
||||
altNames[altName] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for name := range altNames {
|
||||
if _, ok := table.indexesByFields[name]; ok {
|
||||
return nil, fmt.Errorf("duplicate index for fields %s", name)
|
||||
}
|
||||
|
||||
table.indexesByFields[name] = index
|
||||
}
|
||||
|
||||
table.entryCodecsByID[id] = index
|
||||
table.indexesByID[id] = index
|
||||
table.indexes = append(table.indexes, index)
|
||||
table.indexers = append(table.indexers, index.(indexer))
|
||||
}
|
||||
|
||||
if tableDesc.PrimaryKey.AutoIncrement {
|
||||
autoIncField := pkCodec.GetFieldDescriptors()[0]
|
||||
if len(pkFieldNames) != 1 && autoIncField.Kind() != protoreflect.Uint64Kind {
|
||||
return nil, ormerrors.InvalidAutoIncrementKey.Wrapf("field %s", autoIncField.FullName())
|
||||
}
|
||||
|
||||
seqPrefix := encodeutil.AppendVarUInt32(prefix, seqID)
|
||||
seqCodec := ormkv.NewSeqCodec(options.MessageType, seqPrefix)
|
||||
table.entryCodecsByID[seqID] = seqCodec
|
||||
return &autoIncrementTable{
|
||||
tableImpl: table,
|
||||
autoIncField: autoIncField,
|
||||
seqCodec: seqCodec,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return table, nil
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
// Package ormtable defines the interfaces and implementations of tables and
|
||||
// indexes.
|
||||
package ormtable
|
||||
@ -1,103 +0,0 @@
|
||||
package ormtable_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"google.golang.org/protobuf/types/known/durationpb"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
"cosmossdk.io/orm/internal/testkv"
|
||||
"cosmossdk.io/orm/internal/testpb"
|
||||
"cosmossdk.io/orm/model/ormtable"
|
||||
)
|
||||
|
||||
func TestDurationIndex(t *testing.T) {
|
||||
table, err := ormtable.Build(ormtable.Options{
|
||||
MessageType: (&testpb.ExampleDuration{}).ProtoReflect().Type(),
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
backend := testkv.NewDebugBackend(testkv.NewSplitMemBackend(), &testkv.EntryCodecDebugger{
|
||||
EntryCodec: table,
|
||||
})
|
||||
ctx := ormtable.WrapContextDefault(backend)
|
||||
store, err := testpb.NewExampleDurationTable(table)
|
||||
assert.NilError(t, err)
|
||||
|
||||
neg, err := time.ParseDuration("-1h")
|
||||
assert.NilError(t, err)
|
||||
zero, err := time.ParseDuration("0")
|
||||
assert.NilError(t, err)
|
||||
pos, err := time.ParseDuration("11000ms")
|
||||
assert.NilError(t, err)
|
||||
|
||||
negPb, zeroPb, posPb := durationpb.New(neg), durationpb.New(zero), durationpb.New(pos)
|
||||
durOrder := []*durationpb.Duration{negPb, zeroPb, posPb}
|
||||
|
||||
assert.NilError(t, store.Insert(ctx, &testpb.ExampleDuration{
|
||||
Name: "foo",
|
||||
Dur: negPb,
|
||||
}))
|
||||
assert.NilError(t, store.Insert(ctx, &testpb.ExampleDuration{
|
||||
Name: "bar",
|
||||
Dur: zeroPb,
|
||||
}))
|
||||
assert.NilError(t, store.Insert(ctx, &testpb.ExampleDuration{
|
||||
Name: "baz",
|
||||
Dur: posPb,
|
||||
}))
|
||||
|
||||
from, to := testpb.ExampleDurationDurIndexKey{}.WithDur(durationpb.New(neg)),
|
||||
testpb.ExampleDurationDurIndexKey{}.WithDur(durationpb.New(pos))
|
||||
it, err := store.ListRange(ctx, from, to)
|
||||
assert.NilError(t, err)
|
||||
|
||||
i := 0
|
||||
for it.Next() {
|
||||
v, err := it.Value()
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, durOrder[i].String(), v.Dur.String())
|
||||
i++
|
||||
}
|
||||
|
||||
// insert a nil entry
|
||||
id, err := store.InsertReturningId(ctx, &testpb.ExampleDuration{
|
||||
Name: "nil",
|
||||
Dur: nil,
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
|
||||
res, err := store.Get(ctx, id)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, res.Dur == nil)
|
||||
|
||||
it, err = store.List(ctx, testpb.ExampleDurationDurIndexKey{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
// make sure nils are ordered last
|
||||
durOrder = append(durOrder, nil)
|
||||
i = 0
|
||||
for it.Next() {
|
||||
v, err := it.Value()
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, v != nil)
|
||||
x := durOrder[i]
|
||||
if x == nil {
|
||||
assert.Assert(t, v.Dur == nil)
|
||||
} else {
|
||||
assert.Equal(t, x.String(), v.Dur.String())
|
||||
}
|
||||
i++
|
||||
}
|
||||
it.Close()
|
||||
|
||||
// try iterating over just nil timestamps
|
||||
it, err = store.List(ctx, testpb.ExampleDurationDurIndexKey{}.WithDur(nil))
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, it.Next())
|
||||
res, err = it.Value()
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, res.Dur == nil)
|
||||
assert.Assert(t, !it.Next())
|
||||
it.Close()
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
package ormtable
|
||||
|
||||
import "google.golang.org/protobuf/proto"
|
||||
|
||||
type filterIterator struct {
|
||||
Iterator
|
||||
filter func(proto.Message) bool
|
||||
msg proto.Message
|
||||
}
|
||||
|
||||
func (f *filterIterator) Next() bool {
|
||||
for f.Iterator.Next() {
|
||||
msg, err := f.Iterator.GetMessage()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if f.filter(msg) {
|
||||
f.msg = msg
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (f filterIterator) GetMessage() (proto.Message, error) {
|
||||
return f.msg, nil
|
||||
}
|
||||
@ -1,78 +0,0 @@
|
||||
package ormtable
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
|
||||
"cosmossdk.io/orm/encoding/ormkv"
|
||||
"cosmossdk.io/orm/model/ormlist"
|
||||
"cosmossdk.io/orm/types/kv"
|
||||
)
|
||||
|
||||
// Index defines an index on a table. Index instances
|
||||
// are stateless, with all state existing only in the store passed
|
||||
// to index methods.
|
||||
type Index interface {
|
||||
// List does iteration over the index with the provided prefix key and options.
|
||||
// Prefix key values must correspond in type to the index's fields and the
|
||||
// number of values provided cannot exceed the number of fields in the index,
|
||||
// although fewer values can be provided.
|
||||
List(ctx context.Context, prefixKey []interface{}, options ...ormlist.Option) (Iterator, error)
|
||||
|
||||
// ListRange does range iteration over the index with the provided from and to
|
||||
// values and options.
|
||||
//
|
||||
// From and to values must correspond in type to the index's fields and the number of values
|
||||
// provided cannot exceed the number of fields in the index, although fewer
|
||||
// values can be provided.
|
||||
//
|
||||
// Range iteration can only be done for from and to values which are
|
||||
// well-ordered, meaning that any unordered components must be equal. Ex.
|
||||
// the bytes type is considered unordered, so a range iterator is created
|
||||
// over an index with a bytes field, both start and end must have the same
|
||||
// value for bytes.
|
||||
//
|
||||
// Range iteration is inclusive at both ends.
|
||||
ListRange(ctx context.Context, from, to []interface{}, options ...ormlist.Option) (Iterator, error)
|
||||
|
||||
// DeleteBy deletes any entries which match the provided prefix key.
|
||||
DeleteBy(context context.Context, prefixKey ...interface{}) error
|
||||
|
||||
// DeleteRange deletes any entries between the provided range keys.
|
||||
DeleteRange(context context.Context, from, to []interface{}) error
|
||||
|
||||
// MessageType returns the protobuf message type of the index.
|
||||
MessageType() protoreflect.MessageType
|
||||
|
||||
// Fields returns the canonical field names of the index.
|
||||
Fields() string
|
||||
|
||||
doNotImplement()
|
||||
}
|
||||
|
||||
// concreteIndex is used internally by table implementations.
|
||||
type concreteIndex interface {
|
||||
Index
|
||||
ormkv.IndexCodec
|
||||
|
||||
readValueFromIndexKey(context ReadBackend, primaryKey []protoreflect.Value, value []byte, message proto.Message) error
|
||||
}
|
||||
|
||||
// UniqueIndex defines an unique index on a table.
|
||||
type UniqueIndex interface {
|
||||
Index
|
||||
|
||||
// Has returns true if the key values are present in the store for this index.
|
||||
Has(context context.Context, keyValues ...interface{}) (found bool, err error)
|
||||
|
||||
// Get retrieves the message if one exists for the provided key values.
|
||||
Get(context context.Context, message proto.Message, keyValues ...interface{}) (found bool, err error)
|
||||
}
|
||||
|
||||
type indexer interface {
|
||||
onInsert(store kv.Store, message protoreflect.Message) error
|
||||
onUpdate(store kv.Store, new, existing protoreflect.Message) error
|
||||
onDelete(store kv.Store, message protoreflect.Message) error
|
||||
}
|
||||
@ -1,121 +0,0 @@
|
||||
package ormtable
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
|
||||
"cosmossdk.io/orm/encoding/ormkv"
|
||||
"cosmossdk.io/orm/internal/fieldnames"
|
||||
"cosmossdk.io/orm/model/ormlist"
|
||||
"cosmossdk.io/orm/types/kv"
|
||||
"cosmossdk.io/orm/types/ormerrors"
|
||||
)
|
||||
|
||||
// indexKeyIndex implements Index for a regular IndexKey.
|
||||
type indexKeyIndex struct {
|
||||
*ormkv.IndexKeyCodec
|
||||
fields fieldnames.FieldNames
|
||||
primaryKey *primaryKeyIndex
|
||||
getReadBackend func(context.Context) (ReadBackend, error)
|
||||
}
|
||||
|
||||
func (i indexKeyIndex) DeleteBy(ctx context.Context, keyValues ...interface{}) error {
|
||||
it, err := i.List(ctx, keyValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return i.primaryKey.deleteByIterator(ctx, it)
|
||||
}
|
||||
|
||||
func (i indexKeyIndex) DeleteRange(ctx context.Context, from, to []interface{}) error {
|
||||
it, err := i.ListRange(ctx, from, to)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return i.primaryKey.deleteByIterator(ctx, it)
|
||||
}
|
||||
|
||||
func (i indexKeyIndex) List(ctx context.Context, prefixKey []interface{}, options ...ormlist.Option) (Iterator, error) {
|
||||
backend, err := i.getReadBackend(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return prefixIterator(backend.IndexStoreReader(), backend, i, i.KeyCodec, prefixKey, options)
|
||||
}
|
||||
|
||||
func (i indexKeyIndex) ListRange(ctx context.Context, from, to []interface{}, options ...ormlist.Option) (Iterator, error) {
|
||||
backend, err := i.getReadBackend(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rangeIterator(backend.IndexStoreReader(), backend, i, i.KeyCodec, from, to, options)
|
||||
}
|
||||
|
||||
var (
|
||||
_ indexer = &indexKeyIndex{}
|
||||
_ Index = &indexKeyIndex{}
|
||||
)
|
||||
|
||||
func (i indexKeyIndex) doNotImplement() {}
|
||||
|
||||
func (i indexKeyIndex) onInsert(store kv.Store, message protoreflect.Message) error {
|
||||
k, v, err := i.EncodeKVFromMessage(message)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return store.Set(k, v)
|
||||
}
|
||||
|
||||
func (i indexKeyIndex) onUpdate(store kv.Store, new, existing protoreflect.Message) error {
|
||||
newValues := i.GetKeyValues(new)
|
||||
existingValues := i.GetKeyValues(existing)
|
||||
if i.CompareKeys(newValues, existingValues) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
existingKey, err := i.EncodeKey(existingValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = store.Delete(existingKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
newKey, err := i.EncodeKey(newValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return store.Set(newKey, []byte{})
|
||||
}
|
||||
|
||||
func (i indexKeyIndex) onDelete(store kv.Store, message protoreflect.Message) error {
|
||||
_, key, err := i.EncodeKeyFromMessage(message)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return store.Delete(key)
|
||||
}
|
||||
|
||||
func (i indexKeyIndex) readValueFromIndexKey(backend ReadBackend, primaryKey []protoreflect.Value, _ []byte, message proto.Message) error {
|
||||
found, err := i.primaryKey.get(backend, message, primaryKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !found {
|
||||
return ormerrors.UnexpectedError.Wrapf("can't find primary key")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i indexKeyIndex) Fields() string {
|
||||
return i.fields.String()
|
||||
}
|
||||
@ -1,96 +0,0 @@
|
||||
package ormtable
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
queryv1beta1 "cosmossdk.io/api/cosmos/base/query/v1beta1"
|
||||
"cosmossdk.io/orm/internal/listinternal"
|
||||
)
|
||||
|
||||
func paginate(it Iterator, options *listinternal.Options) Iterator {
|
||||
offset := int(options.Offset)
|
||||
limit := int(options.Limit)
|
||||
if limit == 0 {
|
||||
limit = int(options.DefaultLimit)
|
||||
}
|
||||
|
||||
i := 0
|
||||
if offset != 0 {
|
||||
for ; i < offset; i++ {
|
||||
if !it.Next() {
|
||||
return &paginationIterator{
|
||||
Iterator: it,
|
||||
pageRes: &queryv1beta1.PageResponse{Total: uint64(i)},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var done int
|
||||
if limit != 0 {
|
||||
done = limit + offset
|
||||
} else {
|
||||
done = math.MaxInt
|
||||
}
|
||||
|
||||
return &paginationIterator{
|
||||
Iterator: it,
|
||||
pageRes: nil,
|
||||
countTotal: options.CountTotal,
|
||||
i: i,
|
||||
done: done,
|
||||
}
|
||||
}
|
||||
|
||||
type paginationIterator struct {
|
||||
Iterator
|
||||
pageRes *queryv1beta1.PageResponse
|
||||
countTotal bool
|
||||
i int
|
||||
done int
|
||||
}
|
||||
|
||||
func (it *paginationIterator) Next() bool {
|
||||
if it.i >= it.done {
|
||||
it.pageRes = &queryv1beta1.PageResponse{}
|
||||
cursor := it.Cursor()
|
||||
next := it.Iterator.Next()
|
||||
if next {
|
||||
it.pageRes.NextKey = cursor
|
||||
it.i++
|
||||
}
|
||||
if it.countTotal {
|
||||
// once it.Iterator.Next() returns false, another call to it will panic.
|
||||
// we check next here to ensure we do not call it again.
|
||||
if next {
|
||||
for {
|
||||
if !it.Iterator.Next() {
|
||||
it.pageRes.Total = uint64(it.i)
|
||||
return false
|
||||
}
|
||||
it.i++
|
||||
}
|
||||
} else {
|
||||
// when next is false, the iterator can no longer move forward,
|
||||
// so the index == total entries.
|
||||
it.pageRes.Total = uint64(it.i)
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
ok := it.Iterator.Next()
|
||||
if ok {
|
||||
it.i++
|
||||
return true
|
||||
}
|
||||
|
||||
it.pageRes = &queryv1beta1.PageResponse{
|
||||
Total: uint64(it.i),
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (it paginationIterator) PageResponse() *queryv1beta1.PageResponse {
|
||||
return it.pageRes
|
||||
}
|
||||
@ -1,240 +0,0 @@
|
||||
package ormtable
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
|
||||
"cosmossdk.io/orm/encoding/encodeutil"
|
||||
"cosmossdk.io/orm/encoding/ormkv"
|
||||
"cosmossdk.io/orm/internal/fieldnames"
|
||||
"cosmossdk.io/orm/model/ormlist"
|
||||
"cosmossdk.io/orm/types/ormerrors"
|
||||
)
|
||||
|
||||
// primaryKeyIndex defines an UniqueIndex for the primary key.
|
||||
type primaryKeyIndex struct {
|
||||
*ormkv.PrimaryKeyCodec
|
||||
fields fieldnames.FieldNames
|
||||
indexers []indexer
|
||||
getBackend func(context.Context) (ReadBackend, error)
|
||||
}
|
||||
|
||||
func (p primaryKeyIndex) List(ctx context.Context, prefixKey []interface{}, options ...ormlist.Option) (Iterator, error) {
|
||||
backend, err := p.getBackend(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return prefixIterator(backend.CommitmentStoreReader(), backend, p, p.KeyCodec, prefixKey, options)
|
||||
}
|
||||
|
||||
func (p primaryKeyIndex) ListRange(ctx context.Context, from, to []interface{}, options ...ormlist.Option) (Iterator, error) {
|
||||
backend, err := p.getBackend(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rangeIterator(backend.CommitmentStoreReader(), backend, p, p.KeyCodec, from, to, options)
|
||||
}
|
||||
|
||||
func (p primaryKeyIndex) doNotImplement() {}
|
||||
|
||||
func (p primaryKeyIndex) Has(ctx context.Context, key ...interface{}) (found bool, err error) {
|
||||
backend, err := p.getBackend(ctx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return p.has(backend, encodeutil.ValuesOf(key...))
|
||||
}
|
||||
|
||||
func (p primaryKeyIndex) has(backend ReadBackend, values []protoreflect.Value) (found bool, err error) {
|
||||
keyBz, err := p.EncodeKey(values)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return backend.CommitmentStoreReader().Has(keyBz)
|
||||
}
|
||||
|
||||
func (p primaryKeyIndex) Get(ctx context.Context, message proto.Message, values ...interface{}) (found bool, err error) {
|
||||
backend, err := p.getBackend(ctx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return p.get(backend, message, encodeutil.ValuesOf(values...))
|
||||
}
|
||||
|
||||
func (p primaryKeyIndex) get(backend ReadBackend, message proto.Message, values []protoreflect.Value) (found bool, err error) {
|
||||
key, err := p.EncodeKey(values)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return p.getByKeyBytes(backend, key, values, message)
|
||||
}
|
||||
|
||||
func (p primaryKeyIndex) DeleteBy(ctx context.Context, primaryKeyValues ...interface{}) error {
|
||||
if len(primaryKeyValues) == len(p.GetFieldNames()) {
|
||||
return p.doDelete(ctx, encodeutil.ValuesOf(primaryKeyValues...))
|
||||
}
|
||||
|
||||
it, err := p.List(ctx, primaryKeyValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return p.deleteByIterator(ctx, it)
|
||||
}
|
||||
|
||||
func (p primaryKeyIndex) DeleteRange(ctx context.Context, from, to []interface{}) error {
|
||||
it, err := p.ListRange(ctx, from, to)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return p.deleteByIterator(ctx, it)
|
||||
}
|
||||
|
||||
func (p primaryKeyIndex) getWriteBackend(ctx context.Context) (Backend, error) {
|
||||
backend, err := p.getBackend(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if writeBackend, ok := backend.(Backend); ok {
|
||||
return writeBackend, nil
|
||||
}
|
||||
|
||||
return nil, ormerrors.ReadOnly
|
||||
}
|
||||
|
||||
func (p primaryKeyIndex) doDelete(ctx context.Context, primaryKeyValues []protoreflect.Value) error {
|
||||
backend, err := p.getWriteBackend(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// delete object
|
||||
writer := newBatchIndexCommitmentWriter(backend)
|
||||
defer writer.Close()
|
||||
|
||||
pk, err := p.EncodeKey(primaryKeyValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msg := p.MessageType().New().Interface()
|
||||
found, err := p.getByKeyBytes(backend, pk, primaryKeyValues, msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !found {
|
||||
return nil
|
||||
}
|
||||
|
||||
err = p.doDeleteWithWriteBatch(ctx, backend, writer, pk, msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return writer.Write()
|
||||
}
|
||||
|
||||
func (p primaryKeyIndex) doDeleteWithWriteBatch(ctx context.Context, backend Backend, writer *batchIndexCommitmentWriter, primaryKeyBz []byte, message proto.Message) error {
|
||||
if hooks := backend.ValidateHooks(); hooks != nil {
|
||||
err := hooks.ValidateDelete(ctx, message)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// delete object
|
||||
err := writer.CommitmentStore().Delete(primaryKeyBz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// clear indexes
|
||||
mref := message.ProtoReflect()
|
||||
indexStoreWriter := writer.IndexStore()
|
||||
for _, idx := range p.indexers {
|
||||
err := idx.onDelete(indexStoreWriter, mref)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if writeHooks := backend.WriteHooks(); writeHooks != nil {
|
||||
writer.enqueueHook(func() {
|
||||
writeHooks.OnDelete(ctx, message)
|
||||
})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p primaryKeyIndex) getByKeyBytes(store ReadBackend, key []byte, keyValues []protoreflect.Value, message proto.Message) (found bool, err error) {
|
||||
bz, err := store.CommitmentStoreReader().Get(key)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if bz == nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return true, p.Unmarshal(keyValues, bz, message)
|
||||
}
|
||||
|
||||
func (p primaryKeyIndex) readValueFromIndexKey(_ ReadBackend, primaryKey []protoreflect.Value, value []byte, message proto.Message) error {
|
||||
return p.Unmarshal(primaryKey, value, message)
|
||||
}
|
||||
|
||||
func (p primaryKeyIndex) Fields() string {
|
||||
return p.fields.String()
|
||||
}
|
||||
|
||||
func (p primaryKeyIndex) deleteByIterator(ctx context.Context, it Iterator) error {
|
||||
backend, err := p.getWriteBackend(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// we batch writes while the iterator is still open
|
||||
writer := newBatchIndexCommitmentWriter(backend)
|
||||
defer writer.Close()
|
||||
|
||||
for it.Next() {
|
||||
_, pk, err := it.Keys()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msg, err := it.GetMessage()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pkBz, err := p.EncodeKey(pk)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = p.doDeleteWithWriteBatch(ctx, backend, writer, pkBz, msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// close iterator
|
||||
it.Close()
|
||||
// then write batch
|
||||
return writer.Write()
|
||||
}
|
||||
|
||||
var _ UniqueIndex = &primaryKeyIndex{}
|
||||
@ -1,68 +0,0 @@
|
||||
package ormtable_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/regen-network/gocuke"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
"cosmossdk.io/orm/internal/testpb"
|
||||
"cosmossdk.io/orm/model/ormtable"
|
||||
"cosmossdk.io/orm/testing/ormtest"
|
||||
)
|
||||
|
||||
func TestSave(t *testing.T) {
|
||||
gocuke.NewRunner(t, &suite{}).Path("../../features/table/saving.feature").Run()
|
||||
}
|
||||
|
||||
type suite struct {
|
||||
gocuke.TestingT
|
||||
table ormtable.Table
|
||||
ctx context.Context
|
||||
err error
|
||||
}
|
||||
|
||||
func (s *suite) Before() {
|
||||
var err error
|
||||
s.table, err = ormtable.Build(ormtable.Options{
|
||||
MessageType: (&testpb.SimpleExample{}).ProtoReflect().Type(),
|
||||
})
|
||||
assert.NilError(s, err)
|
||||
s.ctx = ormtable.WrapContextDefault(ormtest.NewMemoryBackend())
|
||||
}
|
||||
|
||||
func (s *suite) AnExistingEntity(docString gocuke.DocString) {
|
||||
existing := s.simpleExampleFromDocString(docString)
|
||||
assert.NilError(s, s.table.Insert(s.ctx, existing))
|
||||
}
|
||||
|
||||
func (s suite) simpleExampleFromDocString(docString gocuke.DocString) *testpb.SimpleExample {
|
||||
ex := &testpb.SimpleExample{}
|
||||
assert.NilError(s, protojson.Unmarshal([]byte(docString.Content), ex))
|
||||
return ex
|
||||
}
|
||||
|
||||
func (s *suite) IInsert(a gocuke.DocString) {
|
||||
ex := s.simpleExampleFromDocString(a)
|
||||
s.err = s.table.Insert(s.ctx, ex)
|
||||
}
|
||||
|
||||
func (s *suite) IUpdate(a gocuke.DocString) {
|
||||
ex := s.simpleExampleFromDocString(a)
|
||||
s.err = s.table.Update(s.ctx, ex)
|
||||
}
|
||||
|
||||
func (s *suite) ExpectAError(a string) {
|
||||
assert.ErrorContains(s, s.err, a)
|
||||
}
|
||||
|
||||
func (s *suite) ExpectGrpcErrorCode(a string) {
|
||||
var code codes.Code
|
||||
assert.NilError(s, code.UnmarshalJSON([]byte(fmt.Sprintf("%q", a))))
|
||||
assert.Equal(s, code, status.Code(s.err))
|
||||
}
|
||||
@ -1,101 +0,0 @@
|
||||
package ormtable
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// singleton implements a Table instance for singletons.
|
||||
type singleton struct {
|
||||
*tableImpl
|
||||
}
|
||||
|
||||
func (t singleton) DefaultJSON() json.RawMessage {
|
||||
msg := t.MessageType().New().Interface()
|
||||
bz, err := t.jsonMarshalOptions().Marshal(msg)
|
||||
if err != nil {
|
||||
return json.RawMessage("{}")
|
||||
}
|
||||
return bz
|
||||
}
|
||||
|
||||
func (t singleton) ValidateJSON(reader io.Reader) error {
|
||||
bz, err := io.ReadAll(reader)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msg := t.MessageType().New().Interface()
|
||||
err = protojson.Unmarshal(bz, msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if t.customJSONValidator != nil {
|
||||
return t.customJSONValidator(msg)
|
||||
}
|
||||
|
||||
return DefaultJSONValidator(msg)
|
||||
}
|
||||
|
||||
func (t singleton) ImportJSON(ctx context.Context, reader io.Reader) error {
|
||||
backend, err := t.getWriteBackend(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
bz, err := io.ReadAll(reader)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msg := t.MessageType().New().Interface()
|
||||
err = protojson.Unmarshal(bz, msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return t.save(ctx, backend, msg, saveModeDefault)
|
||||
}
|
||||
|
||||
func (t singleton) ExportJSON(ctx context.Context, writer io.Writer) error {
|
||||
msg := t.MessageType().New().Interface()
|
||||
found, err := t.Get(ctx, msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var bz []byte
|
||||
if !found {
|
||||
bz = t.DefaultJSON()
|
||||
} else {
|
||||
bz, err = t.jsonMarshalOptions().Marshal(msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
_, err = writer.Write(bz)
|
||||
return err
|
||||
}
|
||||
|
||||
func (t singleton) jsonMarshalOptions() protojson.MarshalOptions {
|
||||
return protojson.MarshalOptions{
|
||||
Multiline: true,
|
||||
Indent: "",
|
||||
UseProtoNames: true,
|
||||
EmitUnpopulated: true,
|
||||
Resolver: t.typeResolver,
|
||||
}
|
||||
}
|
||||
|
||||
func (t *singleton) GetTable(message proto.Message) Table {
|
||||
if message.ProtoReflect().Descriptor().FullName() == t.MessageType().Descriptor().FullName() {
|
||||
return t
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
package ormtable_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"google.golang.org/protobuf/testing/protocmp"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
"cosmossdk.io/orm/internal/testkv"
|
||||
"cosmossdk.io/orm/internal/testpb"
|
||||
"cosmossdk.io/orm/model/ormtable"
|
||||
)
|
||||
|
||||
func TestSingleton(t *testing.T) {
|
||||
table, err := ormtable.Build(ormtable.Options{
|
||||
MessageType: (&testpb.ExampleSingleton{}).ProtoReflect().Type(),
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
ctx := ormtable.WrapContextDefault(testkv.NewSplitMemBackend())
|
||||
|
||||
store, err := testpb.NewExampleSingletonTable(table)
|
||||
assert.NilError(t, err)
|
||||
|
||||
val, err := store.Get(ctx)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, val != nil) // singletons are always set
|
||||
assert.NilError(t, store.Save(ctx, &testpb.ExampleSingleton{}))
|
||||
|
||||
val.Foo = "abc"
|
||||
val.Bar = 3
|
||||
assert.NilError(t, store.Save(ctx, val))
|
||||
|
||||
val2, err := store.Get(ctx)
|
||||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t, val, val2, protocmp.Transform())
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
assert.NilError(t, table.ExportJSON(ctx, buf))
|
||||
assert.NilError(t, table.ValidateJSON(bytes.NewReader(buf.Bytes())))
|
||||
store2 := ormtable.WrapContextDefault(testkv.NewSplitMemBackend())
|
||||
assert.NilError(t, table.ImportJSON(store2, bytes.NewReader(buf.Bytes())))
|
||||
|
||||
val3, err := store.Get(ctx)
|
||||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t, val, val3, protocmp.Transform())
|
||||
}
|
||||
@ -1,164 +0,0 @@
|
||||
package ormtable
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"cosmossdk.io/orm/encoding/ormkv"
|
||||
)
|
||||
|
||||
// View defines a read-only table.
|
||||
//
|
||||
// It exists as a separate interacted to support future scenarios where
|
||||
// tables may be "supported" virtually to provide compatibility between
|
||||
// systems, for instance to enable backwards compatibility when a major
|
||||
// migration needs to be performed.
|
||||
type View interface {
|
||||
Index
|
||||
|
||||
// Has returns true if there is an entity in the table with the same
|
||||
// primary key as message. Other fields besides the primary key fields will not
|
||||
// be used for retrieval.
|
||||
Has(ctx context.Context, message proto.Message) (found bool, err error)
|
||||
|
||||
// Get retrieves the message if one exists for the primary key fields
|
||||
// set on the message. Other fields besides the primary key fields will not
|
||||
// be used for retrieval.
|
||||
Get(ctx context.Context, message proto.Message) (found bool, err error)
|
||||
|
||||
// GetIndex returns the index referenced by the provided fields if
|
||||
// one exists or nil. Note that some concrete indexes can be retrieved by
|
||||
// multiple lists of fields.
|
||||
GetIndex(fields string) Index
|
||||
|
||||
// GetUniqueIndex returns the unique index referenced by the provided fields if
|
||||
// one exists or nil. Note that some concrete indexes can be retrieved by
|
||||
// multiple lists of fields.
|
||||
GetUniqueIndex(fields string) UniqueIndex
|
||||
|
||||
// Indexes returns all the concrete indexes for the table.
|
||||
Indexes() []Index
|
||||
|
||||
// GetIndexByID returns the index with the provided ID or nil.
|
||||
GetIndexByID(id uint32) Index
|
||||
|
||||
// PrimaryKey returns the primary key unique index.
|
||||
PrimaryKey() UniqueIndex
|
||||
}
|
||||
|
||||
// Table is an abstract interface around a concrete table. Table instances
|
||||
// are stateless, with all state existing only in the store passed
|
||||
// to table and index methods.
|
||||
type Table interface {
|
||||
View
|
||||
|
||||
ormkv.EntryCodec
|
||||
|
||||
// Save saves the provided entry in the store either inserting it or
|
||||
// updating it if needed.
|
||||
//
|
||||
// If store implement the ValidateHooks interface, the appropriate ValidateInsert or
|
||||
// ValidateUpdate hook method will be called.
|
||||
//
|
||||
// Save attempts to be atomic with respect to the underlying store,
|
||||
// meaning that either the full save operation is written or the store is
|
||||
// left unchanged, unless there is an error with the underlying store.
|
||||
//
|
||||
// If a unique key constraint is violated, ormerrors.UniqueKeyViolation
|
||||
// (or an error wrapping it) will be returned.
|
||||
Save(context context.Context, message proto.Message) error
|
||||
|
||||
// Insert inserts the provided entry in the store and fails if there is
|
||||
// an unique key violation. See Save for more details on behavior.
|
||||
//
|
||||
// If an entity with the same primary key exists, an error wrapping
|
||||
// ormerrors.AlreadyExists will be returned.
|
||||
Insert(ctx context.Context, message proto.Message) error
|
||||
|
||||
// Update updates the provided entry in the store and fails if an entry
|
||||
// with a matching primary key does not exist. See Save for more details
|
||||
// on behavior.
|
||||
//
|
||||
// If an entity with the same primary key does not exist, ormerrors.NotFound
|
||||
// (or an error wrapping it) will be returned.
|
||||
Update(ctx context.Context, message proto.Message) error
|
||||
|
||||
// Delete deletes the entry with the with primary key fields set on message
|
||||
// if one exists. Other fields besides the primary key fields will not
|
||||
// be used for retrieval.
|
||||
//
|
||||
// If store implement the ValidateHooks interface, the ValidateDelete hook method will
|
||||
// be called.
|
||||
//
|
||||
// Delete attempts to be atomic with respect to the underlying store,
|
||||
// meaning that either the full save operation is written or the store is
|
||||
// left unchanged, unless there is an error with the underlying store.
|
||||
Delete(ctx context.Context, message proto.Message) error
|
||||
|
||||
// DefaultJSON returns default JSON that can be used as a template for
|
||||
// genesis files.
|
||||
//
|
||||
// For regular tables this an empty JSON array, but for singletons an
|
||||
// empty instance of the singleton is marshaled.
|
||||
DefaultJSON() json.RawMessage
|
||||
|
||||
// ValidateJSON validates JSON streamed from the reader.
|
||||
ValidateJSON(io.Reader) error
|
||||
|
||||
// ImportJSON imports JSON into the store, streaming one entry at a time.
|
||||
// Each table should be import from a separate JSON file to enable proper
|
||||
// streaming.
|
||||
//
|
||||
// Regular tables should be stored as an array of objects with each object
|
||||
// corresponding to a single record in the table.
|
||||
//
|
||||
// Auto-incrementing tables
|
||||
// can optionally have the last sequence value as the first element in the
|
||||
// array. If the last sequence value is provided, then each value of the
|
||||
// primary key in the file must be <= this last sequence value or omitted
|
||||
// entirely. If no last sequence value is provided, no entries should
|
||||
// contain the primary key as this will be auto-assigned.
|
||||
//
|
||||
// Singletons should define a single object and not an array.
|
||||
//
|
||||
// ImportJSON is not atomic with respect to the underlying store, meaning
|
||||
// that in the case of an error, some records may already have been
|
||||
// imported. It is assumed that ImportJSON is called in the context of some
|
||||
// larger transaction isolation.
|
||||
ImportJSON(context.Context, io.Reader) error
|
||||
|
||||
// ExportJSON exports JSON in the format accepted by ImportJSON.
|
||||
// Auto-incrementing tables will export the last sequence number as the
|
||||
// first element in the JSON array.
|
||||
ExportJSON(context.Context, io.Writer) error
|
||||
|
||||
// ID is the ID of this table within the schema of its FileDescriptor.
|
||||
ID() uint32
|
||||
|
||||
Schema
|
||||
}
|
||||
|
||||
// Schema is an interface for things that contain tables and can encode and
|
||||
// decode kv-store pairs.
|
||||
|
||||
type Schema interface {
|
||||
ormkv.EntryCodec
|
||||
|
||||
// GetTable returns the table for the provided message type or nil.
|
||||
GetTable(message proto.Message) Table
|
||||
}
|
||||
|
||||
type AutoIncrementTable interface {
|
||||
Table
|
||||
|
||||
// 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)
|
||||
|
||||
// LastInsertedSequence retrieves the sequence number of the last entry inserted into the table.
|
||||
// The LastInsertedSequence is 0 if no entries have been inserted into the table.
|
||||
LastInsertedSequence(ctx context.Context) (uint64, error)
|
||||
}
|
||||
@ -1,430 +0,0 @@
|
||||
package ormtable
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"math"
|
||||
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"cosmossdk.io/orm/encoding/encodeutil"
|
||||
"cosmossdk.io/orm/encoding/ormkv"
|
||||
"cosmossdk.io/orm/internal/fieldnames"
|
||||
"cosmossdk.io/orm/types/ormerrors"
|
||||
)
|
||||
|
||||
// tableImpl implements Table.
|
||||
type tableImpl struct {
|
||||
*primaryKeyIndex
|
||||
indexes []Index
|
||||
indexesByFields map[fieldnames.FieldNames]concreteIndex
|
||||
uniqueIndexesByFields map[fieldnames.FieldNames]UniqueIndex
|
||||
indexesByID map[uint32]Index
|
||||
entryCodecsByID map[uint32]ormkv.EntryCodec
|
||||
tablePrefix []byte
|
||||
tableID uint32
|
||||
typeResolver TypeResolver
|
||||
customJSONValidator func(message proto.Message) error
|
||||
}
|
||||
|
||||
func (t *tableImpl) GetTable(message proto.Message) Table {
|
||||
if message.ProtoReflect().Descriptor().FullName() == t.MessageType().Descriptor().FullName() {
|
||||
return t
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t tableImpl) PrimaryKey() UniqueIndex {
|
||||
return t.primaryKeyIndex
|
||||
}
|
||||
|
||||
func (t tableImpl) GetIndexByID(id uint32) Index {
|
||||
return t.indexesByID[id]
|
||||
}
|
||||
|
||||
func (t tableImpl) Save(ctx context.Context, message proto.Message) error {
|
||||
backend, err := t.getWriteBackend(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return t.save(ctx, backend, message, saveModeDefault)
|
||||
}
|
||||
|
||||
func (t tableImpl) Insert(ctx context.Context, message proto.Message) error {
|
||||
backend, err := t.getWriteBackend(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return t.save(ctx, backend, message, saveModeInsert)
|
||||
}
|
||||
|
||||
func (t tableImpl) Update(ctx context.Context, message proto.Message) error {
|
||||
backend, err := t.getWriteBackend(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return t.save(ctx, backend, message, saveModeUpdate)
|
||||
}
|
||||
|
||||
func (t tableImpl) save(ctx context.Context, backend Backend, message proto.Message, mode saveMode) error {
|
||||
writer := newBatchIndexCommitmentWriter(backend)
|
||||
defer writer.Close()
|
||||
return t.doSave(ctx, writer, message, mode)
|
||||
}
|
||||
|
||||
func (t tableImpl) doSave(ctx context.Context, writer *batchIndexCommitmentWriter, message proto.Message, mode saveMode) error {
|
||||
mref := message.ProtoReflect()
|
||||
pkValues, pk, err := t.EncodeKeyFromMessage(mref)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
existing := mref.New().Interface()
|
||||
haveExisting, err := t.getByKeyBytes(writer, pk, pkValues, existing)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if haveExisting {
|
||||
if mode == saveModeInsert {
|
||||
return ormerrors.AlreadyExists.Wrapf("%q:%+v", mref.Descriptor().FullName(), pkValues)
|
||||
}
|
||||
|
||||
if validateHooks := writer.ValidateHooks(); validateHooks != nil {
|
||||
err = validateHooks.ValidateUpdate(ctx, existing, message)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if mode == saveModeUpdate {
|
||||
return ormerrors.NotFound.Wrapf("%q", mref.Descriptor().FullName())
|
||||
}
|
||||
|
||||
if validateHooks := writer.ValidateHooks(); validateHooks != nil {
|
||||
err = validateHooks.ValidateInsert(ctx, message)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// temporarily clear primary key
|
||||
t.ClearValues(mref)
|
||||
|
||||
// store object
|
||||
bz, err := proto.MarshalOptions{Deterministic: true}.Marshal(message)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = writer.CommitmentStore().Set(pk, bz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// set primary key again
|
||||
t.SetKeyValues(mref, pkValues)
|
||||
|
||||
// set indexes
|
||||
indexStoreWriter := writer.IndexStore()
|
||||
if !haveExisting {
|
||||
for _, idx := range t.indexers {
|
||||
err = idx.onInsert(indexStoreWriter, mref)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
if writeHooks := writer.WriteHooks(); writeHooks != nil {
|
||||
writer.enqueueHook(func() {
|
||||
writeHooks.OnInsert(ctx, message)
|
||||
})
|
||||
}
|
||||
} else {
|
||||
existingMref := existing.ProtoReflect()
|
||||
for _, idx := range t.indexers {
|
||||
err = idx.onUpdate(indexStoreWriter, mref, existingMref)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if writeHooks := writer.WriteHooks(); writeHooks != nil {
|
||||
writer.enqueueHook(func() {
|
||||
writeHooks.OnUpdate(ctx, existing, message)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return writer.Write()
|
||||
}
|
||||
|
||||
func (t tableImpl) Delete(ctx context.Context, message proto.Message) error {
|
||||
pk := t.PrimaryKeyCodec.GetKeyValues(message.ProtoReflect())
|
||||
return t.doDelete(ctx, pk)
|
||||
}
|
||||
|
||||
func (t tableImpl) GetIndex(fields string) Index {
|
||||
return t.indexesByFields[fieldnames.CommaSeparatedFieldNames(fields)]
|
||||
}
|
||||
|
||||
func (t tableImpl) GetUniqueIndex(fields string) UniqueIndex {
|
||||
return t.uniqueIndexesByFields[fieldnames.CommaSeparatedFieldNames(fields)]
|
||||
}
|
||||
|
||||
func (t tableImpl) Indexes() []Index {
|
||||
return t.indexes
|
||||
}
|
||||
|
||||
func (t tableImpl) DefaultJSON() json.RawMessage {
|
||||
return json.RawMessage("[]")
|
||||
}
|
||||
|
||||
func (t tableImpl) decodeJSON(reader io.Reader, onMsg func(message proto.Message) error) error {
|
||||
decoder, err := t.startDecodeJSON(reader)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return t.doDecodeJSON(decoder, nil, onMsg)
|
||||
}
|
||||
|
||||
func (t tableImpl) startDecodeJSON(reader io.Reader) (*json.Decoder, error) {
|
||||
decoder := json.NewDecoder(reader)
|
||||
token, err := decoder.Token()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if token != json.Delim('[') {
|
||||
return nil, ormerrors.JSONImportError.Wrapf("expected [ got %s", token)
|
||||
}
|
||||
|
||||
return decoder, nil
|
||||
}
|
||||
|
||||
// onFirst is called on the first RawMessage and used for auto-increment tables
|
||||
// to decode the sequence in which case it should return true.
|
||||
// onMsg is called on every decoded message
|
||||
func (t tableImpl) doDecodeJSON(decoder *json.Decoder, onFirst func(message json.RawMessage) bool, onMsg func(message proto.Message) error) error {
|
||||
unmarshalOptions := protojson.UnmarshalOptions{Resolver: t.typeResolver}
|
||||
|
||||
first := true
|
||||
for decoder.More() {
|
||||
var rawJSON json.RawMessage
|
||||
err := decoder.Decode(&rawJSON)
|
||||
if err != nil {
|
||||
return ormerrors.JSONImportError.Wrapf("%s", err)
|
||||
}
|
||||
|
||||
if first {
|
||||
first = false
|
||||
if onFirst != nil {
|
||||
if onFirst(rawJSON) {
|
||||
// if onFirst handled this, skip decoding into a proto message
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msg := t.MessageType().New().Interface()
|
||||
err = unmarshalOptions.Unmarshal(rawJSON, msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = onMsg(msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
token, err := decoder.Token()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if token != json.Delim(']') {
|
||||
return ormerrors.JSONImportError.Wrapf("expected ] got %s", token)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DefaultJSONValidator is the default validator used when calling
|
||||
// Table.ValidateJSON(). It will call methods with the signature `ValidateBasic() error`
|
||||
// and/or `Validate() error` to validate the message.
|
||||
func DefaultJSONValidator(message proto.Message) error {
|
||||
if v, ok := message.(interface{ ValidateBasic() error }); ok {
|
||||
err := v.ValidateBasic()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if v, ok := message.(interface{ Validate() error }); ok {
|
||||
err := v.Validate()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t tableImpl) ValidateJSON(reader io.Reader) error {
|
||||
return t.decodeJSON(reader, func(message proto.Message) error {
|
||||
if t.customJSONValidator != nil {
|
||||
return t.customJSONValidator(message)
|
||||
}
|
||||
|
||||
return DefaultJSONValidator(message)
|
||||
})
|
||||
}
|
||||
|
||||
func (t tableImpl) ImportJSON(ctx context.Context, reader io.Reader) error {
|
||||
backend, err := t.getWriteBackend(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return t.decodeJSON(reader, func(message proto.Message) error {
|
||||
return t.save(ctx, backend, message, saveModeDefault)
|
||||
})
|
||||
}
|
||||
|
||||
func (t tableImpl) ExportJSON(context context.Context, writer io.Writer) error {
|
||||
_, err := writer.Write([]byte("["))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return t.doExportJSON(context, writer, true)
|
||||
}
|
||||
|
||||
func (t tableImpl) doExportJSON(ctx context.Context, writer io.Writer, start bool) error {
|
||||
marshalOptions := protojson.MarshalOptions{
|
||||
UseProtoNames: true,
|
||||
Resolver: t.typeResolver,
|
||||
}
|
||||
|
||||
var err error
|
||||
it, _ := t.List(ctx, nil)
|
||||
for {
|
||||
found := it.Next()
|
||||
|
||||
if !found {
|
||||
_, err = writer.Write([]byte("]"))
|
||||
return err
|
||||
} else if !start {
|
||||
_, err = writer.Write([]byte(",\n"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
start = false
|
||||
|
||||
msg := t.MessageType().New().Interface()
|
||||
err = it.UnmarshalMessage(msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
bz, err := marshalOptions.Marshal(msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = writer.Write(bz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func (t tableImpl) DecodeEntry(k, v []byte) (ormkv.Entry, error) {
|
||||
r := bytes.NewReader(k)
|
||||
err := encodeutil.SkipPrefix(r, t.tablePrefix)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id, err := binary.ReadUvarint(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if id > math.MaxUint32 {
|
||||
return nil, ormerrors.UnexpectedDecodePrefix.Wrapf("uint32 varint id out of range %d", id)
|
||||
}
|
||||
|
||||
idx, ok := t.entryCodecsByID[uint32(id)]
|
||||
if !ok {
|
||||
return nil, ormerrors.UnexpectedDecodePrefix.Wrapf("can't find field with id %d", id)
|
||||
}
|
||||
|
||||
return idx.DecodeEntry(k, v)
|
||||
}
|
||||
|
||||
func (t tableImpl) EncodeEntry(entry ormkv.Entry) (k, v []byte, err error) {
|
||||
switch entry := entry.(type) {
|
||||
case *ormkv.PrimaryKeyEntry:
|
||||
return t.PrimaryKeyCodec.EncodeEntry(entry)
|
||||
case *ormkv.IndexKeyEntry:
|
||||
idx, ok := t.indexesByFields[fieldnames.FieldsFromNames(entry.Fields)]
|
||||
if !ok {
|
||||
return nil, nil, ormerrors.BadDecodeEntry.Wrapf("can't find index with fields %s", entry.Fields)
|
||||
}
|
||||
|
||||
return idx.EncodeEntry(entry)
|
||||
default:
|
||||
return nil, nil, ormerrors.BadDecodeEntry.Wrapf("%s", entry)
|
||||
}
|
||||
}
|
||||
|
||||
func (t tableImpl) ID() uint32 {
|
||||
return t.tableID
|
||||
}
|
||||
|
||||
func (t tableImpl) Has(ctx context.Context, message proto.Message) (found bool, err error) {
|
||||
backend, err := t.getBackend(ctx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
keyValues := t.primaryKeyIndex.PrimaryKeyCodec.GetKeyValues(message.ProtoReflect())
|
||||
return t.primaryKeyIndex.has(backend, keyValues)
|
||||
}
|
||||
|
||||
// Get retrieves the message if one exists for the primary key fields
|
||||
// set on the message. Other fields besides the primary key fields will not
|
||||
// be used for retrieval.
|
||||
func (t tableImpl) Get(ctx context.Context, message proto.Message) (found bool, err error) {
|
||||
backend, err := t.getBackend(ctx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
keyValues := t.primaryKeyIndex.PrimaryKeyCodec.GetKeyValues(message.ProtoReflect())
|
||||
return t.primaryKeyIndex.get(backend, message, keyValues)
|
||||
}
|
||||
|
||||
var (
|
||||
_ Table = &tableImpl{}
|
||||
_ Schema = &tableImpl{}
|
||||
)
|
||||
|
||||
type saveMode int
|
||||
|
||||
const (
|
||||
saveModeDefault saveMode = iota
|
||||
saveModeInsert
|
||||
saveModeUpdate
|
||||
)
|
||||
@ -1,2 +0,0 @@
|
||||
[1,
|
||||
{"id":"2","x":"foo","y":5}]
|
||||
@ -1 +0,0 @@
|
||||
[{"id":"1","x":"foo","y":5}]
|
||||
80
orm/model/ormtable/testdata/test_auto_inc.golden
vendored
80
orm/model/ormtable/testdata/test_auto_inc.golden
vendored
@ -1,80 +0,0 @@
|
||||
GET 03000005
|
||||
PK testpb.ExampleAutoIncrementTable 5 -> {"id":5}
|
||||
GET 03808002
|
||||
SEQ testpb.ExampleAutoIncrementTable 0
|
||||
GET 03000001
|
||||
PK testpb.ExampleAutoIncrementTable 1 -> {"id":1}
|
||||
ORM BEFORE INSERT testpb.ExampleAutoIncrementTable {"id":1,"x":"foo","y":5}
|
||||
HAS 0301666f6f
|
||||
ERR:EOF
|
||||
SET 03000001 1203666f6f1805
|
||||
PK testpb.ExampleAutoIncrementTable 1 -> {"id":1,"x":"foo","y":5}
|
||||
SET 03808002 01
|
||||
SEQ testpb.ExampleAutoIncrementTable 1
|
||||
SET 0301666f6f 0001
|
||||
UNIQ testpb.ExampleAutoIncrementTable x : foo -> 1
|
||||
ORM AFTER INSERT testpb.ExampleAutoIncrementTable {"id":1,"x":"foo","y":5}
|
||||
GET 03808002 01
|
||||
SEQ testpb.ExampleAutoIncrementTable 1
|
||||
GET 03808002 01
|
||||
SEQ testpb.ExampleAutoIncrementTable 1
|
||||
GET 03000002
|
||||
PK testpb.ExampleAutoIncrementTable 2 -> {"id":2}
|
||||
ORM BEFORE INSERT testpb.ExampleAutoIncrementTable {"id":2,"x":"bar","y":10}
|
||||
HAS 0301626172
|
||||
ERR:EOF
|
||||
SET 03000002 1203626172180a
|
||||
PK testpb.ExampleAutoIncrementTable 2 -> {"id":2,"x":"bar","y":10}
|
||||
SET 03808002 02
|
||||
SEQ testpb.ExampleAutoIncrementTable 2
|
||||
SET 0301626172 0002
|
||||
UNIQ testpb.ExampleAutoIncrementTable x : bar -> 2
|
||||
ORM AFTER INSERT testpb.ExampleAutoIncrementTable {"id":2,"x":"bar","y":10}
|
||||
GET 03808002 02
|
||||
SEQ testpb.ExampleAutoIncrementTable 2
|
||||
GET 03808002 02
|
||||
SEQ testpb.ExampleAutoIncrementTable 2
|
||||
ITERATOR 0300 -> 0301
|
||||
VALID true
|
||||
KEY 03000001 1203666f6f1805
|
||||
PK testpb.ExampleAutoIncrementTable 1 -> {"id":1,"x":"foo","y":5}
|
||||
NEXT
|
||||
VALID true
|
||||
KEY 03000002 1203626172180a
|
||||
PK testpb.ExampleAutoIncrementTable 2 -> {"id":2,"x":"bar","y":10}
|
||||
NEXT
|
||||
VALID false
|
||||
ITERATOR 0300 -> 0301
|
||||
VALID true
|
||||
KEY 03000001 1203666f6f1805
|
||||
PK testpb.ExampleAutoIncrementTable 1 -> {"id":1,"x":"foo","y":5}
|
||||
KEY 03000001 1203666f6f1805
|
||||
PK testpb.ExampleAutoIncrementTable 1 -> {"id":1,"x":"foo","y":5}
|
||||
NEXT
|
||||
VALID true
|
||||
KEY 03000002 1203626172180a
|
||||
PK testpb.ExampleAutoIncrementTable 2 -> {"id":2,"x":"bar","y":10}
|
||||
KEY 03000002 1203626172180a
|
||||
PK testpb.ExampleAutoIncrementTable 2 -> {"id":2,"x":"bar","y":10}
|
||||
NEXT
|
||||
VALID false
|
||||
GET 03000001 1203666f6f1805
|
||||
PK testpb.ExampleAutoIncrementTable 1 -> {"id":1,"x":"foo","y":5}
|
||||
ORM BEFORE DELETE testpb.ExampleAutoIncrementTable {"id":1,"x":"foo","y":5}
|
||||
DEL 03000001
|
||||
DEL PK testpb.ExampleAutoIncrementTable 1 -> {"id":1}
|
||||
DEL 0301666f6f
|
||||
DEL ERR:EOF
|
||||
ORM AFTER DELETE testpb.ExampleAutoIncrementTable {"id":1,"x":"foo","y":5}
|
||||
GET 03000002 1203626172180a
|
||||
PK testpb.ExampleAutoIncrementTable 2 -> {"id":2,"x":"bar","y":10}
|
||||
ORM BEFORE DELETE testpb.ExampleAutoIncrementTable {"id":2,"x":"bar","y":10}
|
||||
DEL 03000002
|
||||
DEL PK testpb.ExampleAutoIncrementTable 2 -> {"id":2}
|
||||
DEL 0301626172
|
||||
DEL ERR:EOF
|
||||
ORM AFTER DELETE testpb.ExampleAutoIncrementTable {"id":2,"x":"bar","y":10}
|
||||
GET 03808002 02
|
||||
SEQ testpb.ExampleAutoIncrementTable 2
|
||||
ITERATOR 0300 -> 0301
|
||||
VALID false
|
||||
1185
orm/model/ormtable/testdata/test_scenario.golden
vendored
1185
orm/model/ormtable/testdata/test_scenario.golden
vendored
File diff suppressed because it is too large
Load Diff
@ -1 +0,0 @@
|
||||
[2]
|
||||
@ -1,102 +0,0 @@
|
||||
package ormtable_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
"cosmossdk.io/orm/internal/testkv"
|
||||
"cosmossdk.io/orm/internal/testpb"
|
||||
"cosmossdk.io/orm/model/ormtable"
|
||||
)
|
||||
|
||||
func TestTimestampIndex(t *testing.T) {
|
||||
table, err := ormtable.Build(ormtable.Options{
|
||||
MessageType: (&testpb.ExampleTimestamp{}).ProtoReflect().Type(),
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
backend := testkv.NewDebugBackend(testkv.NewSplitMemBackend(), &testkv.EntryCodecDebugger{
|
||||
EntryCodec: table,
|
||||
})
|
||||
ctx := ormtable.WrapContextDefault(backend)
|
||||
store, err := testpb.NewExampleTimestampTable(table)
|
||||
assert.NilError(t, err)
|
||||
|
||||
past, err := time.Parse("2006-01-02", "2000-01-01")
|
||||
assert.NilError(t, err)
|
||||
middle, err := time.Parse("2006-01-02", "2020-01-01")
|
||||
assert.NilError(t, err)
|
||||
future, err := time.Parse("2006-01-02", "2049-01-01")
|
||||
assert.NilError(t, err)
|
||||
|
||||
pastPb, middlePb, futurePb := timestamppb.New(past), timestamppb.New(middle), timestamppb.New(future)
|
||||
timeOrder := []*timestamppb.Timestamp{pastPb, middlePb, futurePb}
|
||||
|
||||
assert.NilError(t, store.Insert(ctx, &testpb.ExampleTimestamp{
|
||||
Name: "foo",
|
||||
Ts: pastPb,
|
||||
}))
|
||||
assert.NilError(t, store.Insert(ctx, &testpb.ExampleTimestamp{
|
||||
Name: "bar",
|
||||
Ts: middlePb,
|
||||
}))
|
||||
assert.NilError(t, store.Insert(ctx, &testpb.ExampleTimestamp{
|
||||
Name: "baz",
|
||||
Ts: futurePb,
|
||||
}))
|
||||
|
||||
from, to := testpb.ExampleTimestampTsIndexKey{}.WithTs(timestamppb.New(past)), testpb.ExampleTimestampTsIndexKey{}.WithTs(timestamppb.New(future))
|
||||
it, err := store.ListRange(ctx, from, to)
|
||||
assert.NilError(t, err)
|
||||
|
||||
i := 0
|
||||
for it.Next() {
|
||||
v, err := it.Value()
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, timeOrder[i].String(), v.Ts.String())
|
||||
i++
|
||||
}
|
||||
|
||||
// insert a nil entry
|
||||
id, err := store.InsertReturningId(ctx, &testpb.ExampleTimestamp{
|
||||
Name: "nil",
|
||||
Ts: nil,
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
|
||||
res, err := store.Get(ctx, id)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, res.Ts == nil)
|
||||
|
||||
it, err = store.List(ctx, testpb.ExampleTimestampTsIndexKey{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
// make sure nils are ordered last
|
||||
timeOrder = append(timeOrder, nil)
|
||||
i = 0
|
||||
for it.Next() {
|
||||
v, err := it.Value()
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, v != nil)
|
||||
x := timeOrder[i]
|
||||
if x == nil {
|
||||
assert.Assert(t, v.Ts == nil)
|
||||
} else {
|
||||
assert.Equal(t, x.String(), v.Ts.String())
|
||||
}
|
||||
i++
|
||||
}
|
||||
it.Close()
|
||||
|
||||
// try iterating over just nil timestamps
|
||||
it, err = store.List(ctx, testpb.ExampleTimestampTsIndexKey{}.WithTs(nil))
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, it.Next())
|
||||
res, err = it.Value()
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, res.Ts == nil)
|
||||
assert.Assert(t, !it.Next())
|
||||
it.Close()
|
||||
}
|
||||
@ -1,210 +0,0 @@
|
||||
package ormtable
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
|
||||
"cosmossdk.io/orm/encoding/encodeutil"
|
||||
"cosmossdk.io/orm/encoding/ormkv"
|
||||
"cosmossdk.io/orm/internal/fieldnames"
|
||||
"cosmossdk.io/orm/model/ormlist"
|
||||
"cosmossdk.io/orm/types/kv"
|
||||
"cosmossdk.io/orm/types/ormerrors"
|
||||
)
|
||||
|
||||
type uniqueKeyIndex struct {
|
||||
*ormkv.UniqueKeyCodec
|
||||
fields fieldnames.FieldNames
|
||||
primaryKey *primaryKeyIndex
|
||||
getReadBackend func(context.Context) (ReadBackend, error)
|
||||
}
|
||||
|
||||
func (u uniqueKeyIndex) List(ctx context.Context, prefixKey []interface{}, options ...ormlist.Option) (Iterator, error) {
|
||||
backend, err := u.getReadBackend(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return prefixIterator(backend.IndexStoreReader(), backend, u, u.GetKeyCodec(), prefixKey, options)
|
||||
}
|
||||
|
||||
func (u uniqueKeyIndex) ListRange(ctx context.Context, from, to []interface{}, options ...ormlist.Option) (Iterator, error) {
|
||||
backend, err := u.getReadBackend(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rangeIterator(backend.IndexStoreReader(), backend, u, u.GetKeyCodec(), from, to, options)
|
||||
}
|
||||
|
||||
func (u uniqueKeyIndex) doNotImplement() {}
|
||||
|
||||
func (u uniqueKeyIndex) Has(ctx context.Context, values ...interface{}) (found bool, err error) {
|
||||
backend, err := u.getReadBackend(ctx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
key, err := u.GetKeyCodec().EncodeKey(encodeutil.ValuesOf(values...))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return backend.IndexStoreReader().Has(key)
|
||||
}
|
||||
|
||||
func (u uniqueKeyIndex) Get(ctx context.Context, message proto.Message, keyValues ...interface{}) (found bool, err error) {
|
||||
backend, err := u.getReadBackend(ctx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
key, err := u.GetKeyCodec().EncodeKey(encodeutil.ValuesOf(keyValues...))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
value, err := backend.IndexStoreReader().Get(key)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// for unique keys, value can be empty and the entry still exists
|
||||
if value == nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
_, pk, err := u.DecodeIndexKey(key, value)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
|
||||
return u.primaryKey.get(backend, message, pk)
|
||||
}
|
||||
|
||||
func (u uniqueKeyIndex) DeleteBy(ctx context.Context, keyValues ...interface{}) error {
|
||||
it, err := u.List(ctx, keyValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return u.primaryKey.deleteByIterator(ctx, it)
|
||||
}
|
||||
|
||||
func (u uniqueKeyIndex) DeleteRange(ctx context.Context, from, to []interface{}) error {
|
||||
it, err := u.ListRange(ctx, from, to)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return u.primaryKey.deleteByIterator(ctx, it)
|
||||
}
|
||||
|
||||
func (u uniqueKeyIndex) onInsert(store kv.Store, message protoreflect.Message) error {
|
||||
k, v, err := u.EncodeKVFromMessage(message)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
has, err := store.Has(k)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if has {
|
||||
return ormerrors.UniqueKeyViolation.Wrapf("%q", u.fields)
|
||||
}
|
||||
|
||||
return store.Set(k, v)
|
||||
}
|
||||
|
||||
func (u uniqueKeyIndex) onUpdate(store kv.Store, new, existing protoreflect.Message) error {
|
||||
keyCodec := u.GetKeyCodec()
|
||||
newValues := keyCodec.GetKeyValues(new)
|
||||
existingValues := keyCodec.GetKeyValues(existing)
|
||||
if keyCodec.CompareKeys(newValues, existingValues) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
newKey, err := keyCodec.EncodeKey(newValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
has, err := store.Has(newKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if has {
|
||||
return ormerrors.UniqueKeyViolation.Wrapf("%q", u.fields)
|
||||
}
|
||||
|
||||
existingKey, err := keyCodec.EncodeKey(existingValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = store.Delete(existingKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, value, err := u.GetValueCodec().EncodeKeyFromMessage(new)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return store.Set(newKey, value)
|
||||
}
|
||||
|
||||
func (u uniqueKeyIndex) onDelete(store kv.Store, message protoreflect.Message) error {
|
||||
_, key, err := u.GetKeyCodec().EncodeKeyFromMessage(message)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return store.Delete(key)
|
||||
}
|
||||
|
||||
func (u uniqueKeyIndex) readValueFromIndexKey(store ReadBackend, primaryKey []protoreflect.Value, _ []byte, message proto.Message) error {
|
||||
found, err := u.primaryKey.get(store, message, primaryKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !found {
|
||||
return ormerrors.UnexpectedError.Wrapf("can't find primary key")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u uniqueKeyIndex) Fields() string {
|
||||
return u.fields.String()
|
||||
}
|
||||
|
||||
var (
|
||||
_ indexer = &uniqueKeyIndex{}
|
||||
_ UniqueIndex = &uniqueKeyIndex{}
|
||||
)
|
||||
|
||||
// isNonTrivialUniqueKey checks if unique key fields are non-trivial, meaning that they
|
||||
// don't contain the full primary key. If they contain the full primary key, then
|
||||
// we can just use a regular index because there is no new unique constraint.
|
||||
func isNonTrivialUniqueKey(fields, primaryKeyFields []protoreflect.Name) bool {
|
||||
have := map[protoreflect.Name]bool{}
|
||||
for _, field := range fields {
|
||||
have[field] = true
|
||||
}
|
||||
|
||||
for _, field := range primaryKeyFields {
|
||||
if !have[field] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
package ormtable
|
||||
|
||||
// prefixEndBytes returns the []byte that would end a
|
||||
// range query for all []byte with a certain prefix
|
||||
// Deals with last byte of prefix being FF without overflowing
|
||||
func prefixEndBytes(prefix []byte) []byte {
|
||||
if len(prefix) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
end := make([]byte, len(prefix))
|
||||
copy(end, prefix)
|
||||
|
||||
for {
|
||||
if end[len(end)-1] != byte(255) {
|
||||
end[len(end)-1]++
|
||||
break
|
||||
}
|
||||
|
||||
end = end[:len(end)-1]
|
||||
|
||||
if len(end) == 0 {
|
||||
end = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return end
|
||||
}
|
||||
|
||||
// inclusiveEndBytes returns the []byte that would end a
|
||||
// range query such that the input would be included
|
||||
func inclusiveEndBytes(inclusiveBytes []byte) []byte {
|
||||
return append(inclusiveBytes, byte(0x00))
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
// Package ormmocks contains generated mocks for orm types that can be used
|
||||
// in testing. Right now, this package only contains a mock for ormtable.ValidateHooks
|
||||
// as this useful way for unit testing using an in-memory database. Rather
|
||||
// than attempting to mock a whole table or database instance, instead
|
||||
// a mock Hook instance can be passed in to verify that the expected
|
||||
// insert/update/delete operations are happening in the database.
|
||||
//
|
||||
// The Eq function gomock.Matcher that compares protobuf messages can
|
||||
// be used in gomock EXPECT functions.
|
||||
//
|
||||
// See TestHooks in ormdb/module_test.go for examples of how to use
|
||||
// mock ValidateHooks in a real-world scenario.
|
||||
package ormmocks
|
||||
@ -1,19 +0,0 @@
|
||||
// Package ormtest contains utilities for testing modules built with the ORM.
|
||||
package ormtest
|
||||
|
||||
import (
|
||||
"cosmossdk.io/orm/internal/testkv"
|
||||
"cosmossdk.io/orm/model/ormtable"
|
||||
)
|
||||
|
||||
// NewMemoryBackend returns a new ORM memory backend which can be used for
|
||||
// testing purposes independent of any storage layer.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// backend := ormtest.NewMemoryBackend()
|
||||
// ctx := ormtable.WrapContextDefault()
|
||||
// ...
|
||||
func NewMemoryBackend() ormtable.Backend {
|
||||
return testkv.NewSplitMemBackend()
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
// Package types contains types used in the ORM implementation that don't
|
||||
// have another home.
|
||||
package types
|
||||
Loading…
Reference in New Issue
Block a user