Recursive record type for DB (#144)

This commit is contained in:
Janos Dobronszki
2021-06-08 16:03:59 +01:00
committed by GitHub
parent 01380190aa
commit dc4a493805
7 changed files with 171 additions and 89 deletions

View File

@@ -2,7 +2,12 @@
"create": [{
"title": "Create a record",
"request": {
"record": "{\"id\": \"1\", \"name\": \"Jane\", \"age\": 42, \"isActive\":true}"
"record": {
"id": "1",
"name": "Jane",
"age": 42,
"isActive":true
}
},
"response": {
"id": "1"
@@ -18,7 +23,10 @@
"update": [{
"title": "Update a record",
"request": {
"record": "{\"id\": \"1\", \"age\": 43}"
"record": {
"id": "1",
"age": 43
}
},
"response": {
}
@@ -29,7 +37,12 @@
"query": "age == 43"
},
"response": {
"records": "[{\"id\": \"1\", \"name\": \"Jane\", \"age\": 43, \"isActive\":true}]"
"records": [{
"id": "1",
"name": "Jane",
"age": 42,
"isActive":true
}]
}
}]
}

View File

@@ -14,6 +14,7 @@ import (
gorm2 "github.com/micro/services/pkg/gorm"
"github.com/micro/services/pkg/tenant"
"github.com/patrickmn/go-cache"
"google.golang.org/protobuf/types/known/structpb"
"gorm.io/datatypes"
"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
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")
}
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)
}
m := map[string]interface{}{}
err = json.Unmarshal([]byte(req.Record), &m)
if err != nil {
return err
}
m := req.Record.AsMap()
if _, ok := m[idKey].(string); !ok {
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 {
if len(req.Record) == 0 {
if len(req.Record.AsMap()) == 0 {
return errors.BadRequest("db.update", "missing record")
}
tenantId, ok := tenant.FromContext(ctx)
@@ -98,11 +95,7 @@ func (e *Db) Update(ctx context.Context, req *db.UpdateRequest, rsp *db.UpdateRe
return err
}
m := map[string]interface{}{}
err = json.Unmarshal([]byte(req.Record), &m)
if err != nil {
return err
}
m := req.Record.AsMap()
// where ID is specified do a single update record update
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 {
return err
}
ret := []map[string]interface{}{}
rsp.Records = []*structpb.Struct{}
for _, rec := range recs {
m, err := rec.Data.MarshalJSON()
if err != nil {
@@ -191,10 +185,15 @@ func (e *Db) Read(ctx context.Context, req *db.ReadRequest, rsp *db.ReadResponse
ma := map[string]interface{}{}
json.Unmarshal(m, &ma)
ma[idKey] = rec.ID
ret = append(ret, ma)
m, _ = json.Marshal(ma)
s := &structpb.Struct{}
err = s.UnmarshalJSON(m)
if err != nil {
return err
}
rsp.Records = append(rsp.Records, s)
}
bs, _ := json.Marshal(ret)
rsp.Records = string(bs)
return nil
}

View File

@@ -10,6 +10,8 @@ import (
)
var quoteEscape = fmt.Sprint(0x10FFFF)
var singleQuoteEscape = fmt.Sprint(0x10FFFE)
var backtickEscape = fmt.Sprint(0x10FFFD)
const (
itemIgnore = iota
@@ -53,6 +55,8 @@ var expressions = []lexer.TokenExpr{
{`>`, itemGreaterThan},
{`[0-9]+`, itemInt},
{`"(?:[^"\\]|\\.)*"`, itemString},
{"`" + `(?:[^"\\]|\\.)*` + "`", itemString},
{`'(?:[^"\\]|\\.)*'`, itemString},
{`[\<\>\!\=\+\-\|\&\*\/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")
}
q = strings.Replace(q, `""`, quoteEscape, -1)
q = strings.Replace(q, "``", singleQuoteEscape, -1)
q = strings.Replace(q, "''", backtickEscape, -1)
tokens, err := lexer.Lex(q, expressions)
if err != nil {
return nil, err
@@ -102,7 +109,11 @@ func Parse(q string) ([]Query, error) {
if len(token.Text) < 2 {
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:
switch current.Op {
case itemEquals, itemNotEquals:

View File

@@ -20,7 +20,7 @@ func TestLexing(t *testing.T) {
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 ||
tokens[1].Typ != itemEquals ||
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
tCase{
Q: `a == 12 and name != "He said ""yes""!"`,
Q: `a == 12 and name != 'He said ""yes""!'`,
E: []Query{
Query{
Field: "a",

View File

@@ -1,12 +1,13 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.15.6
// protoc v3.6.1
// source: proto/db.proto
package db
import (
_struct "github.com/golang/protobuf/ptypes/struct"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
@@ -118,7 +119,7 @@ type ReadResponse struct {
unknownFields protoimpl.UnknownFields
// 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() {
@@ -153,11 +154,11 @@ func (*ReadResponse) Descriptor() ([]byte, []int) {
return file_proto_db_proto_rawDescGZIP(), []int{1}
}
func (x *ReadResponse) GetRecords() string {
func (x *ReadResponse) GetRecords() []*_struct.Struct {
if x != nil {
return x.Records
}
return ""
return nil
}
type CreateRequest struct {
@@ -167,7 +168,7 @@ type CreateRequest struct {
Table string `protobuf:"bytes,1,opt,name=table,proto3" json:"table,omitempty"`
// 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() {
@@ -209,11 +210,11 @@ func (x *CreateRequest) GetTable() string {
return ""
}
func (x *CreateRequest) GetRecord() string {
func (x *CreateRequest) GetRecord() *_struct.Struct {
if x != nil {
return x.Record
}
return ""
return nil
}
type CreateResponse struct {
@@ -272,8 +273,8 @@ type UpdateRequest struct {
Table string `protobuf:"bytes,1,opt,name=table,proto3" json:"table,omitempty"`
// query filter if applying to multiple records
Query string `protobuf:"bytes,2,opt,name=query,proto3" json:"query,omitempty"`
// JSON encoded record or records (can be array or object)
Record string `protobuf:"bytes,3,opt,name=record,proto3" json:"record,omitempty"`
// record, JSON object
Record *_struct.Struct `protobuf:"bytes,3,opt,name=record,proto3" json:"record,omitempty"`
}
func (x *UpdateRequest) Reset() {
@@ -322,11 +323,11 @@ func (x *UpdateRequest) GetQuery() string {
return ""
}
func (x *UpdateRequest) GetRecord() string {
func (x *UpdateRequest) GetRecord() *_struct.Struct {
if x != nil {
return x.Record
}
return ""
return nil
}
type UpdateResponse struct {
@@ -465,50 +466,57 @@ var File_proto_db_proto protoreflect.FileDescriptor
var file_proto_db_proto_rawDesc = []byte{
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,
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, 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, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05,
0x52, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x69, 0x6d, 0x69,
0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x18,
0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x42, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52,
0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x42, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x6f, 0x72, 0x64, 0x65,
0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x22, 0x28,
0x0a, 0x0c, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18,
0x0a, 0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x07, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x22, 0x3d, 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,
0x16, 0x0a, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
0x12, 0x02, 0x64, 0x62, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x22, 0x97, 0x01, 0x0a, 0x0b, 0x52, 0x65, 0x61, 0x64, 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, 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, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06,
0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18,
0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x18, 0x0a, 0x07,
0x6f, 0x72, 0x64, 0x65, 0x72, 0x42, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f,
0x72, 0x64, 0x65, 0x72, 0x42, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x18,
0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x22, 0x41, 0x0a, 0x0c,
0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x31, 0x0a, 0x07,
0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 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, 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,
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,
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,
0x05, 0x71, 0x75, 0x65, 0x72, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64,
0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x22, 0x10,
0x0a, 0x0e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
0x22, 0x35, 0x0a, 0x0d, 0x44, 0x65, 0x6c, 0x65, 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, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x02, 0x20,
0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x10, 0x0a, 0x0e, 0x44, 0x65, 0x6c, 0x65, 0x74,
0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xca, 0x01, 0x0a, 0x02, 0x44, 0x62,
0x12, 0x31, 0x0a, 0x06, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x12, 0x11, 0x2e, 0x64, 0x62, 0x2e,
0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e,
0x64, 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x22, 0x00, 0x12, 0x2b, 0x0a, 0x04, 0x52, 0x65, 0x61, 0x64, 0x12, 0x0f, 0x2e, 0x64, 0x62,
0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x64,
0x62, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00,
0x12, 0x31, 0x0a, 0x06, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x11, 0x2e, 0x64, 0x62, 0x2e,
0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e,
0x64, 0x62, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x22, 0x00, 0x12, 0x31, 0x0a, 0x06, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x11, 0x2e,
0x64, 0x62, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x1a, 0x12, 0x2e, 0x64, 0x62, 0x2e, 0x44, 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,
0x05, 0x71, 0x75, 0x65, 0x72, 0x79, 0x12, 0x2f, 0x0a, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64,
0x18, 0x03, 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, 0x10, 0x0a, 0x0e, 0x55, 0x70, 0x64, 0x61, 0x74,
0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x35, 0x0a, 0x0d, 0x44, 0x65, 0x6c,
0x65, 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, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64,
0x22, 0x10, 0x0a, 0x0e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x73, 0x65, 0x32, 0xca, 0x01, 0x0a, 0x02, 0x44, 0x62, 0x12, 0x31, 0x0a, 0x06, 0x43, 0x72, 0x65,
0x61, 0x74, 0x65, 0x12, 0x11, 0x2e, 0x64, 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x64, 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61,
0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x2b, 0x0a, 0x04,
0x52, 0x65, 0x61, 0x64, 0x12, 0x0f, 0x2e, 0x64, 0x62, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x64, 0x62, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52,
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x31, 0x0a, 0x06, 0x55, 0x70, 0x64,
0x61, 0x74, 0x65, 0x12, 0x11, 0x2e, 0x64, 0x62, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x64, 0x62, 0x2e, 0x55, 0x70, 0x64, 0x61,
0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x31, 0x0a, 0x06,
0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x11, 0x2e, 0x64, 0x62, 0x2e, 0x44, 0x65, 0x6c, 0x65,
0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x64, 0x62, 0x2e, 0x44,
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 (
@@ -533,21 +541,25 @@ var file_proto_db_proto_goTypes = []interface{}{
(*UpdateResponse)(nil), // 5: db.UpdateResponse
(*DeleteRequest)(nil), // 6: db.DeleteRequest
(*DeleteResponse)(nil), // 7: db.DeleteResponse
(*_struct.Struct)(nil), // 8: google.protobuf.Struct
}
var file_proto_db_proto_depIdxs = []int32{
2, // 0: db.Db.Create:input_type -> db.CreateRequest
0, // 1: db.Db.Read:input_type -> db.ReadRequest
4, // 2: db.Db.Update:input_type -> db.UpdateRequest
6, // 3: db.Db.Delete:input_type -> db.DeleteRequest
3, // 4: db.Db.Create:output_type -> db.CreateResponse
1, // 5: db.Db.Read:output_type -> db.ReadResponse
5, // 6: db.Db.Update:output_type -> db.UpdateResponse
7, // 7: db.Db.Delete:output_type -> db.DeleteResponse
4, // [4:8] is the sub-list for method output_type
0, // [0:4] 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
8, // 0: db.ReadResponse.records:type_name -> google.protobuf.Struct
8, // 1: db.CreateRequest.record:type_name -> google.protobuf.Struct
8, // 2: db.UpdateRequest.record:type_name -> google.protobuf.Struct
2, // 3: db.Db.Create:input_type -> db.CreateRequest
0, // 4: db.Db.Read:input_type -> db.ReadRequest
4, // 5: db.Db.Update:input_type -> db.UpdateRequest
6, // 6: db.Db.Delete:input_type -> db.DeleteRequest
3, // 7: db.Db.Create:output_type -> db.CreateResponse
1, // 8: db.Db.Read:output_type -> db.ReadResponse
5, // 9: db.Db.Update:output_type -> db.UpdateResponse
7, // 10: db.Db.Delete:output_type -> db.DeleteResponse
7, // [7:11] is the sub-list for method output_type
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() }

View File

@@ -6,6 +6,7 @@ package db
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
_ "github.com/golang/protobuf/ptypes/struct"
math "math"
)

View File

@@ -1,4 +1,5 @@
syntax = "proto3";
import "google/protobuf/struct.proto";
package db;
@@ -28,13 +29,13 @@ message ReadRequest {
message ReadResponse {
// JSON encoded records
string records = 1;
repeated google.protobuf.Struct records = 1;
}
message CreateRequest {
string table = 1;
// JSON encoded record or records (can be array or object)
string record = 2;
google.protobuf.Struct record = 2;
}
message CreateResponse {
@@ -46,8 +47,8 @@ message UpdateRequest {
string table = 1;
// query filter if applying to multiple records
string query = 2;
// JSON encoded record or records (can be array or object)
string record = 3;
// record, JSON object
google.protobuf.Struct record = 3;
}
message UpdateResponse {