mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-17 13:24:56 +00:00
Generic datastore service with basic indexing and querying capabilities, ts client generation (#52)
This commit is contained in:
1111
datastore/proto/datastore.pb.go
Normal file
1111
datastore/proto/datastore.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
161
datastore/proto/datastore.pb.micro.go
Normal file
161
datastore/proto/datastore.pb.micro.go
Normal file
@@ -0,0 +1,161 @@
|
||||
// Code generated by protoc-gen-micro. DO NOT EDIT.
|
||||
// source: proto/datastore.proto
|
||||
|
||||
package datastore
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
math "math"
|
||||
)
|
||||
|
||||
import (
|
||||
context "context"
|
||||
api "github.com/micro/micro/v3/service/api"
|
||||
client "github.com/micro/micro/v3/service/client"
|
||||
server "github.com/micro/micro/v3/service/server"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ api.Endpoint
|
||||
var _ context.Context
|
||||
var _ client.Option
|
||||
var _ server.Option
|
||||
|
||||
// Api Endpoints for Datastore service
|
||||
|
||||
func NewDatastoreEndpoints() []*api.Endpoint {
|
||||
return []*api.Endpoint{}
|
||||
}
|
||||
|
||||
// Client API for Datastore service
|
||||
|
||||
type DatastoreService interface {
|
||||
Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error)
|
||||
Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error)
|
||||
Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error)
|
||||
Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error)
|
||||
CreateIndex(ctx context.Context, in *CreateIndexRequest, opts ...client.CallOption) (*CreateIndexResponse, error)
|
||||
}
|
||||
|
||||
type datastoreService struct {
|
||||
c client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
func NewDatastoreService(name string, c client.Client) DatastoreService {
|
||||
return &datastoreService{
|
||||
c: c,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *datastoreService) Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Datastore.Create", in)
|
||||
out := new(CreateResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *datastoreService) Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Datastore.Update", in)
|
||||
out := new(UpdateResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *datastoreService) Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Datastore.Read", in)
|
||||
out := new(ReadResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *datastoreService) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Datastore.Delete", in)
|
||||
out := new(DeleteResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *datastoreService) CreateIndex(ctx context.Context, in *CreateIndexRequest, opts ...client.CallOption) (*CreateIndexResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Datastore.CreateIndex", in)
|
||||
out := new(CreateIndexResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Server API for Datastore service
|
||||
|
||||
type DatastoreHandler interface {
|
||||
Create(context.Context, *CreateRequest, *CreateResponse) error
|
||||
Update(context.Context, *UpdateRequest, *UpdateResponse) error
|
||||
Read(context.Context, *ReadRequest, *ReadResponse) error
|
||||
Delete(context.Context, *DeleteRequest, *DeleteResponse) error
|
||||
CreateIndex(context.Context, *CreateIndexRequest, *CreateIndexResponse) error
|
||||
}
|
||||
|
||||
func RegisterDatastoreHandler(s server.Server, hdlr DatastoreHandler, opts ...server.HandlerOption) error {
|
||||
type datastore interface {
|
||||
Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error
|
||||
Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error
|
||||
Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error
|
||||
Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error
|
||||
CreateIndex(ctx context.Context, in *CreateIndexRequest, out *CreateIndexResponse) error
|
||||
}
|
||||
type Datastore struct {
|
||||
datastore
|
||||
}
|
||||
h := &datastoreHandler{hdlr}
|
||||
return s.Handle(s.NewHandler(&Datastore{h}, opts...))
|
||||
}
|
||||
|
||||
type datastoreHandler struct {
|
||||
DatastoreHandler
|
||||
}
|
||||
|
||||
func (h *datastoreHandler) Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error {
|
||||
return h.DatastoreHandler.Create(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *datastoreHandler) Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error {
|
||||
return h.DatastoreHandler.Update(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *datastoreHandler) Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error {
|
||||
return h.DatastoreHandler.Read(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *datastoreHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error {
|
||||
return h.DatastoreHandler.Delete(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *datastoreHandler) CreateIndex(ctx context.Context, in *CreateIndexRequest, out *CreateIndexResponse) error {
|
||||
return h.DatastoreHandler.CreateIndex(ctx, in, out)
|
||||
}
|
||||
113
datastore/proto/datastore.proto
Normal file
113
datastore/proto/datastore.proto
Normal file
@@ -0,0 +1,113 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package datastore;
|
||||
|
||||
option go_package = "proto;datastore";
|
||||
|
||||
// These endpoints are experimental and will likely change,
|
||||
// especially related to indexes.
|
||||
service Datastore {
|
||||
rpc Create(CreateRequest) returns (CreateResponse) {}
|
||||
rpc Update(UpdateRequest) returns (UpdateResponse) {}
|
||||
rpc Read(ReadRequest) returns (ReadResponse) {}
|
||||
rpc Delete(DeleteRequest) returns (DeleteResponse) {}
|
||||
rpc CreateIndex(CreateIndexRequest) returns (CreateIndexResponse) {}
|
||||
}
|
||||
|
||||
message Query {
|
||||
Index index = 1;
|
||||
Order order = 2;
|
||||
string value = 3;
|
||||
int64 offset = 4;
|
||||
int64 limit = 5;
|
||||
}
|
||||
|
||||
// Order is the order of the index
|
||||
message Order {
|
||||
// Field to order on
|
||||
// eg. age
|
||||
string fieldName = 1;
|
||||
// Ordered or unordered keys. Ordered keys are padded.
|
||||
// Default is true. This option only exists for strings, where ordering
|
||||
// comes at the cost of having rather long padded keys.
|
||||
enum OrderType {
|
||||
option allow_alias = true;
|
||||
UNORDERED = 0;
|
||||
ASCENDING = 1;
|
||||
DESCENDING = 2;
|
||||
}
|
||||
// Type of the ordering
|
||||
// eg. ascending, descending, unordered
|
||||
OrderType orderType = 2;
|
||||
}
|
||||
|
||||
message Index {
|
||||
// Field to index on.
|
||||
// eg. email
|
||||
string fieldName = 1;
|
||||
// Type of index
|
||||
// eg. eq
|
||||
string type = 2;
|
||||
Order order = 3;
|
||||
|
||||
// Do not allow duplicate values of this field in the index.
|
||||
// Useful for emails, usernames, post slugs etc.
|
||||
bool unique = 4;
|
||||
|
||||
// Strings for ordering will be padded to a fix length
|
||||
// Not a useful property for Querying, please ignore this at query time.
|
||||
// Number is in bytes, not string characters. Choose a sufficiently big one.
|
||||
// Consider that each character might take 4 bytes given the
|
||||
// internals of reverse ordering. So a good rule of thumbs is expected
|
||||
// characters in a string X 4
|
||||
int64 stringOrderPadLength = 5;
|
||||
// True = base32 encode ordered strings for easier management
|
||||
// or false = keep 4 bytes long runes that might dispaly weirdly
|
||||
bool Base32Encode = 6;
|
||||
|
||||
string FloatFormat = 7;
|
||||
float Float64Max = 8;
|
||||
float Float32Max = 9;
|
||||
}
|
||||
|
||||
|
||||
message CreateRequest {
|
||||
// JSON marshalled record to save
|
||||
string value = 1;
|
||||
}
|
||||
|
||||
message CreateResponse {
|
||||
}
|
||||
|
||||
message UpdateRequest {
|
||||
// JSON marshalled record to save
|
||||
string value = 1;
|
||||
}
|
||||
|
||||
message UpdateResponse {
|
||||
|
||||
}
|
||||
|
||||
message ReadRequest {
|
||||
Query query = 1;
|
||||
}
|
||||
|
||||
message ReadResponse {
|
||||
// JSON marshalled record found
|
||||
string value = 1;
|
||||
}
|
||||
|
||||
message DeleteRequest {
|
||||
Query query = 1;
|
||||
}
|
||||
|
||||
message DeleteResponse {
|
||||
}
|
||||
|
||||
message CreateIndexRequest {
|
||||
Index index = 1;
|
||||
}
|
||||
|
||||
message CreateIndexResponse {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user