feat(orm): specify generic gRPC query service (#11791)
## Description Ref #11774 This proposes a generic gRPC query service that uses direct index access and can basically be implemented as a thin layer directly on top of `ormtable.Table`. There is relatively little code required to implement this but it can potentially provide a lot of value as a way to expose queries to basically everything that's using the ORM without needing to implement any custom gRPC queries. A version of this which is type safe is also proposed in #11774 but that would require additional codegen of .proto files. #11774 also proposes a logical query layer instead of direct index access but that's substantially more code to do even naively and an optimized version would take more effort. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
This commit is contained in:
parent
82412afd17
commit
d084887828
5376
api/cosmos/orm/query/v1alpha1/query.pulsar.go
Normal file
5376
api/cosmos/orm/query/v1alpha1/query.pulsar.go
Normal file
File diff suppressed because it is too large
Load Diff
145
api/cosmos/orm/query/v1alpha1/query_grpc.pb.go
Normal file
145
api/cosmos/orm/query/v1alpha1/query_grpc.pb.go
Normal file
@ -0,0 +1,145 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.2.0
|
||||
// - protoc (unknown)
|
||||
// source: cosmos/orm/query/v1alpha1/query.proto
|
||||
|
||||
package queryv1alpha1
|
||||
|
||||
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
|
||||
|
||||
// QueryClient is the client API for Query 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 QueryClient interface {
|
||||
// Get queries an ORM table against an unique index.
|
||||
Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error)
|
||||
// List queries an ORM table against an index.
|
||||
List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error)
|
||||
}
|
||||
|
||||
type queryClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewQueryClient(cc grpc.ClientConnInterface) QueryClient {
|
||||
return &queryClient{cc}
|
||||
}
|
||||
|
||||
func (c *queryClient) Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) {
|
||||
out := new(GetResponse)
|
||||
err := c.cc.Invoke(ctx, "/cosmos.orm.query.v1alpha1.Query/Get", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *queryClient) List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) {
|
||||
out := new(ListResponse)
|
||||
err := c.cc.Invoke(ctx, "/cosmos.orm.query.v1alpha1.Query/List", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// QueryServer is the server API for Query service.
|
||||
// All implementations must embed UnimplementedQueryServer
|
||||
// for forward compatibility
|
||||
type QueryServer interface {
|
||||
// Get queries an ORM table against an unique index.
|
||||
Get(context.Context, *GetRequest) (*GetResponse, error)
|
||||
// List queries an ORM table against an index.
|
||||
List(context.Context, *ListRequest) (*ListResponse, error)
|
||||
mustEmbedUnimplementedQueryServer()
|
||||
}
|
||||
|
||||
// UnimplementedQueryServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedQueryServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedQueryServer) Get(context.Context, *GetRequest) (*GetResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Get not implemented")
|
||||
}
|
||||
func (UnimplementedQueryServer) List(context.Context, *ListRequest) (*ListResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method List not implemented")
|
||||
}
|
||||
func (UnimplementedQueryServer) mustEmbedUnimplementedQueryServer() {}
|
||||
|
||||
// UnsafeQueryServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to QueryServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeQueryServer interface {
|
||||
mustEmbedUnimplementedQueryServer()
|
||||
}
|
||||
|
||||
func RegisterQueryServer(s grpc.ServiceRegistrar, srv QueryServer) {
|
||||
s.RegisterService(&Query_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _Query_Get_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(QueryServer).Get(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/cosmos.orm.query.v1alpha1.Query/Get",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(QueryServer).Get(ctx, req.(*GetRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Query_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(QueryServer).List(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/cosmos.orm.query.v1alpha1.Query/List",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(QueryServer).List(ctx, req.(*ListRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// Query_ServiceDesc is the grpc.ServiceDesc for Query service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var Query_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "cosmos.orm.query.v1alpha1.Query",
|
||||
HandlerType: (*QueryServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "Get",
|
||||
Handler: _Query_Get_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "List",
|
||||
Handler: _Query_List_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "cosmos/orm/query/v1alpha1/query.proto",
|
||||
}
|
||||
131
proto/cosmos/orm/query/v1alpha1/query.proto
Normal file
131
proto/cosmos/orm/query/v1alpha1/query.proto
Normal file
@ -0,0 +1,131 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package cosmos.orm.query.v1alpha1;
|
||||
|
||||
import "google/protobuf/timestamp.proto";
|
||||
import "google/protobuf/duration.proto";
|
||||
import "google/protobuf/any.proto";
|
||||
import "cosmos/base/query/v1beta1/pagination.proto";
|
||||
|
||||
// Query is a generic gRPC service for querying ORM data.
|
||||
service Query {
|
||||
|
||||
// Get queries an ORM table against an unique index.
|
||||
rpc Get(GetRequest) returns (GetResponse);
|
||||
|
||||
// List queries an ORM table against an index.
|
||||
rpc List(ListRequest) returns (ListResponse);
|
||||
}
|
||||
|
||||
// GetRequest is the Query/Get request type.
|
||||
message GetRequest {
|
||||
// message_name is the fully-qualified message name of the ORM table being queried.
|
||||
string message_name = 1;
|
||||
|
||||
// index is the index fields expression used in orm definitions. If it
|
||||
// is empty, the table's primary key is assumed. If it is non-empty, it must
|
||||
// refer to an unique index.
|
||||
string index = 2;
|
||||
|
||||
// values are the values of the fields corresponding to the requested index.
|
||||
// There must be as many values provided as there are fields in the index and
|
||||
// these values must correspond to the index field types.
|
||||
repeated IndexValue values = 3;
|
||||
}
|
||||
|
||||
// GetResponse is the Query/Get response type.
|
||||
message GetResponse {
|
||||
|
||||
// result is the result of the get query. If no value is found, the gRPC
|
||||
// status code NOT_FOUND will be returned.
|
||||
google.protobuf.Any result = 1;
|
||||
}
|
||||
|
||||
// ListRequest is the Query/List request type.
|
||||
message ListRequest {
|
||||
// message_name is the fully-qualified message name of the ORM table being queried.
|
||||
string message_name = 1;
|
||||
|
||||
// index is the index fields expression used in orm definitions. If it
|
||||
// is empty, the table's primary key is assumed.
|
||||
string index = 2;
|
||||
|
||||
// query is the query expression corresponding to the provided index. If
|
||||
// neither prefix nor range is specified, the query will list all the fields
|
||||
// in the index.
|
||||
oneof query {
|
||||
|
||||
// prefix defines a prefix query.
|
||||
Prefix prefix = 3;
|
||||
|
||||
// range defines a range query.
|
||||
Range range = 4;
|
||||
}
|
||||
|
||||
// pagination is the pagination request.
|
||||
cosmos.base.query.v1beta1.PageRequest pagination = 5;
|
||||
|
||||
// Prefix specifies the arguments to a prefix query.
|
||||
message Prefix {
|
||||
// values specifies the index values for the prefix query.
|
||||
// It is valid to special a partial prefix with fewer values than
|
||||
// the number of fields in the index.
|
||||
repeated IndexValue values = 1;
|
||||
}
|
||||
|
||||
// Range specifies the arguments to a range query.
|
||||
message Range {
|
||||
// start specifies the starting index values for the range query.
|
||||
// It is valid to provide fewer values than the number of fields in the
|
||||
// index.
|
||||
repeated IndexValue start = 1;
|
||||
|
||||
// end specifies the inclusive ending index values for the range query.
|
||||
// It is valid to provide fewer values than the number of fields in the
|
||||
// index.
|
||||
repeated IndexValue end = 2;
|
||||
}
|
||||
}
|
||||
|
||||
// ListResponse is the Query/List response type.
|
||||
message ListResponse {
|
||||
|
||||
// results are the results of the query.
|
||||
repeated google.protobuf.Any results = 1;
|
||||
|
||||
// pagination is the pagination response.
|
||||
cosmos.base.query.v1beta1.PageResponse pagination = 5;
|
||||
}
|
||||
|
||||
// IndexValue represents the value of a field in an ORM index expression.
|
||||
message IndexValue {
|
||||
|
||||
// value specifies the index value
|
||||
oneof value {
|
||||
// uint specifies a value for an uint32, fixed32, uint64, or fixed64
|
||||
// index field.
|
||||
uint64 uint = 1;
|
||||
|
||||
// int64 specifies a value for an int32, sfixed32, int64, or sfixed64
|
||||
// index field.
|
||||
int64 int = 2;
|
||||
|
||||
// str specifies a value for a string index field.
|
||||
string str = 3;
|
||||
|
||||
// bytes specifies a value for a bytes index field.
|
||||
bytes bytes = 4;
|
||||
|
||||
// enum specifies a value for an enum index field.
|
||||
string enum = 5;
|
||||
|
||||
// bool specifies a value for a bool index field.
|
||||
bool bool = 6;
|
||||
|
||||
// timestamp specifies a value for a timestamp index field.
|
||||
google.protobuf.Timestamp timestamp = 7;
|
||||
|
||||
// duration specifies a value for a duration index field.
|
||||
google.protobuf.Duration duration = 8;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user