mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-24 08:25:31 +00:00
Recursive record type for DB (#144)
This commit is contained in:
@@ -2,7 +2,12 @@
|
|||||||
"create": [{
|
"create": [{
|
||||||
"title": "Create a record",
|
"title": "Create a record",
|
||||||
"request": {
|
"request": {
|
||||||
"record": "{\"id\": \"1\", \"name\": \"Jane\", \"age\": 42, \"isActive\":true}"
|
"record": {
|
||||||
|
"id": "1",
|
||||||
|
"name": "Jane",
|
||||||
|
"age": 42,
|
||||||
|
"isActive":true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"response": {
|
"response": {
|
||||||
"id": "1"
|
"id": "1"
|
||||||
@@ -18,7 +23,10 @@
|
|||||||
"update": [{
|
"update": [{
|
||||||
"title": "Update a record",
|
"title": "Update a record",
|
||||||
"request": {
|
"request": {
|
||||||
"record": "{\"id\": \"1\", \"age\": 43}"
|
"record": {
|
||||||
|
"id": "1",
|
||||||
|
"age": 43
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"response": {
|
"response": {
|
||||||
}
|
}
|
||||||
@@ -29,7 +37,12 @@
|
|||||||
"query": "age == 43"
|
"query": "age == 43"
|
||||||
},
|
},
|
||||||
"response": {
|
"response": {
|
||||||
"records": "[{\"id\": \"1\", \"name\": \"Jane\", \"age\": 43, \"isActive\":true}]"
|
"records": [{
|
||||||
|
"id": "1",
|
||||||
|
"name": "Jane",
|
||||||
|
"age": 42,
|
||||||
|
"isActive":true
|
||||||
|
}]
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
gorm2 "github.com/micro/services/pkg/gorm"
|
gorm2 "github.com/micro/services/pkg/gorm"
|
||||||
"github.com/micro/services/pkg/tenant"
|
"github.com/micro/services/pkg/tenant"
|
||||||
"github.com/patrickmn/go-cache"
|
"github.com/patrickmn/go-cache"
|
||||||
|
"google.golang.org/protobuf/types/known/structpb"
|
||||||
"gorm.io/datatypes"
|
"gorm.io/datatypes"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@@ -37,7 +38,7 @@ type Db struct {
|
|||||||
|
|
||||||
// Call is a single request handler called via client.Call or the generated client code
|
// Call is a single request handler called via client.Call or the generated client code
|
||||||
func (e *Db) Create(ctx context.Context, req *db.CreateRequest, rsp *db.CreateResponse) error {
|
func (e *Db) Create(ctx context.Context, req *db.CreateRequest, rsp *db.CreateResponse) error {
|
||||||
if len(req.Record) == 0 {
|
if len(req.Record.AsMap()) == 0 {
|
||||||
return errors.BadRequest("db.create", "missing record")
|
return errors.BadRequest("db.create", "missing record")
|
||||||
}
|
}
|
||||||
tenantId, ok := tenant.FromContext(ctx)
|
tenantId, ok := tenant.FromContext(ctx)
|
||||||
@@ -60,11 +61,7 @@ func (e *Db) Create(ctx context.Context, req *db.CreateRequest, rsp *db.CreateRe
|
|||||||
c.Set(req.Table, true, 0)
|
c.Set(req.Table, true, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
m := map[string]interface{}{}
|
m := req.Record.AsMap()
|
||||||
err = json.Unmarshal([]byte(req.Record), &m)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, ok := m[idKey].(string); !ok {
|
if _, ok := m[idKey].(string); !ok {
|
||||||
m[idKey] = uuid.New().String()
|
m[idKey] = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -85,7 +82,7 @@ func (e *Db) Create(ctx context.Context, req *db.CreateRequest, rsp *db.CreateRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Db) Update(ctx context.Context, req *db.UpdateRequest, rsp *db.UpdateResponse) error {
|
func (e *Db) Update(ctx context.Context, req *db.UpdateRequest, rsp *db.UpdateResponse) error {
|
||||||
if len(req.Record) == 0 {
|
if len(req.Record.AsMap()) == 0 {
|
||||||
return errors.BadRequest("db.update", "missing record")
|
return errors.BadRequest("db.update", "missing record")
|
||||||
}
|
}
|
||||||
tenantId, ok := tenant.FromContext(ctx)
|
tenantId, ok := tenant.FromContext(ctx)
|
||||||
@@ -98,11 +95,7 @@ func (e *Db) Update(ctx context.Context, req *db.UpdateRequest, rsp *db.UpdateRe
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
m := map[string]interface{}{}
|
m := req.Record.AsMap()
|
||||||
err = json.Unmarshal([]byte(req.Record), &m)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// where ID is specified do a single update record update
|
// where ID is specified do a single update record update
|
||||||
id, ok := m[idKey].(string)
|
id, ok := m[idKey].(string)
|
||||||
@@ -182,7 +175,8 @@ func (e *Db) Read(ctx context.Context, req *db.ReadRequest, rsp *db.ReadResponse
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ret := []map[string]interface{}{}
|
|
||||||
|
rsp.Records = []*structpb.Struct{}
|
||||||
for _, rec := range recs {
|
for _, rec := range recs {
|
||||||
m, err := rec.Data.MarshalJSON()
|
m, err := rec.Data.MarshalJSON()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -191,10 +185,15 @@ func (e *Db) Read(ctx context.Context, req *db.ReadRequest, rsp *db.ReadResponse
|
|||||||
ma := map[string]interface{}{}
|
ma := map[string]interface{}{}
|
||||||
json.Unmarshal(m, &ma)
|
json.Unmarshal(m, &ma)
|
||||||
ma[idKey] = rec.ID
|
ma[idKey] = rec.ID
|
||||||
ret = append(ret, ma)
|
m, _ = json.Marshal(ma)
|
||||||
|
s := &structpb.Struct{}
|
||||||
|
err = s.UnmarshalJSON(m)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
bs, _ := json.Marshal(ret)
|
rsp.Records = append(rsp.Records, s)
|
||||||
rsp.Records = string(bs)
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var quoteEscape = fmt.Sprint(0x10FFFF)
|
var quoteEscape = fmt.Sprint(0x10FFFF)
|
||||||
|
var singleQuoteEscape = fmt.Sprint(0x10FFFE)
|
||||||
|
var backtickEscape = fmt.Sprint(0x10FFFD)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
itemIgnore = iota
|
itemIgnore = iota
|
||||||
@@ -53,6 +55,8 @@ var expressions = []lexer.TokenExpr{
|
|||||||
{`>`, itemGreaterThan},
|
{`>`, itemGreaterThan},
|
||||||
{`[0-9]+`, itemInt},
|
{`[0-9]+`, itemInt},
|
||||||
{`"(?:[^"\\]|\\.)*"`, itemString},
|
{`"(?:[^"\\]|\\.)*"`, itemString},
|
||||||
|
{"`" + `(?:[^"\\]|\\.)*` + "`", itemString},
|
||||||
|
{`'(?:[^"\\]|\\.)*'`, itemString},
|
||||||
{`[\<\>\!\=\+\-\|\&\*\/A-Za-z][A-Za-z0-9_]*`, itemFieldName},
|
{`[\<\>\!\=\+\-\|\&\*\/A-Za-z][A-Za-z0-9_]*`, itemFieldName},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +71,9 @@ func Parse(q string) ([]Query, error) {
|
|||||||
return nil, errors.New("query contains illegal max rune")
|
return nil, errors.New("query contains illegal max rune")
|
||||||
}
|
}
|
||||||
q = strings.Replace(q, `""`, quoteEscape, -1)
|
q = strings.Replace(q, `""`, quoteEscape, -1)
|
||||||
|
q = strings.Replace(q, "``", singleQuoteEscape, -1)
|
||||||
|
q = strings.Replace(q, "''", backtickEscape, -1)
|
||||||
|
|
||||||
tokens, err := lexer.Lex(q, expressions)
|
tokens, err := lexer.Lex(q, expressions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -102,7 +109,11 @@ func Parse(q string) ([]Query, error) {
|
|||||||
if len(token.Text) < 2 {
|
if len(token.Text) < 2 {
|
||||||
return nil, fmt.Errorf("string literal too short: '%v'", token.Text)
|
return nil, fmt.Errorf("string literal too short: '%v'", token.Text)
|
||||||
}
|
}
|
||||||
current.Value = strings.Replace(token.Text[1:len(token.Text)-1], quoteEscape, `"`, -1)
|
to := token.Text[1 : len(token.Text)-1]
|
||||||
|
to = strings.Replace(to, quoteEscape, `"`, -1)
|
||||||
|
to = strings.Replace(to, singleQuoteEscape, `'`, -1)
|
||||||
|
to = strings.Replace(to, backtickEscape, "`", -1)
|
||||||
|
current.Value = to
|
||||||
case itemBoolTrue:
|
case itemBoolTrue:
|
||||||
switch current.Op {
|
switch current.Op {
|
||||||
case itemEquals, itemNotEquals:
|
case itemEquals, itemNotEquals:
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func TestLexing(t *testing.T) {
|
|||||||
t.Fatal(tokens)
|
t.Fatal(tokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
tokens, err = lexer.Lex(`a == 12 and name != "nandos"`, expressions)
|
tokens, err = lexer.Lex(`a == 12 and name != 'nandos'`, expressions)
|
||||||
if tokens[0].Typ != itemFieldName ||
|
if tokens[0].Typ != itemFieldName ||
|
||||||
tokens[1].Typ != itemEquals ||
|
tokens[1].Typ != itemEquals ||
|
||||||
tokens[2].Typ != itemInt ||
|
tokens[2].Typ != itemInt ||
|
||||||
@@ -55,9 +55,54 @@ func TestParsing(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
tCase{
|
||||||
|
Q: `a == 12 and name != "nan'dos"`,
|
||||||
|
E: []Query{
|
||||||
|
Query{
|
||||||
|
Field: "a",
|
||||||
|
Value: int64(12),
|
||||||
|
Op: itemEquals,
|
||||||
|
},
|
||||||
|
Query{
|
||||||
|
Field: "name",
|
||||||
|
Value: "nan'dos",
|
||||||
|
Op: itemNotEquals,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tCase{
|
||||||
|
Q: `a == 12 and name != 'nandos'`,
|
||||||
|
E: []Query{
|
||||||
|
Query{
|
||||||
|
Field: "a",
|
||||||
|
Value: int64(12),
|
||||||
|
Op: itemEquals,
|
||||||
|
},
|
||||||
|
Query{
|
||||||
|
Field: "name",
|
||||||
|
Value: "nandos",
|
||||||
|
Op: itemNotEquals,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tCase{
|
||||||
|
Q: "a == 12 and name != `nandos`",
|
||||||
|
E: []Query{
|
||||||
|
Query{
|
||||||
|
Field: "a",
|
||||||
|
Value: int64(12),
|
||||||
|
Op: itemEquals,
|
||||||
|
},
|
||||||
|
Query{
|
||||||
|
Field: "name",
|
||||||
|
Value: "nandos",
|
||||||
|
Op: itemNotEquals,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
// test escaping quotes
|
// test escaping quotes
|
||||||
tCase{
|
tCase{
|
||||||
Q: `a == 12 and name != "He said ""yes""!"`,
|
Q: `a == 12 and name != 'He said ""yes""!'`,
|
||||||
E: []Query{
|
E: []Query{
|
||||||
Query{
|
Query{
|
||||||
Field: "a",
|
Field: "a",
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.26.0
|
// protoc-gen-go v1.26.0
|
||||||
// protoc v3.15.6
|
// protoc v3.6.1
|
||||||
// source: proto/db.proto
|
// source: proto/db.proto
|
||||||
|
|
||||||
package db
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
_struct "github.com/golang/protobuf/ptypes/struct"
|
||||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||||
reflect "reflect"
|
reflect "reflect"
|
||||||
@@ -118,7 +119,7 @@ type ReadResponse struct {
|
|||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
// JSON encoded records
|
// JSON encoded records
|
||||||
Records string `protobuf:"bytes,1,opt,name=records,proto3" json:"records,omitempty"`
|
Records []*_struct.Struct `protobuf:"bytes,1,rep,name=records,proto3" json:"records,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ReadResponse) Reset() {
|
func (x *ReadResponse) Reset() {
|
||||||
@@ -153,11 +154,11 @@ func (*ReadResponse) Descriptor() ([]byte, []int) {
|
|||||||
return file_proto_db_proto_rawDescGZIP(), []int{1}
|
return file_proto_db_proto_rawDescGZIP(), []int{1}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ReadResponse) GetRecords() string {
|
func (x *ReadResponse) GetRecords() []*_struct.Struct {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Records
|
return x.Records
|
||||||
}
|
}
|
||||||
return ""
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateRequest struct {
|
type CreateRequest struct {
|
||||||
@@ -167,7 +168,7 @@ type CreateRequest struct {
|
|||||||
|
|
||||||
Table string `protobuf:"bytes,1,opt,name=table,proto3" json:"table,omitempty"`
|
Table string `protobuf:"bytes,1,opt,name=table,proto3" json:"table,omitempty"`
|
||||||
// JSON encoded record or records (can be array or object)
|
// JSON encoded record or records (can be array or object)
|
||||||
Record string `protobuf:"bytes,2,opt,name=record,proto3" json:"record,omitempty"`
|
Record *_struct.Struct `protobuf:"bytes,2,opt,name=record,proto3" json:"record,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *CreateRequest) Reset() {
|
func (x *CreateRequest) Reset() {
|
||||||
@@ -209,11 +210,11 @@ func (x *CreateRequest) GetTable() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *CreateRequest) GetRecord() string {
|
func (x *CreateRequest) GetRecord() *_struct.Struct {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Record
|
return x.Record
|
||||||
}
|
}
|
||||||
return ""
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateResponse struct {
|
type CreateResponse struct {
|
||||||
@@ -272,8 +273,8 @@ type UpdateRequest struct {
|
|||||||
Table string `protobuf:"bytes,1,opt,name=table,proto3" json:"table,omitempty"`
|
Table string `protobuf:"bytes,1,opt,name=table,proto3" json:"table,omitempty"`
|
||||||
// query filter if applying to multiple records
|
// query filter if applying to multiple records
|
||||||
Query string `protobuf:"bytes,2,opt,name=query,proto3" json:"query,omitempty"`
|
Query string `protobuf:"bytes,2,opt,name=query,proto3" json:"query,omitempty"`
|
||||||
// JSON encoded record or records (can be array or object)
|
// record, JSON object
|
||||||
Record string `protobuf:"bytes,3,opt,name=record,proto3" json:"record,omitempty"`
|
Record *_struct.Struct `protobuf:"bytes,3,opt,name=record,proto3" json:"record,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *UpdateRequest) Reset() {
|
func (x *UpdateRequest) Reset() {
|
||||||
@@ -322,11 +323,11 @@ func (x *UpdateRequest) GetQuery() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *UpdateRequest) GetRecord() string {
|
func (x *UpdateRequest) GetRecord() *_struct.Struct {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Record
|
return x.Record
|
||||||
}
|
}
|
||||||
return ""
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateResponse struct {
|
type UpdateResponse struct {
|
||||||
@@ -465,50 +466,57 @@ var File_proto_db_proto protoreflect.FileDescriptor
|
|||||||
|
|
||||||
var file_proto_db_proto_rawDesc = []byte{
|
var file_proto_db_proto_rawDesc = []byte{
|
||||||
0x0a, 0x0e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
0x0a, 0x0e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||||
0x12, 0x02, 0x64, 0x62, 0x22, 0x97, 0x01, 0x0a, 0x0b, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71,
|
0x12, 0x02, 0x64, 0x62, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f,
|
||||||
0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x01, 0x20,
|
0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x2e, 0x70, 0x72, 0x6f,
|
||||||
0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x71, 0x75,
|
0x74, 0x6f, 0x22, 0x97, 0x01, 0x0a, 0x0b, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65,
|
||||||
0x65, 0x72, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x71, 0x75, 0x65, 0x72, 0x79,
|
0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||||
0x12, 0x16, 0x0a, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05,
|
0x09, 0x52, 0x05, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x71, 0x75, 0x65, 0x72,
|
||||||
0x52, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x69, 0x6d, 0x69,
|
0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x71, 0x75, 0x65, 0x72, 0x79, 0x12, 0x16,
|
||||||
0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x18,
|
0x0a, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06,
|
||||||
0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x42, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52,
|
0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18,
|
||||||
0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x42, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x6f, 0x72, 0x64, 0x65,
|
0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x18, 0x0a, 0x07,
|
||||||
0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x22, 0x28,
|
0x6f, 0x72, 0x64, 0x65, 0x72, 0x42, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f,
|
||||||
0x0a, 0x0c, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18,
|
0x72, 0x64, 0x65, 0x72, 0x42, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x18,
|
||||||
0x0a, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
|
0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x22, 0x41, 0x0a, 0x0c,
|
||||||
0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x3d, 0x0a, 0x0d, 0x43, 0x72, 0x65, 0x61,
|
0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x31, 0x0a, 0x07,
|
||||||
0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x61, 0x62,
|
0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x17, 0x2e,
|
||||||
0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x12,
|
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e,
|
||||||
0x16, 0x0a, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
|
0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x52, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22,
|
||||||
|
0x56, 0x0a, 0x0d, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
|
||||||
|
0x12, 0x14, 0x0a, 0x05, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||||
|
0x05, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x2f, 0x0a, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64,
|
||||||
|
0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
|
||||||
|
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x52,
|
||||||
0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x22, 0x20, 0x0a, 0x0e, 0x43, 0x72, 0x65, 0x61, 0x74,
|
0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x22, 0x20, 0x0a, 0x0e, 0x43, 0x72, 0x65, 0x61, 0x74,
|
||||||
0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18,
|
0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18,
|
||||||
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x53, 0x0a, 0x0d, 0x55, 0x70, 0x64,
|
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x6c, 0x0a, 0x0d, 0x55, 0x70, 0x64,
|
||||||
0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x61,
|
0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x61,
|
||||||
0x62, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x61, 0x62, 0x6c, 0x65,
|
0x62, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x61, 0x62, 0x6c, 0x65,
|
||||||
0x12, 0x14, 0x0a, 0x05, 0x71, 0x75, 0x65, 0x72, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
|
0x12, 0x14, 0x0a, 0x05, 0x71, 0x75, 0x65, 0x72, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||||
0x05, 0x71, 0x75, 0x65, 0x72, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64,
|
0x05, 0x71, 0x75, 0x65, 0x72, 0x79, 0x12, 0x2f, 0x0a, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64,
|
||||||
0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x22, 0x10,
|
0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
|
||||||
0x0a, 0x0e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
|
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x52,
|
||||||
0x22, 0x35, 0x0a, 0x0d, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
|
0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x22, 0x10, 0x0a, 0x0e, 0x55, 0x70, 0x64, 0x61, 0x74,
|
||||||
0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
|
0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x35, 0x0a, 0x0d, 0x44, 0x65, 0x6c,
|
||||||
0x52, 0x05, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x02, 0x20,
|
0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x61,
|
||||||
0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x10, 0x0a, 0x0e, 0x44, 0x65, 0x6c, 0x65, 0x74,
|
0x62, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x61, 0x62, 0x6c, 0x65,
|
||||||
0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xca, 0x01, 0x0a, 0x02, 0x44, 0x62,
|
0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64,
|
||||||
0x12, 0x31, 0x0a, 0x06, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x12, 0x11, 0x2e, 0x64, 0x62, 0x2e,
|
0x22, 0x10, 0x0a, 0x0e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
||||||
0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e,
|
0x73, 0x65, 0x32, 0xca, 0x01, 0x0a, 0x02, 0x44, 0x62, 0x12, 0x31, 0x0a, 0x06, 0x43, 0x72, 0x65,
|
||||||
0x64, 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
|
0x61, 0x74, 0x65, 0x12, 0x11, 0x2e, 0x64, 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52,
|
||||||
0x65, 0x22, 0x00, 0x12, 0x2b, 0x0a, 0x04, 0x52, 0x65, 0x61, 0x64, 0x12, 0x0f, 0x2e, 0x64, 0x62,
|
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x64, 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61,
|
||||||
0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x64,
|
0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x2b, 0x0a, 0x04,
|
||||||
0x62, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00,
|
0x52, 0x65, 0x61, 0x64, 0x12, 0x0f, 0x2e, 0x64, 0x62, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65,
|
||||||
0x12, 0x31, 0x0a, 0x06, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x11, 0x2e, 0x64, 0x62, 0x2e,
|
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x64, 0x62, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52,
|
||||||
0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e,
|
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x31, 0x0a, 0x06, 0x55, 0x70, 0x64,
|
||||||
0x64, 0x62, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
|
0x61, 0x74, 0x65, 0x12, 0x11, 0x2e, 0x64, 0x62, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52,
|
||||||
0x65, 0x22, 0x00, 0x12, 0x31, 0x0a, 0x06, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x11, 0x2e,
|
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x64, 0x62, 0x2e, 0x55, 0x70, 0x64, 0x61,
|
||||||
0x64, 0x62, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
|
0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x31, 0x0a, 0x06,
|
||||||
0x1a, 0x12, 0x2e, 0x64, 0x62, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70,
|
0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x11, 0x2e, 0x64, 0x62, 0x2e, 0x44, 0x65, 0x6c, 0x65,
|
||||||
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0c, 0x5a, 0x0a, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74,
|
0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x64, 0x62, 0x2e, 0x44,
|
||||||
0x6f, 0x3b, 0x64, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42,
|
||||||
|
0x0c, 0x5a, 0x0a, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x64, 0x62, 0x62, 0x06, 0x70,
|
||||||
|
0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -533,21 +541,25 @@ var file_proto_db_proto_goTypes = []interface{}{
|
|||||||
(*UpdateResponse)(nil), // 5: db.UpdateResponse
|
(*UpdateResponse)(nil), // 5: db.UpdateResponse
|
||||||
(*DeleteRequest)(nil), // 6: db.DeleteRequest
|
(*DeleteRequest)(nil), // 6: db.DeleteRequest
|
||||||
(*DeleteResponse)(nil), // 7: db.DeleteResponse
|
(*DeleteResponse)(nil), // 7: db.DeleteResponse
|
||||||
|
(*_struct.Struct)(nil), // 8: google.protobuf.Struct
|
||||||
}
|
}
|
||||||
var file_proto_db_proto_depIdxs = []int32{
|
var file_proto_db_proto_depIdxs = []int32{
|
||||||
2, // 0: db.Db.Create:input_type -> db.CreateRequest
|
8, // 0: db.ReadResponse.records:type_name -> google.protobuf.Struct
|
||||||
0, // 1: db.Db.Read:input_type -> db.ReadRequest
|
8, // 1: db.CreateRequest.record:type_name -> google.protobuf.Struct
|
||||||
4, // 2: db.Db.Update:input_type -> db.UpdateRequest
|
8, // 2: db.UpdateRequest.record:type_name -> google.protobuf.Struct
|
||||||
6, // 3: db.Db.Delete:input_type -> db.DeleteRequest
|
2, // 3: db.Db.Create:input_type -> db.CreateRequest
|
||||||
3, // 4: db.Db.Create:output_type -> db.CreateResponse
|
0, // 4: db.Db.Read:input_type -> db.ReadRequest
|
||||||
1, // 5: db.Db.Read:output_type -> db.ReadResponse
|
4, // 5: db.Db.Update:input_type -> db.UpdateRequest
|
||||||
5, // 6: db.Db.Update:output_type -> db.UpdateResponse
|
6, // 6: db.Db.Delete:input_type -> db.DeleteRequest
|
||||||
7, // 7: db.Db.Delete:output_type -> db.DeleteResponse
|
3, // 7: db.Db.Create:output_type -> db.CreateResponse
|
||||||
4, // [4:8] is the sub-list for method output_type
|
1, // 8: db.Db.Read:output_type -> db.ReadResponse
|
||||||
0, // [0:4] is the sub-list for method input_type
|
5, // 9: db.Db.Update:output_type -> db.UpdateResponse
|
||||||
0, // [0:0] is the sub-list for extension type_name
|
7, // 10: db.Db.Delete:output_type -> db.DeleteResponse
|
||||||
0, // [0:0] is the sub-list for extension extendee
|
7, // [7:11] is the sub-list for method output_type
|
||||||
0, // [0:0] is the sub-list for field type_name
|
3, // [3:7] is the sub-list for method input_type
|
||||||
|
3, // [3:3] is the sub-list for extension type_name
|
||||||
|
3, // [3:3] is the sub-list for extension extendee
|
||||||
|
0, // [0:3] is the sub-list for field type_name
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { file_proto_db_proto_init() }
|
func init() { file_proto_db_proto_init() }
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package db
|
|||||||
import (
|
import (
|
||||||
fmt "fmt"
|
fmt "fmt"
|
||||||
proto "github.com/golang/protobuf/proto"
|
proto "github.com/golang/protobuf/proto"
|
||||||
|
_ "github.com/golang/protobuf/ptypes/struct"
|
||||||
math "math"
|
math "math"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
|
import "google/protobuf/struct.proto";
|
||||||
|
|
||||||
package db;
|
package db;
|
||||||
|
|
||||||
@@ -28,13 +29,13 @@ message ReadRequest {
|
|||||||
|
|
||||||
message ReadResponse {
|
message ReadResponse {
|
||||||
// JSON encoded records
|
// JSON encoded records
|
||||||
string records = 1;
|
repeated google.protobuf.Struct records = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CreateRequest {
|
message CreateRequest {
|
||||||
string table = 1;
|
string table = 1;
|
||||||
// JSON encoded record or records (can be array or object)
|
// JSON encoded record or records (can be array or object)
|
||||||
string record = 2;
|
google.protobuf.Struct record = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CreateResponse {
|
message CreateResponse {
|
||||||
@@ -46,8 +47,8 @@ message UpdateRequest {
|
|||||||
string table = 1;
|
string table = 1;
|
||||||
// query filter if applying to multiple records
|
// query filter if applying to multiple records
|
||||||
string query = 2;
|
string query = 2;
|
||||||
// JSON encoded record or records (can be array or object)
|
// record, JSON object
|
||||||
string record = 3;
|
google.protobuf.Struct record = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message UpdateResponse {
|
message UpdateResponse {
|
||||||
|
|||||||
Reference in New Issue
Block a user