Ver código fonte

添加delete where

yjp 1 ano atrás
pai
commit
93893d44a0

+ 1 - 0
client/client.go

@@ -41,6 +41,7 @@ type Client interface {
 	Insert(request *InsertRequest) (string, error)
 	InsertBatch(request *InsertBatchRequest) (string, error)
 	Delete(request *DeleteRequest) (string, error)
+	DeleteWhere(request *DeleteWhereRequest) (string, error)
 	DeleteBatch(request *DeleteBatchRequest) (string, error)
 	Update(request *UpdateRequest) (string, error)
 	Replay(request *ReplayRequest) (string, error)

+ 8 - 0
client/client_cmd_request.go

@@ -37,6 +37,14 @@ type DeleteRequest struct {
 	UserID                string
 }
 
+type DeleteWhereRequest struct {
+	TablePrefixWithSchema string
+	Version               string
+	KeyColumns            []string
+	Where                 *Clause
+	UserID                string
+}
+
 type DeleteBatchRequest struct {
 	Items  []DeleteTableRowItem
 	UserID string

+ 1 - 0
client/transaction.go

@@ -6,6 +6,7 @@ type Transaction interface {
 	InsertTx(request *InsertRequest) (string, error)
 	InsertBatchTx(request *InsertBatchRequest) (string, error)
 	DeleteTx(request *DeleteRequest) (string, error)
+	DeleteWhereTx(request *DeleteWhereRequest) (string, error)
 	DeleteBatchTx(request *DeleteBatchRequest) (string, error)
 	UpdateTx(request *UpdateRequest) (string, error)
 }

+ 26 - 0
dpsv1/client.go

@@ -3,6 +3,7 @@ package dpsv1
 import (
 	"context"
 	"encoding/json"
+	"errors"
 	"git.sxidc.com/service-supports/dps-sdk/client"
 	"git.sxidc.com/service-supports/dps-sdk/pb/v1"
 	"git.sxidc.com/service-supports/dps-sdk/pb/v1/request"
@@ -207,6 +208,31 @@ func (c *Client) Delete(req *client.DeleteRequest) (string, error) {
 	return reply.Statement, nil
 }
 
+func (c *Client) DeleteWhere(req *client.DeleteWhereRequest) (string, error) {
+	if req.Where == nil {
+		return "", errors.New("没有传递Where条件")
+	}
+
+	whereJsonBytes, err := req.Where.ToJson()
+	if err != nil {
+		return "", err
+	}
+
+	reply, err := c.commandServiceClient.DeleteWhere(context.Background(), &request.DeleteWhereRequest{
+		DatabaseID:            c.databaseID,
+		TablePrefixWithSchema: req.TablePrefixWithSchema,
+		Version:               req.Version,
+		KeyColumns:            req.KeyColumns,
+		Where:                 whereJsonBytes,
+		UserID:                req.UserID,
+	})
+	if err != nil {
+		return "", err
+	}
+
+	return reply.Statement, nil
+}
+
 func (c *Client) DeleteBatch(req *client.DeleteBatchRequest) (string, error) {
 	tableRowItems := make([]*request.DeleteTableRowItem, 0)
 

+ 51 - 0
dpsv1/transaction.go

@@ -1,6 +1,7 @@
 package dpsv1
 
 import (
+	"errors"
 	"git.sxidc.com/service-supports/dps-sdk/client"
 	"git.sxidc.com/service-supports/dps-sdk/pb/v1"
 	"git.sxidc.com/service-supports/dps-sdk/pb/v1/request"
@@ -164,6 +165,56 @@ func (tx *Transaction) DeleteTx(req *client.DeleteRequest) (string, error) {
 	return txResponse.Statement, nil
 }
 
+func (tx *Transaction) DeleteWhereTx(req *client.DeleteWhereRequest) (string, error) {
+	tx.client.transactionMutex.Lock()
+	defer tx.client.transactionMutex.Unlock()
+
+	if tx.client.conn == nil {
+		return "", nil
+	}
+
+	if req.Where == nil {
+		return "", errors.New("没有传递Where条件")
+	}
+
+	var err error
+
+	defer func() {
+		if err != nil {
+			innerErr := tx.stream.CloseSend()
+			if innerErr != nil {
+				panic(innerErr)
+			}
+		}
+	}()
+
+	whereJsonBytes, err := req.Where.ToJson()
+	if err != nil {
+		return "", err
+	}
+
+	err = tx.stream.Send(&request.TransactionOperation{
+		Request: &request.TransactionOperation_DeleteWhereTxRequest{
+			DeleteWhereTxRequest: &request.DeleteWhereTxRequest{
+				TablePrefixWithSchema: req.TablePrefixWithSchema,
+				Version:               req.Version,
+				KeyColumns:            req.KeyColumns,
+				Where:                 whereJsonBytes,
+				UserID:                req.UserID,
+			},
+		}})
+	if err != nil {
+		return "", err
+	}
+
+	txResponse, err := tx.stream.Recv()
+	if err != nil {
+		return "", err
+	}
+
+	return txResponse.Statement, nil
+}
+
 func (tx *Transaction) DeleteBatchTx(req *client.DeleteBatchRequest) (string, error) {
 	tx.client.transactionMutex.Lock()
 	defer tx.client.transactionMutex.Unlock()

+ 18 - 0
instance_command.go

@@ -59,6 +59,24 @@ func Delete(req *client.DeleteRequest, tx client.Transaction) error {
 	return nil
 }
 
+func DeleteWhere(req *client.DeleteWhereRequest, tx client.Transaction) error {
+	var statement string
+	var err error
+
+	if tx == nil {
+		statement, err = dpsClient.DeleteWhere(req)
+	} else {
+		statement, err = tx.DeleteWhereTx(req)
+	}
+	if err != nil {
+		return err
+	}
+
+	fslog.Info(statement)
+
+	return nil
+}
+
 func DeleteBatch(req *client.DeleteBatchRequest, tx client.Transaction) error {
 	var statement string
 	var err error

+ 50 - 41
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, 0xf2, 0x04, 0x0a, 0x0e, 0x43, 0x6f, 0x6d,
+	0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0xc4, 0x05, 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,
@@ -57,22 +57,28 @@ var file_v1_command_proto_rawDesc = []byte{
 	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,
+	0x65, 0x6c, 0x65, 0x74, 0x65, 0x57, 0x68, 0x65, 0x72, 0x65, 0x12, 0x1b, 0x2e, 0x72, 0x65, 0x71,
+	0x75, 0x65, 0x73, 0x74, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x57, 0x68, 0x65, 0x72, 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,
+	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{}{
@@ -81,34 +87,37 @@ var file_v1_command_proto_goTypes = []interface{}{
 	(*request.InsertRequest)(nil),             // 2: request.InsertRequest
 	(*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
+	(*request.DeleteWhereRequest)(nil),        // 5: request.DeleteWhereRequest
+	(*request.DeleteBatchRequest)(nil),        // 6: request.DeleteBatchRequest
+	(*request.UpdateRequest)(nil),             // 7: request.UpdateRequest
+	(*request.ReplayRequest)(nil),             // 8: request.ReplayRequest
+	(*empty.Empty)(nil),                       // 9: google.protobuf.Empty
+	(*response.CommandStatementResponse)(nil), // 10: 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.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
+	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.InsertBatch:input_type -> request.InsertBatchRequest
+	4,  // 4: v1.CommandService.Delete:input_type -> request.DeleteRequest
+	5,  // 5: v1.CommandService.DeleteWhere:input_type -> request.DeleteWhereRequest
+	6,  // 6: v1.CommandService.DeleteBatch:input_type -> request.DeleteBatchRequest
+	7,  // 7: v1.CommandService.Update:input_type -> request.UpdateRequest
+	8,  // 8: v1.CommandService.Replay:input_type -> request.ReplayRequest
+	9,  // 9: v1.CommandService.AutoMigrate:output_type -> google.protobuf.Empty
+	10, // 10: v1.CommandService.Transaction:output_type -> response.CommandStatementResponse
+	10, // 11: v1.CommandService.Insert:output_type -> response.CommandStatementResponse
+	10, // 12: v1.CommandService.InsertBatch:output_type -> response.CommandStatementResponse
+	10, // 13: v1.CommandService.Delete:output_type -> response.CommandStatementResponse
+	10, // 14: v1.CommandService.DeleteWhere:output_type -> response.CommandStatementResponse
+	10, // 15: v1.CommandService.DeleteBatch:output_type -> response.CommandStatementResponse
+	10, // 16: v1.CommandService.Update:output_type -> response.CommandStatementResponse
+	10, // 17: v1.CommandService.Replay:output_type -> response.CommandStatementResponse
+	9,  // [9:18] is the sub-list for method output_type
+	0,  // [0:9] 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
 }
 
 func init() { file_v1_command_proto_init() }

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

@@ -30,6 +30,7 @@ type CommandServiceClient interface {
 	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)
+	DeleteWhere(ctx context.Context, in *request.DeleteWhereRequest, 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)
@@ -110,6 +111,15 @@ func (c *commandServiceClient) Delete(ctx context.Context, in *request.DeleteReq
 	return out, nil
 }
 
+func (c *commandServiceClient) DeleteWhere(ctx context.Context, in *request.DeleteWhereRequest, opts ...grpc.CallOption) (*response.CommandStatementResponse, error) {
+	out := new(response.CommandStatementResponse)
+	err := c.cc.Invoke(ctx, "/v1.CommandService/DeleteWhere", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	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...)
@@ -146,6 +156,7 @@ type CommandServiceServer interface {
 	Insert(context.Context, *request.InsertRequest) (*response.CommandStatementResponse, error)
 	InsertBatch(context.Context, *request.InsertBatchRequest) (*response.CommandStatementResponse, error)
 	Delete(context.Context, *request.DeleteRequest) (*response.CommandStatementResponse, error)
+	DeleteWhere(context.Context, *request.DeleteWhereRequest) (*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)
@@ -171,6 +182,9 @@ func (UnimplementedCommandServiceServer) InsertBatch(context.Context, *request.I
 func (UnimplementedCommandServiceServer) Delete(context.Context, *request.DeleteRequest) (*response.CommandStatementResponse, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented")
 }
+func (UnimplementedCommandServiceServer) DeleteWhere(context.Context, *request.DeleteWhereRequest) (*response.CommandStatementResponse, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method DeleteWhere not implemented")
+}
 func (UnimplementedCommandServiceServer) DeleteBatch(context.Context, *request.DeleteBatchRequest) (*response.CommandStatementResponse, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method DeleteBatch not implemented")
 }
@@ -291,6 +305,24 @@ func _CommandService_Delete_Handler(srv interface{}, ctx context.Context, dec fu
 	return interceptor(ctx, in, info, handler)
 }
 
+func _CommandService_DeleteWhere_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(request.DeleteWhereRequest)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(CommandServiceServer).DeleteWhere(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/v1.CommandService/DeleteWhere",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(CommandServiceServer).DeleteWhere(ctx, req.(*request.DeleteWhereRequest))
+	}
+	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 {
@@ -368,6 +400,10 @@ var CommandService_ServiceDesc = grpc.ServiceDesc{
 			MethodName: "Delete",
 			Handler:    _CommandService_Delete_Handler,
 		},
+		{
+			MethodName: "DeleteWhere",
+			Handler:    _CommandService_DeleteWhere_Handler,
+		},
 		{
 			MethodName: "DeleteBatch",
 			Handler:    _CommandService_DeleteBatch_Handler,

Diferenças do arquivo suprimidas por serem muito extensas
+ 470 - 256
pb/v1/request/command.pb.go


+ 38 - 0
pb/v1/request/command.validator.pb.go

@@ -92,6 +92,20 @@ func (this *DeleteTxRequest) Validate() error {
 	// Validation of proto3 map<> fields is unsupported.
 	return nil
 }
+func (this *DeleteWhereTxRequest) 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))
+	}
+	for _, item := range this.KeyColumns {
+		if !(len(item) > 0) {
+			return github_com_mwitkow_go_proto_validators.FieldError("KeyColumns", fmt.Errorf(`value '%v' must have a length greater than '0'`, item))
+		}
+	}
+	return nil
+}
 func (this *DeleteBatchTxRequest) Validate() error {
 	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))
@@ -152,6 +166,13 @@ func (this *TransactionOperation) Validate() error {
 			}
 		}
 	}
+	if oneOfNester, ok := this.GetRequest().(*TransactionOperation_DeleteWhereTxRequest); ok {
+		if oneOfNester.DeleteWhereTxRequest != nil {
+			if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(oneOfNester.DeleteWhereTxRequest); err != nil {
+				return github_com_mwitkow_go_proto_validators.FieldError("DeleteWhereTxRequest", err)
+			}
+		}
+	}
 	if oneOfNester, ok := this.GetRequest().(*TransactionOperation_DeleteBatchTxRequest); ok {
 		if oneOfNester.DeleteBatchTxRequest != nil {
 			if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(oneOfNester.DeleteBatchTxRequest); err != nil {
@@ -247,6 +268,23 @@ func (this *DeleteRequest) Validate() error {
 	// Validation of proto3 map<> fields is unsupported.
 	return nil
 }
+func (this *DeleteWhereRequest) 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 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))
+	}
+	for _, item := range this.KeyColumns {
+		if !(len(item) > 0) {
+			return github_com_mwitkow_go_proto_validators.FieldError("KeyColumns", fmt.Errorf(`value '%v' must have a length greater than '0'`, item))
+		}
+	}
+	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))

+ 80 - 0
test/instance/instance_test.go

@@ -159,6 +159,39 @@ func TestTransaction(t *testing.T) {
 			Version:               "v1",
 			Where:                 client.NewClause().Equal("id", id),
 		}, &count).
+		assertEqual(int64(0), count, "数量不一致").
+		insert(&client.InsertRequest{
+			TablePrefixWithSchema: tablePrefix,
+			Version:               "v1",
+			KeyColumns:            []string{"id"},
+			TableRow: client.NewTableRow().
+				AddColumnValueString("id", id).
+				AddColumnValueString("name", name).
+				AddColumnValueTime("time", now).
+				AddColumnValueInt("table_num", tableNum),
+			UserID: "test",
+		}).
+		transaction(func(tx client.Transaction) error {
+			statement, err := tx.DeleteWhereTx(&client.DeleteWhereRequest{
+				TablePrefixWithSchema: tablePrefix,
+				Version:               "v1",
+				KeyColumns:            []string{"id"},
+				Where:                 client.NewClause().Equal("name", name),
+				UserID:                "test",
+			})
+			if err != nil {
+				return err
+			}
+
+			fmt.Println(statement)
+
+			return nil
+		}).
+		countWhere(&client.CountWhereRequest{
+			TablePrefixWithSchema: tablePrefix,
+			Version:               "v1",
+			Where:                 client.NewClause().Equal("id", id),
+		}, &count).
 		assertEqual(int64(0), count, "数量不一致")
 }
 
@@ -543,6 +576,53 @@ func TestDelete(t *testing.T) {
 		assertEqual(int64(0), count, "数量不一致")
 }
 
+func TestDeleteWhere(t *testing.T) {
+	initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
+	defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
+
+	tablePrefix := "test." + simpleUUID()[0:8]
+
+	id := simpleUUID()
+	name := simpleUUID()
+	now := time.Now().Local()
+	tableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
+
+	var count int64
+
+	newToolKit(t).
+		autoMigrate([]client.AutoMigrateItem{
+			{
+				TablePrefixWithSchema: tablePrefix,
+				Version:               "v1",
+				TableModelDescribe:    tableModelDescribe,
+			},
+		}).
+		insert(&client.InsertRequest{
+			TablePrefixWithSchema: tablePrefix,
+			Version:               "v1",
+			KeyColumns:            []string{"id"},
+			TableRow: client.NewTableRow().
+				AddColumnValueString("id", id).
+				AddColumnValueString("name", name).
+				AddColumnValueTime("time", now).
+				AddColumnValueInt("table_num", tableNum),
+			UserID: "test",
+		}).
+		deleteWhere(&client.DeleteWhereRequest{
+			TablePrefixWithSchema: tablePrefix,
+			Version:               "v1",
+			KeyColumns:            []string{"id"},
+			Where:                 client.NewClause().Equal("name", name),
+			UserID:                "test",
+		}).
+		countWhere(&client.CountWhereRequest{
+			TablePrefixWithSchema: tablePrefix,
+			Version:               "v1",
+			Where:                 client.NewClause().Equal("id", id),
+		}, &count).
+		assertEqual(int64(0), count, "数量不一致")
+}
+
 func TestDeleteBatch(t *testing.T) {
 	initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
 	defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")

+ 9 - 0
test/instance/sdk.go

@@ -74,6 +74,15 @@ func (toolKit *ToolKit) delete(req *client.DeleteRequest) *ToolKit {
 	return toolKit
 }
 
+func (toolKit *ToolKit) deleteWhere(req *client.DeleteWhereRequest) *ToolKit {
+	err := dps.DeleteWhere(req, nil)
+	if err != nil {
+		toolKit.t.Fatal(err)
+	}
+
+	return toolKit
+}
+
 func (toolKit *ToolKit) deleteBatch(req *client.DeleteBatchRequest) *ToolKit {
 	err := dps.DeleteBatch(req, nil)
 	if err != nil {

+ 11 - 0
test/v1/sdk.go

@@ -87,6 +87,17 @@ func (toolKit *ToolKit) delete(req *client.DeleteRequest) *ToolKit {
 	return toolKit
 }
 
+func (toolKit *ToolKit) deleteWhere(req *client.DeleteWhereRequest) *ToolKit {
+	statement, err := clientInstance.DeleteWhere(req)
+	if err != nil {
+		toolKit.t.Fatal(err)
+	}
+
+	fmt.Println(statement)
+
+	return toolKit
+}
+
 func (toolKit *ToolKit) deleteBatch(req *client.DeleteBatchRequest) *ToolKit {
 	statement, err := clientInstance.DeleteBatch(req)
 	if err != nil {

+ 82 - 0
test/v1/v1_test.go

@@ -163,6 +163,39 @@ func TestTransaction(t *testing.T) {
 			Version:               "v1",
 			Where:                 client.NewClause().Equal("id", id),
 		}, &count).
+		assertEqual(int64(0), count, "数量不一致").
+		insert(&client.InsertRequest{
+			TablePrefixWithSchema: tablePrefix,
+			Version:               "v1",
+			KeyColumns:            []string{"id"},
+			TableRow: client.NewTableRow().
+				AddColumnValueString("id", id).
+				AddColumnValueString("name", name).
+				AddColumnValueTime("time", now).
+				AddColumnValueInt("table_num", tableNum),
+			UserID: "test",
+		}).
+		transaction(func(tx client.Transaction) error {
+			statement, err := tx.DeleteWhereTx(&client.DeleteWhereRequest{
+				TablePrefixWithSchema: tablePrefix,
+				Version:               "v1",
+				KeyColumns:            []string{"id"},
+				Where:                 client.NewClause().Equal("name", name),
+				UserID:                "test",
+			})
+			if err != nil {
+				return err
+			}
+
+			fmt.Println(statement)
+
+			return nil
+		}).
+		countWhere(&client.CountWhereRequest{
+			TablePrefixWithSchema: tablePrefix,
+			Version:               "v1",
+			Where:                 client.NewClause().Equal("id", id),
+		}, &count).
 		assertEqual(int64(0), count, "数量不一致")
 }
 
@@ -541,6 +574,55 @@ func TestDelete(t *testing.T) {
 		assertEqual(int64(0), count, "数量不一致")
 }
 
+func TestDeleteWhere(t *testing.T) {
+	initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
+	defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
+
+	tablePrefix := "test." + simpleUUID()[0:8]
+
+	id := simpleUUID()
+	name := simpleUUID()
+	now := time.Now().Local()
+	tableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
+
+	var count int64
+
+	newToolKit(t).
+		autoMigrate(&client.AutoMigrateRequest{
+			Items: []client.AutoMigrateItem{
+				{
+					TablePrefixWithSchema: tablePrefix,
+					Version:               "v1",
+					TableModelDescribe:    tableModelDescribe,
+				},
+			},
+		}).
+		insert(&client.InsertRequest{
+			TablePrefixWithSchema: tablePrefix,
+			Version:               "v1",
+			KeyColumns:            []string{"id"},
+			TableRow: client.NewTableRow().
+				AddColumnValueString("id", id).
+				AddColumnValueString("name", name).
+				AddColumnValueTime("time", now).
+				AddColumnValueInt("table_num", tableNum),
+			UserID: "test",
+		}).
+		deleteWhere(&client.DeleteWhereRequest{
+			TablePrefixWithSchema: tablePrefix,
+			Version:               "v1",
+			KeyColumns:            []string{"id"},
+			Where:                 client.NewClause().Equal("name", name),
+			UserID:                "test",
+		}).
+		countWhere(&client.CountWhereRequest{
+			TablePrefixWithSchema: tablePrefix,
+			Version:               "v1",
+			Where:                 client.NewClause().Equal("id", id),
+		}, &count).
+		assertEqual(int64(0), count, "数量不一致")
+}
+
 func TestDeleteBatch(t *testing.T) {
 	initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
 	defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff