Przeglądaj źródła

完成insert接口开发

yjp 1 rok temu
rodzic
commit
7715370e8f

+ 9 - 2
dps.go

@@ -51,8 +51,15 @@ func DestroyClient(version string) error {
 
 	switch version {
 	case "v1":
-		return dpsv1.DestroyClient(client.(*dpsv1.Client))
+		err := dpsv1.DestroyClient(client.(*dpsv1.Client))
+		if err != nil {
+			return err
+		}
 	default:
-		return nil
+		break
 	}
+
+	delete(clientMap, version)
+
+	return nil
 }

+ 98 - 2
dpsv1/client.go

@@ -49,7 +49,7 @@ func DestroyClient(client *Client) error {
 }
 
 func (c *Client) AutoMigrate(req *ports.AutoMigrateRequest) error {
-	modelJsonByte, err := json.Marshal(req.Model)
+	tableModelDescribeJsonByte, err := json.Marshal(req.TableModelDescribe)
 	if err != nil {
 		return err
 	}
@@ -58,7 +58,7 @@ func (c *Client) AutoMigrate(req *ports.AutoMigrateRequest) error {
 		DatabaseID:            req.DatabaseID,
 		TablePrefixWithSchema: req.TablePrefixWithSchema,
 		Version:               req.Version,
-		Model:                 modelJsonByte,
+		TableModelDescribe:    tableModelDescribeJsonByte,
 	})
 	if err != nil {
 		return err
@@ -66,3 +66,99 @@ func (c *Client) AutoMigrate(req *ports.AutoMigrateRequest) error {
 
 	return nil
 }
+
+func (c *Client) Insert(req *ports.InsertRequest) (string, error) {
+	keysJsonByte, err := json.Marshal(req.Keys)
+	if err != nil {
+		return "", err
+	}
+
+	tableRowJsonByte, err := json.Marshal(req.TableRow)
+	if err != nil {
+		return "", err
+	}
+
+	reply, err := c.commandServiceClient.Insert(context.Background(), &request.InsertRequest{
+		DatabaseID:            req.DatabaseID,
+		TablePrefixWithSchema: req.TablePrefixWithSchema,
+		Version:               req.Version,
+		Keys:                  keysJsonByte,
+		TableRow:              tableRowJsonByte,
+		UserID:                req.UserID,
+	})
+	if err != nil {
+		return "", err
+	}
+
+	return reply.Statement, nil
+}
+
+// TODO InsertBatch
+
+func (c *Client) Delete(req *ports.DeleteRequest) (string, error) {
+	keysJsonByte, err := json.Marshal(req.Keys)
+	if err != nil {
+		return "", err
+	}
+
+	reply, err := c.commandServiceClient.Delete(context.Background(), &request.DeleteRequest{
+		DatabaseID:            req.DatabaseID,
+		TablePrefixWithSchema: req.TablePrefixWithSchema,
+		Version:               req.Version,
+		Keys:                  keysJsonByte,
+		UserID:                req.UserID,
+	})
+	if err != nil {
+		return "", err
+	}
+
+	return reply.Statement, nil
+}
+
+// TODO DeleteBatch
+
+func (c *Client) Update(req *ports.UpdateRequest) (string, error) {
+	keysJsonByte, err := json.Marshal(req.Keys)
+	if err != nil {
+		return "", err
+	}
+
+	newTableRowJsonByte, err := json.Marshal(req.NewTableRow)
+	if err != nil {
+		return "", err
+	}
+
+	reply, err := c.commandServiceClient.Update(context.Background(), &request.UpdateRequest{
+		DatabaseID:            req.DatabaseID,
+		TablePrefixWithSchema: req.TablePrefixWithSchema,
+		Version:               req.Version,
+		Keys:                  keysJsonByte,
+		NewTableRow:           newTableRowJsonByte,
+		UserID:                req.UserID,
+	})
+	if err != nil {
+		return "", err
+	}
+
+	return reply.Statement, nil
+}
+
+func (c *Client) Replay(req *ports.ReplayRequest) (string, error) {
+	keysJsonByte, err := json.Marshal(req.Keys)
+	if err != nil {
+		return "", err
+	}
+
+	reply, err := c.commandServiceClient.Replay(context.Background(), &request.ReplayRequest{
+		DatabaseID:            req.DatabaseID,
+		TablePrefixWithSchema: req.TablePrefixWithSchema,
+		Version:               req.Version,
+		Keys:                  keysJsonByte,
+		UserID:                req.UserID,
+	})
+	if err != nil {
+		return "", err
+	}
+
+	return reply.Statement, nil
+}

+ 0 - 9
dpsv1/request.go

@@ -1,9 +0,0 @@
-package dpsv1
-
-type AutoMigrateRequest struct {
-	DatabaseID  string
-	Schema      string
-	TablePrefix string
-	Version     string
-	Model       []byte
-}

+ 49 - 33
pb/v1/command.pb.go

@@ -31,7 +31,7 @@ var file_v1_command_proto_rawDesc = []byte{
 	0x1a, 0x19, 0x76, 0x31, 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2f, 0x63, 0x6f,
 	0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x67, 0x6f, 0x6f,
 	0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70,
-	0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0xce, 0x03, 0x0a, 0x0e, 0x43, 0x6f, 0x6d,
+	0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0xf2, 0x04, 0x0a, 0x0e, 0x43, 0x6f, 0x6d,
 	0x6d, 0x61, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x44, 0x0a, 0x0b, 0x41,
 	0x75, 0x74, 0x6f, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x65, 0x12, 0x1b, 0x2e, 0x72, 0x65, 0x71,
 	0x75, 0x65, 0x73, 0x74, 0x2e, 0x41, 0x75, 0x74, 0x6f, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x65,
@@ -47,49 +47,65 @@ var file_v1_command_proto_rawDesc = []byte{
 	0x73, 0x65, 0x72, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x72, 0x65,
 	0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x53, 0x74,
 	0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22,
-	0x00, 0x12, 0x46, 0x0a, 0x06, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x16, 0x2e, 0x72, 0x65,
-	0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75,
-	0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x43,
-	0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x52,
-	0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x46, 0x0a, 0x06, 0x55, 0x70, 0x64,
-	0x61, 0x74, 0x65, 0x12, 0x16, 0x2e, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x55, 0x70,
-	0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x72, 0x65,
-	0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x53, 0x74,
-	0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22,
-	0x00, 0x12, 0x46, 0x0a, 0x06, 0x52, 0x65, 0x70, 0x6c, 0x61, 0x79, 0x12, 0x16, 0x2e, 0x72, 0x65,
-	0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x61, 0x79, 0x52, 0x65, 0x71, 0x75,
-	0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x43,
-	0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x52,
-	0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x18, 0x5a, 0x16, 0x64, 0x70, 0x73,
-	0x2f, 0x61, 0x70, 0x69, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x5f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x62,
-	0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+	0x00, 0x12, 0x50, 0x0a, 0x0b, 0x49, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x42, 0x61, 0x74, 0x63, 0x68,
+	0x12, 0x1b, 0x2e, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x49, 0x6e, 0x73, 0x65, 0x72,
+	0x74, 0x42, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e,
+	0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64,
+	0x53, 0x74, 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
+	0x65, 0x22, 0x00, 0x12, 0x46, 0x0a, 0x06, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x16, 0x2e,
+	0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65,
+	0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
+	0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e,
+	0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x50, 0x0a, 0x0b, 0x44,
+	0x65, 0x6c, 0x65, 0x74, 0x65, 0x42, 0x61, 0x74, 0x63, 0x68, 0x12, 0x1b, 0x2e, 0x72, 0x65, 0x71,
+	0x75, 0x65, 0x73, 0x74, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x42, 0x61, 0x74, 0x63, 0x68,
+	0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e,
+	0x73, 0x65, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x6d,
+	0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x46, 0x0a,
+	0x06, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x16, 0x2e, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73,
+	0x74, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
+	0x22, 0x2e, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61,
+	0x6e, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f,
+	0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x46, 0x0a, 0x06, 0x52, 0x65, 0x70, 0x6c, 0x61, 0x79, 0x12,
+	0x16, 0x2e, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x61, 0x79,
+	0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e,
+	0x73, 0x65, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x6d,
+	0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x18, 0x5a,
+	0x16, 0x64, 0x70, 0x73, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x5f, 0x61, 0x70,
+	0x69, 0x2f, 0x70, 0x62, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var file_v1_command_proto_goTypes = []interface{}{
 	(*request.AutoMigrateRequest)(nil),        // 0: request.AutoMigrateRequest
 	(*request.TransactionOperation)(nil),      // 1: request.TransactionOperation
 	(*request.InsertRequest)(nil),             // 2: request.InsertRequest
-	(*request.DeleteRequest)(nil),             // 3: request.DeleteRequest
-	(*request.UpdateRequest)(nil),             // 4: request.UpdateRequest
-	(*request.ReplayRequest)(nil),             // 5: request.ReplayRequest
-	(*empty.Empty)(nil),                       // 6: google.protobuf.Empty
-	(*response.CommandStatementResponse)(nil), // 7: response.CommandStatementResponse
+	(*request.InsertBatchRequest)(nil),        // 3: request.InsertBatchRequest
+	(*request.DeleteRequest)(nil),             // 4: request.DeleteRequest
+	(*request.DeleteBatchRequest)(nil),        // 5: request.DeleteBatchRequest
+	(*request.UpdateRequest)(nil),             // 6: request.UpdateRequest
+	(*request.ReplayRequest)(nil),             // 7: request.ReplayRequest
+	(*empty.Empty)(nil),                       // 8: google.protobuf.Empty
+	(*response.CommandStatementResponse)(nil), // 9: response.CommandStatementResponse
 }
 var file_v1_command_proto_depIdxs = []int32{
 	0, // 0: v1.CommandService.AutoMigrate:input_type -> request.AutoMigrateRequest
 	1, // 1: v1.CommandService.Transaction:input_type -> request.TransactionOperation
 	2, // 2: v1.CommandService.Insert:input_type -> request.InsertRequest
-	3, // 3: v1.CommandService.Delete:input_type -> request.DeleteRequest
-	4, // 4: v1.CommandService.Update:input_type -> request.UpdateRequest
-	5, // 5: v1.CommandService.Replay:input_type -> request.ReplayRequest
-	6, // 6: v1.CommandService.AutoMigrate:output_type -> google.protobuf.Empty
-	7, // 7: v1.CommandService.Transaction:output_type -> response.CommandStatementResponse
-	7, // 8: v1.CommandService.Insert:output_type -> response.CommandStatementResponse
-	7, // 9: v1.CommandService.Delete:output_type -> response.CommandStatementResponse
-	7, // 10: v1.CommandService.Update:output_type -> response.CommandStatementResponse
-	7, // 11: v1.CommandService.Replay:output_type -> response.CommandStatementResponse
-	6, // [6:12] is the sub-list for method output_type
-	0, // [0:6] is the sub-list for method input_type
+	3, // 3: v1.CommandService.InsertBatch:input_type -> request.InsertBatchRequest
+	4, // 4: v1.CommandService.Delete:input_type -> request.DeleteRequest
+	5, // 5: v1.CommandService.DeleteBatch:input_type -> request.DeleteBatchRequest
+	6, // 6: v1.CommandService.Update:input_type -> request.UpdateRequest
+	7, // 7: v1.CommandService.Replay:input_type -> request.ReplayRequest
+	8, // 8: v1.CommandService.AutoMigrate:output_type -> google.protobuf.Empty
+	9, // 9: v1.CommandService.Transaction:output_type -> response.CommandStatementResponse
+	9, // 10: v1.CommandService.Insert:output_type -> response.CommandStatementResponse
+	9, // 11: v1.CommandService.InsertBatch:output_type -> response.CommandStatementResponse
+	9, // 12: v1.CommandService.Delete:output_type -> response.CommandStatementResponse
+	9, // 13: v1.CommandService.DeleteBatch:output_type -> response.CommandStatementResponse
+	9, // 14: v1.CommandService.Update:output_type -> response.CommandStatementResponse
+	9, // 15: v1.CommandService.Replay:output_type -> response.CommandStatementResponse
+	8, // [8:16] is the sub-list for method output_type
+	0, // [0:8] 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

+ 72 - 0
pb/v1/command_grpc.pb.go

@@ -28,7 +28,9 @@ type CommandServiceClient interface {
 	AutoMigrate(ctx context.Context, in *request.AutoMigrateRequest, opts ...grpc.CallOption) (*empty.Empty, error)
 	Transaction(ctx context.Context, opts ...grpc.CallOption) (CommandService_TransactionClient, error)
 	Insert(ctx context.Context, in *request.InsertRequest, opts ...grpc.CallOption) (*response.CommandStatementResponse, error)
+	InsertBatch(ctx context.Context, in *request.InsertBatchRequest, opts ...grpc.CallOption) (*response.CommandStatementResponse, error)
 	Delete(ctx context.Context, in *request.DeleteRequest, opts ...grpc.CallOption) (*response.CommandStatementResponse, error)
+	DeleteBatch(ctx context.Context, in *request.DeleteBatchRequest, opts ...grpc.CallOption) (*response.CommandStatementResponse, error)
 	Update(ctx context.Context, in *request.UpdateRequest, opts ...grpc.CallOption) (*response.CommandStatementResponse, error)
 	Replay(ctx context.Context, in *request.ReplayRequest, opts ...grpc.CallOption) (*response.CommandStatementResponse, error)
 }
@@ -90,6 +92,15 @@ func (c *commandServiceClient) Insert(ctx context.Context, in *request.InsertReq
 	return out, nil
 }
 
+func (c *commandServiceClient) InsertBatch(ctx context.Context, in *request.InsertBatchRequest, opts ...grpc.CallOption) (*response.CommandStatementResponse, error) {
+	out := new(response.CommandStatementResponse)
+	err := c.cc.Invoke(ctx, "/v1.CommandService/InsertBatch", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
 func (c *commandServiceClient) Delete(ctx context.Context, in *request.DeleteRequest, opts ...grpc.CallOption) (*response.CommandStatementResponse, error) {
 	out := new(response.CommandStatementResponse)
 	err := c.cc.Invoke(ctx, "/v1.CommandService/Delete", in, out, opts...)
@@ -99,6 +110,15 @@ func (c *commandServiceClient) Delete(ctx context.Context, in *request.DeleteReq
 	return out, nil
 }
 
+func (c *commandServiceClient) DeleteBatch(ctx context.Context, in *request.DeleteBatchRequest, opts ...grpc.CallOption) (*response.CommandStatementResponse, error) {
+	out := new(response.CommandStatementResponse)
+	err := c.cc.Invoke(ctx, "/v1.CommandService/DeleteBatch", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
 func (c *commandServiceClient) Update(ctx context.Context, in *request.UpdateRequest, opts ...grpc.CallOption) (*response.CommandStatementResponse, error) {
 	out := new(response.CommandStatementResponse)
 	err := c.cc.Invoke(ctx, "/v1.CommandService/Update", in, out, opts...)
@@ -124,7 +144,9 @@ type CommandServiceServer interface {
 	AutoMigrate(context.Context, *request.AutoMigrateRequest) (*empty.Empty, error)
 	Transaction(CommandService_TransactionServer) error
 	Insert(context.Context, *request.InsertRequest) (*response.CommandStatementResponse, error)
+	InsertBatch(context.Context, *request.InsertBatchRequest) (*response.CommandStatementResponse, error)
 	Delete(context.Context, *request.DeleteRequest) (*response.CommandStatementResponse, error)
+	DeleteBatch(context.Context, *request.DeleteBatchRequest) (*response.CommandStatementResponse, error)
 	Update(context.Context, *request.UpdateRequest) (*response.CommandStatementResponse, error)
 	Replay(context.Context, *request.ReplayRequest) (*response.CommandStatementResponse, error)
 	mustEmbedUnimplementedCommandServiceServer()
@@ -143,9 +165,15 @@ func (UnimplementedCommandServiceServer) Transaction(CommandService_TransactionS
 func (UnimplementedCommandServiceServer) Insert(context.Context, *request.InsertRequest) (*response.CommandStatementResponse, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method Insert not implemented")
 }
+func (UnimplementedCommandServiceServer) InsertBatch(context.Context, *request.InsertBatchRequest) (*response.CommandStatementResponse, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method InsertBatch not implemented")
+}
 func (UnimplementedCommandServiceServer) Delete(context.Context, *request.DeleteRequest) (*response.CommandStatementResponse, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented")
 }
+func (UnimplementedCommandServiceServer) DeleteBatch(context.Context, *request.DeleteBatchRequest) (*response.CommandStatementResponse, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method DeleteBatch not implemented")
+}
 func (UnimplementedCommandServiceServer) Update(context.Context, *request.UpdateRequest) (*response.CommandStatementResponse, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method Update not implemented")
 }
@@ -227,6 +255,24 @@ func _CommandService_Insert_Handler(srv interface{}, ctx context.Context, dec fu
 	return interceptor(ctx, in, info, handler)
 }
 
+func _CommandService_InsertBatch_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(request.InsertBatchRequest)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(CommandServiceServer).InsertBatch(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/v1.CommandService/InsertBatch",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(CommandServiceServer).InsertBatch(ctx, req.(*request.InsertBatchRequest))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
 func _CommandService_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
 	in := new(request.DeleteRequest)
 	if err := dec(in); err != nil {
@@ -245,6 +291,24 @@ func _CommandService_Delete_Handler(srv interface{}, ctx context.Context, dec fu
 	return interceptor(ctx, in, info, handler)
 }
 
+func _CommandService_DeleteBatch_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(request.DeleteBatchRequest)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(CommandServiceServer).DeleteBatch(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/v1.CommandService/DeleteBatch",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(CommandServiceServer).DeleteBatch(ctx, req.(*request.DeleteBatchRequest))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
 func _CommandService_Update_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
 	in := new(request.UpdateRequest)
 	if err := dec(in); err != nil {
@@ -296,10 +360,18 @@ var CommandService_ServiceDesc = grpc.ServiceDesc{
 			MethodName: "Insert",
 			Handler:    _CommandService_Insert_Handler,
 		},
+		{
+			MethodName: "InsertBatch",
+			Handler:    _CommandService_InsertBatch_Handler,
+		},
 		{
 			MethodName: "Delete",
 			Handler:    _CommandService_Delete_Handler,
 		},
+		{
+			MethodName: "DeleteBatch",
+			Handler:    _CommandService_DeleteBatch_Handler,
+		},
 		{
 			MethodName: "Update",
 			Handler:    _CommandService_Update_Handler,

Plik diff jest za duży
+ 582 - 142
pb/v1/request/command.pb.go


+ 92 - 6
pb/v1/request/command.validator.pb.go

@@ -26,8 +26,8 @@ func (this *AutoMigrateRequest) Validate() error {
 	if this.Version == "" {
 		return github_com_mwitkow_go_proto_validators.FieldError("Version", fmt.Errorf(`value '%v' must not be an empty string`, this.Version))
 	}
-	if !(len(this.Model) > 0) {
-		return github_com_mwitkow_go_proto_validators.FieldError("Model", fmt.Errorf(`value '%v' must have a length greater than '0'`, this.Model))
+	if !(len(this.TableModelDescribe) > 0) {
+		return github_com_mwitkow_go_proto_validators.FieldError("TableModelDescribe", fmt.Errorf(`value '%v' must have a length greater than '0'`, this.TableModelDescribe))
 	}
 	return nil
 }
@@ -46,6 +46,13 @@ func (this *TransactionOperation) Validate() error {
 			}
 		}
 	}
+	if oneOfNester, ok := this.GetRequest().(*TransactionOperation_InsertBatchRequest); ok {
+		if oneOfNester.InsertBatchRequest != nil {
+			if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(oneOfNester.InsertBatchRequest); err != nil {
+				return github_com_mwitkow_go_proto_validators.FieldError("InsertBatchRequest", err)
+			}
+		}
+	}
 	if oneOfNester, ok := this.GetRequest().(*TransactionOperation_DeleteRequest); ok {
 		if oneOfNester.DeleteRequest != nil {
 			if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(oneOfNester.DeleteRequest); err != nil {
@@ -53,6 +60,13 @@ func (this *TransactionOperation) Validate() error {
 			}
 		}
 	}
+	if oneOfNester, ok := this.GetRequest().(*TransactionOperation_DeleteBatchRequest); ok {
+		if oneOfNester.DeleteBatchRequest != nil {
+			if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(oneOfNester.DeleteBatchRequest); err != nil {
+				return github_com_mwitkow_go_proto_validators.FieldError("DeleteBatchRequest", err)
+			}
+		}
+	}
 	if oneOfNester, ok := this.GetRequest().(*TransactionOperation_UpdateRequest); ok {
 		if oneOfNester.UpdateRequest != nil {
 			if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(oneOfNester.UpdateRequest); err != nil {
@@ -82,8 +96,39 @@ func (this *InsertRequest) Validate() error {
 	if !(len(this.Keys) > 0) {
 		return github_com_mwitkow_go_proto_validators.FieldError("Keys", fmt.Errorf(`value '%v' must have a length greater than '0'`, this.Keys))
 	}
-	if !(len(this.Models) > 0) {
-		return github_com_mwitkow_go_proto_validators.FieldError("Models", fmt.Errorf(`value '%v' must have a length greater than '0'`, this.Models))
+	if !(len(this.TableRow) > 0) {
+		return github_com_mwitkow_go_proto_validators.FieldError("TableRow", fmt.Errorf(`value '%v' must have a length greater than '0'`, this.TableRow))
+	}
+	return nil
+}
+func (this *InsertBatchRequest) Validate() error {
+	if this.DatabaseID == "" {
+		return github_com_mwitkow_go_proto_validators.FieldError("DatabaseID", fmt.Errorf(`value '%v' must not be an empty string`, this.DatabaseID))
+	}
+	if len(this.Items) < 1 {
+		return github_com_mwitkow_go_proto_validators.FieldError("Items", fmt.Errorf(`value '%v' must contain at least 1 elements`, this.Items))
+	}
+	for _, item := range this.Items {
+		if item != nil {
+			if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
+				return github_com_mwitkow_go_proto_validators.FieldError("Items", err)
+			}
+		}
+	}
+	return nil
+}
+func (this *InsertItem) Validate() error {
+	if this.TablePrefixWithSchema == "" {
+		return github_com_mwitkow_go_proto_validators.FieldError("TablePrefixWithSchema", fmt.Errorf(`value '%v' must not be an empty string`, this.TablePrefixWithSchema))
+	}
+	if this.Version == "" {
+		return github_com_mwitkow_go_proto_validators.FieldError("Version", fmt.Errorf(`value '%v' must not be an empty string`, this.Version))
+	}
+	if !(len(this.Keys) > 0) {
+		return github_com_mwitkow_go_proto_validators.FieldError("Keys", fmt.Errorf(`value '%v' must have a length greater than '0'`, this.Keys))
+	}
+	if !(len(this.TableRow) > 0) {
+		return github_com_mwitkow_go_proto_validators.FieldError("TableRow", fmt.Errorf(`value '%v' must have a length greater than '0'`, this.TableRow))
 	}
 	return nil
 }
@@ -102,6 +147,47 @@ func (this *DeleteRequest) Validate() error {
 	}
 	return nil
 }
+func (this *DeleteBatchRequest) Validate() error {
+	if this.DatabaseID == "" {
+		return github_com_mwitkow_go_proto_validators.FieldError("DatabaseID", fmt.Errorf(`value '%v' must not be an empty string`, this.DatabaseID))
+	}
+	if len(this.Items) < 1 {
+		return github_com_mwitkow_go_proto_validators.FieldError("Items", fmt.Errorf(`value '%v' must contain at least 1 elements`, this.Items))
+	}
+	for _, item := range this.Items {
+		if item != nil {
+			if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
+				return github_com_mwitkow_go_proto_validators.FieldError("Items", err)
+			}
+		}
+	}
+	return nil
+}
+func (this *DeleteTableItem) Validate() error {
+	if this.TablePrefixWithSchema == "" {
+		return github_com_mwitkow_go_proto_validators.FieldError("TablePrefixWithSchema", fmt.Errorf(`value '%v' must not be an empty string`, this.TablePrefixWithSchema))
+	}
+	if this.Version == "" {
+		return github_com_mwitkow_go_proto_validators.FieldError("Version", fmt.Errorf(`value '%v' must not be an empty string`, this.Version))
+	}
+	if len(this.Items) < 1 {
+		return github_com_mwitkow_go_proto_validators.FieldError("Items", fmt.Errorf(`value '%v' must contain at least 1 elements`, this.Items))
+	}
+	for _, item := range this.Items {
+		if item != nil {
+			if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
+				return github_com_mwitkow_go_proto_validators.FieldError("Items", err)
+			}
+		}
+	}
+	return nil
+}
+func (this *DeleteItem) Validate() error {
+	if !(len(this.Keys) > 0) {
+		return github_com_mwitkow_go_proto_validators.FieldError("Keys", fmt.Errorf(`value '%v' must have a length greater than '0'`, this.Keys))
+	}
+	return nil
+}
 func (this *UpdateRequest) Validate() error {
 	if this.DatabaseID == "" {
 		return github_com_mwitkow_go_proto_validators.FieldError("DatabaseID", fmt.Errorf(`value '%v' must not be an empty string`, this.DatabaseID))
@@ -115,8 +201,8 @@ func (this *UpdateRequest) Validate() error {
 	if !(len(this.Keys) > 0) {
 		return github_com_mwitkow_go_proto_validators.FieldError("Keys", fmt.Errorf(`value '%v' must have a length greater than '0'`, this.Keys))
 	}
-	if !(len(this.NewModel) > 0) {
-		return github_com_mwitkow_go_proto_validators.FieldError("NewModel", fmt.Errorf(`value '%v' must have a length greater than '0'`, this.NewModel))
+	if !(len(this.NewTableRow) > 0) {
+		return github_com_mwitkow_go_proto_validators.FieldError("NewTableRow", fmt.Errorf(`value '%v' must have a length greater than '0'`, this.NewTableRow))
 	}
 	return nil
 }

+ 3 - 0
ports/client.go

@@ -2,4 +2,7 @@ package ports
 
 type Client interface {
 	AutoMigrate(request *AutoMigrateRequest) error
+	Insert(request *InsertRequest) (string, error)
+	Delete(request *DeleteRequest) (string, error)
+	Update(request *UpdateRequest) (string, error)
 }

+ 93 - 0
ports/client_cmd_request.go

@@ -0,0 +1,93 @@
+package ports
+
+type AutoMigrateRequest struct {
+	DatabaseID            string
+	TablePrefixWithSchema string
+	Version               string
+	TableModelDescribe    TableModelDescribe
+}
+
+// TODO 事务
+
+type InsertRequest struct {
+	DatabaseID            string
+	TablePrefixWithSchema string
+	Version               string
+	Keys                  []Key
+	TableRow              map[string]any
+	UserID                string
+}
+
+type InsertBatchRequest struct {
+	DatabaseID string
+	Items      []*InsertItem
+}
+
+type InsertItem struct {
+	TablePrefixWithSchema string
+	Version               string
+	Keys                  []Key
+	TableRow              map[string]any
+	UserID                string
+}
+
+type DeleteRequest struct {
+	DatabaseID            string
+	TablePrefixWithSchema string
+	Version               string
+	Keys                  []Key
+	UserID                string
+}
+
+type DeleteBatchRequest struct {
+	DatabaseID string
+	Items      []*DeleteTableItem
+	UserID     string
+}
+
+type DeleteTableItem struct {
+	TablePrefixWithSchema string
+	Version               string
+	Items                 []*DeleteItem
+}
+
+type DeleteItem struct {
+	Keys []Key
+}
+
+type UpdateRequest struct {
+	DatabaseID            string
+	TablePrefixWithSchema string
+	Version               string
+	Keys                  []Key
+	NewTableRow           []map[string]any
+	UserID                string
+}
+
+type ReplayRequest struct {
+	DatabaseID            string
+	TablePrefixWithSchema string
+	Version               string
+	Keys                  []Key
+	UserID                string
+}
+
+type TableModelDescribe struct {
+	Fields []TableModelField `json:"fields"`
+}
+
+type TableModelField struct {
+	Name string `json:"name"`
+	Tag  string `json:"tag"`
+}
+
+type Key struct {
+	Column string `json:"column"`
+	Value  string `json:"value"`
+}
+
+type ColumnCompare struct {
+	Column  string `json:"column"`
+	Value   any    `json:"value"`
+	Compare string `json:"compare"`
+}

+ 0 - 17
ports/client_request.go

@@ -1,17 +0,0 @@
-package ports
-
-type AutoMigrateRequest struct {
-	DatabaseID            string
-	TablePrefixWithSchema string
-	Version               string
-	Model                 AutoMigrateModel
-}
-
-type AutoMigrateModel struct {
-	Fields []AutoMigrateModelField `json:"fields"`
-}
-
-type AutoMigrateModelField struct {
-	Name string `json:"name"`
-	Tag  string `json:"tag"`
-}

+ 53 - 5
test/v1/sdk.go

@@ -1,18 +1,21 @@
 package v1
 
 import (
+	"fmt"
 	"git.sxidc.com/service-supports/dps-sdk"
 	"git.sxidc.com/service-supports/dps-sdk/ports"
 	"testing"
 )
 
-func initClient(t *testing.T, address string) ports.Client {
+var clientInstance ports.Client
+
+func initClient(t *testing.T, address string) {
 	client, err := dps.NewClient(address, "v1")
 	if err != nil {
 		t.Fatal(err)
 	}
 
-	return client
+	clientInstance = client
 }
 
 func destroyClient(t *testing.T) {
@@ -20,11 +23,56 @@ func destroyClient(t *testing.T) {
 	if err != nil {
 		t.Fatal(err)
 	}
+
+	clientInstance = nil
+}
+
+type ToolKit struct {
+	t *testing.T
 }
 
-func autoMigrate(t *testing.T, client ports.Client, req *ports.AutoMigrateRequest) {
-	err := client.AutoMigrate(req)
+func newToolKit(t *testing.T) *ToolKit {
+	return &ToolKit{t: t}
+}
+
+func (toolKit *ToolKit) autoMigrate(req *ports.AutoMigrateRequest) *ToolKit {
+	err := clientInstance.AutoMigrate(req)
 	if err != nil {
-		t.Fatal(err)
+		toolKit.t.Fatal(err)
+	}
+
+	return toolKit
+}
+
+func (toolKit *ToolKit) insert(req *ports.InsertRequest) *ToolKit {
+	statement, err := clientInstance.Insert(req)
+	if err != nil {
+		toolKit.t.Fatal(err)
+	}
+
+	fmt.Println(statement)
+
+	return toolKit
+}
+
+func (toolKit *ToolKit) delete(req *ports.DeleteRequest) *ToolKit {
+	statement, err := clientInstance.Delete(req)
+	if err != nil {
+		toolKit.t.Fatal(err)
 	}
+
+	fmt.Println(statement)
+
+	return toolKit
+}
+
+func (toolKit *ToolKit) update(req *ports.UpdateRequest) *ToolKit {
+	statement, err := clientInstance.Update(req)
+	if err != nil {
+		toolKit.t.Fatal(err)
+	}
+
+	fmt.Println(statement)
+
+	return toolKit
 }

+ 46 - 9
test/v1/v1_test.go

@@ -2,24 +2,61 @@ package v1
 
 import (
 	"git.sxidc.com/service-supports/dps-sdk/ports"
+	"math/rand"
 	"testing"
+	"time"
 )
 
+var tableModelDescribe = ports.TableModelDescribe{
+	Fields: []ports.TableModelField{
+		{"ID", "gorm:\"primary_key;type:varchar(32);comment:id;\""},
+		{"Name", "gorm:\"not null;type:varchar(128);comment:数据库名称;\""},
+		{"Time", "gorm:\"not null;type:timestamp with time zone;comment:数据库时间;\""},
+		{"TableNum", "gorm:\"not null;type:integer;comment:数据库表数量;\""},
+	},
+}
+
 func TestAutoMigrate(t *testing.T) {
-	client := initClient(t, "localhost:30170")
+	initClient(t, "localhost:30170")
 	defer destroyClient(t)
 
-	autoMigrate(t, client, &ports.AutoMigrateRequest{
+	newToolKit(t).autoMigrate(&ports.AutoMigrateRequest{
 		DatabaseID:            "2b78141779ee432295ca371b91c5cac7",
 		TablePrefixWithSchema: "test." + simpleUUID()[0:8],
 		Version:               "v1",
-		Model: ports.AutoMigrateModel{
-			Fields: []ports.AutoMigrateModelField{
-				{Name: "ID", Tag: "gorm:\"primary_key;type:varchar(32);comment:id;\""},
-				{Name: "Name", Tag: "gorm:\"not null;type:varchar(128);comment:数据库名称;\""},
-				{Name: "Time", Tag: "gorm:\"not null;type:timestamp with time zone;comment:数据库时间;\""},
-				{Name: "TableNum", Tag: "gorm:\"not null;type:integer;comment:数据库表数量;\""},
-			},
+		TableModelDescribe:    tableModelDescribe,
+	})
+}
+
+func TestInsert(t *testing.T) {
+	initClient(t, "localhost:30170")
+	defer destroyClient(t)
+
+	tablePrefix := "test." + simpleUUID()[0:8]
+
+	id := simpleUUID()
+	name := simpleUUID()
+	now := time.Now().Local()
+	tableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
+
+	newToolKit(t).autoMigrate(&ports.AutoMigrateRequest{
+		DatabaseID:            "2b78141779ee432295ca371b91c5cac7",
+		TablePrefixWithSchema: tablePrefix,
+		Version:               "v1",
+		TableModelDescribe:    tableModelDescribe,
+	}).insert(&ports.InsertRequest{
+		DatabaseID:            "2b78141779ee432295ca371b91c5cac7",
+		TablePrefixWithSchema: tablePrefix,
+		Version:               "v1",
+		Keys: []ports.Key{
+			{"id", id},
+		},
+		TableRow: map[string]any{
+			"id":        id,
+			"name":      name,
+			"time":      now,
+			"table_num": tableNum,
 		},
+		UserID: "test",
 	})
 }

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików