From cc7d1911d54dd5bc26610ee3539d465ecfc96a93 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Tue, 16 Nov 2021 13:34:56 +0000 Subject: [PATCH] db: added drop table endpoint (#271) * db: added drop table endpoint * F * Update db.proto Co-authored-by: Asim Aslam --- db/examples.json | 16 ++- db/handler/db.go | 15 +++ db/proto/db.pb.go | 260 +++++++++++++++++++++++++++++----------- db/proto/db.pb.micro.go | 17 +++ db/proto/db.proto | 13 +- 5 files changed, 241 insertions(+), 80 deletions(-) diff --git a/db/examples.json b/db/examples.json index 763705e..468a008 100644 --- a/db/examples.json +++ b/db/examples.json @@ -73,6 +73,16 @@ "response": {} } ], + "dropTable": [ + { + "title": "Drop table", + "run_check": false, + "request": { + "table": "users" + }, + "response": {} + } + ], "count": [ { "title": "Count entries in a table", @@ -89,8 +99,7 @@ { "title": "List tables", "run_check": false, - "request": { - }, + "request": {}, "response": { "tables": ["users", "events"] } @@ -104,8 +113,7 @@ "from": "events", "to": "events_backup" }, - "response": { - } + "response": {} } ] } diff --git a/db/handler/db.go b/db/handler/db.go index 2c84c86..cdf60ae 100644 --- a/db/handler/db.go +++ b/db/handler/db.go @@ -23,6 +23,7 @@ import ( const idKey = "id" const stmt = "create table if not exists %v(id text not null, data jsonb, primary key(id)); alter table %v add created_at timestamptz; alter table %v add updated_at timestamptz" const truncateStmt = `truncate table "%v"` +const dropTableStmt = `drop table "%v"` const renameTableStmt = `ALTER TABLE "%v" RENAME TO "%v"` var re = regexp.MustCompile("^[a-zA-Z0-9_]*$") @@ -330,6 +331,20 @@ func (e *Db) Truncate(ctx context.Context, req *db.TruncateRequest, rsp *db.Trun return db.Exec(fmt.Sprintf(truncateStmt, tableName)).Error } +func (e *Db) DropTable(ctx context.Context, req *db.DropTableRequest, rsp *db.DropTableResponse) error { + tableName, err := e.tableName(ctx, req.Table) + if err != nil { + return err + } + logger.Infof("Dropping table '%v'", tableName) + + db, err := e.GetDBConn(ctx) + if err != nil { + return err + } + return db.Exec(fmt.Sprintf(dropTableStmt, tableName)).Error +} + func (e *Db) Count(ctx context.Context, req *db.CountRequest, rsp *db.CountResponse) error { if req.Table == "" { req.Table = "default" diff --git a/db/proto/db.pb.go b/db/proto/db.pb.go index b8f4447..95d51c6 100644 --- a/db/proto/db.pb.go +++ b/db/proto/db.pb.go @@ -489,7 +489,6 @@ type TruncateRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // Optional table name. Defaults to 'default' Table string `protobuf:"bytes,1,opt,name=table,proto3" json:"table,omitempty"` } @@ -536,9 +535,6 @@ type TruncateResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - - // The table truncated - Table string `protobuf:"bytes,1,opt,name=table,proto3" json:"table,omitempty"` } func (x *TruncateResponse) Reset() { @@ -573,13 +569,6 @@ func (*TruncateResponse) Descriptor() ([]byte, []int) { return file_proto_db_proto_rawDescGZIP(), []int{9} } -func (x *TruncateResponse) GetTable() string { - if x != nil { - return x.Table - } - return "" -} - // Count records in a table type CountRequest struct { state protoimpl.MessageState @@ -677,13 +666,16 @@ func (x *CountResponse) GetCount() int32 { return 0 } +// Rename a table type RenameTableRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + // current table name From string `protobuf:"bytes,1,opt,name=from,proto3" json:"from,omitempty"` - To string `protobuf:"bytes,2,opt,name=to,proto3" json:"to,omitempty"` + // new table name + To string `protobuf:"bytes,2,opt,name=to,proto3" json:"to,omitempty"` } func (x *RenameTableRequest) Reset() { @@ -770,6 +762,7 @@ func (*RenameTableResponse) Descriptor() ([]byte, []int) { return file_proto_db_proto_rawDescGZIP(), []int{13} } +// List tables in the DB type ListTablesRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -813,6 +806,7 @@ type ListTablesResponse struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + // list of tables Tables []string `protobuf:"bytes,1,rep,name=tables,proto3" json:"tables,omitempty"` } @@ -855,6 +849,91 @@ func (x *ListTablesResponse) GetTables() []string { return nil } +type DropTableRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Table string `protobuf:"bytes,1,opt,name=table,proto3" json:"table,omitempty"` +} + +func (x *DropTableRequest) Reset() { + *x = DropTableRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_db_proto_msgTypes[16] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DropTableRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DropTableRequest) ProtoMessage() {} + +func (x *DropTableRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_db_proto_msgTypes[16] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DropTableRequest.ProtoReflect.Descriptor instead. +func (*DropTableRequest) Descriptor() ([]byte, []int) { + return file_proto_db_proto_rawDescGZIP(), []int{16} +} + +func (x *DropTableRequest) GetTable() string { + if x != nil { + return x.Table + } + return "" +} + +type DropTableResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *DropTableResponse) Reset() { + *x = DropTableResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_db_proto_msgTypes[17] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DropTableResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DropTableResponse) ProtoMessage() {} + +func (x *DropTableResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_db_proto_msgTypes[17] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DropTableResponse.ProtoReflect.Descriptor instead. +func (*DropTableResponse) Descriptor() ([]byte, []int) { + return file_proto_db_proto_rawDescGZIP(), []int{17} +} + var File_proto_db_proto protoreflect.FileDescriptor var file_proto_db_proto_rawDesc = []byte{ @@ -898,52 +977,59 @@ var file_proto_db_proto_rawDesc = []byte{ 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x27, 0x0a, 0x0f, 0x54, 0x72, 0x75, 0x6e, 0x63, 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, 0x22, 0x28, 0x0a, 0x10, 0x54, 0x72, 0x75, 0x6e, 0x63, 0x61, 0x74, - 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x61, 0x62, + 0x74, 0x61, 0x62, 0x6c, 0x65, 0x22, 0x12, 0x0a, 0x10, 0x54, 0x72, 0x75, 0x6e, 0x63, 0x61, 0x74, + 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x24, 0x0a, 0x0c, 0x43, 0x6f, 0x75, + 0x6e, 0x74, 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, 0x22, - 0x24, 0x0a, 0x0c, 0x43, 0x6f, 0x75, 0x6e, 0x74, 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, 0x22, 0x25, 0x0a, 0x0d, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x38, 0x0a, 0x12, - 0x52, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x12, 0x0e, 0x0a, 0x02, 0x74, 0x6f, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x02, 0x74, 0x6f, 0x22, 0x15, 0x0a, 0x13, 0x52, 0x65, 0x6e, 0x61, 0x6d, 0x65, - 0x54, 0x61, 0x62, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x13, 0x0a, - 0x11, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x22, 0x2c, 0x0a, 0x12, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x73, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x74, 0x61, 0x62, 0x6c, - 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x73, - 0x32, 0xb4, 0x03, 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, 0x12, 0x37, 0x0a, - 0x08, 0x54, 0x72, 0x75, 0x6e, 0x63, 0x61, 0x74, 0x65, 0x12, 0x13, 0x2e, 0x64, 0x62, 0x2e, 0x54, - 0x72, 0x75, 0x6e, 0x63, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, - 0x2e, 0x64, 0x62, 0x2e, 0x54, 0x72, 0x75, 0x6e, 0x63, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x2e, 0x0a, 0x05, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, - 0x10, 0x2e, 0x64, 0x62, 0x2e, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x11, 0x2e, 0x64, 0x62, 0x2e, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x40, 0x0a, 0x0b, 0x52, 0x65, 0x6e, 0x61, 0x6d, 0x65, - 0x54, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x16, 0x2e, 0x64, 0x62, 0x2e, 0x52, 0x65, 0x6e, 0x61, 0x6d, - 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, - 0x64, 0x62, 0x2e, 0x52, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3d, 0x0a, 0x0a, 0x4c, 0x69, 0x73, 0x74, - 0x54, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x12, 0x15, 0x2e, 0x64, 0x62, 0x2e, 0x4c, 0x69, 0x73, 0x74, - 0x54, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, - 0x64, 0x62, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x73, 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, + 0x25, 0x0a, 0x0d, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x38, 0x0a, 0x12, 0x52, 0x65, 0x6e, 0x61, 0x6d, 0x65, + 0x54, 0x61, 0x62, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, + 0x66, 0x72, 0x6f, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x66, 0x72, 0x6f, 0x6d, + 0x12, 0x0e, 0x0a, 0x02, 0x74, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x74, 0x6f, + 0x22, 0x15, 0x0a, 0x13, 0x52, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x13, 0x0a, 0x11, 0x4c, 0x69, 0x73, 0x74, 0x54, + 0x61, 0x62, 0x6c, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x2c, 0x0a, 0x12, + 0x4c, 0x69, 0x73, 0x74, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, + 0x28, 0x09, 0x52, 0x06, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x22, 0x28, 0x0a, 0x10, 0x44, 0x72, + 0x6f, 0x70, 0x54, 0x61, 0x62, 0x6c, 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, 0x22, 0x13, 0x0a, 0x11, 0x44, 0x72, 0x6f, 0x70, 0x54, 0x61, 0x62, 0x6c, + 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xf0, 0x03, 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, 0x12, 0x37, 0x0a, 0x08, 0x54, 0x72, 0x75, 0x6e, 0x63, 0x61, + 0x74, 0x65, 0x12, 0x13, 0x2e, 0x64, 0x62, 0x2e, 0x54, 0x72, 0x75, 0x6e, 0x63, 0x61, 0x74, 0x65, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x64, 0x62, 0x2e, 0x54, 0x72, 0x75, + 0x6e, 0x63, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, + 0x2e, 0x0a, 0x05, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x10, 0x2e, 0x64, 0x62, 0x2e, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x64, 0x62, 0x2e, + 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, + 0x40, 0x0a, 0x0b, 0x52, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x16, + 0x2e, 0x64, 0x62, 0x2e, 0x52, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x64, 0x62, 0x2e, 0x52, 0x65, 0x6e, 0x61, + 0x6d, 0x65, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x00, 0x12, 0x3d, 0x0a, 0x0a, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x12, + 0x15, 0x2e, 0x64, 0x62, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x64, 0x62, 0x2e, 0x4c, 0x69, 0x73, 0x74, + 0x54, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, + 0x12, 0x3a, 0x0a, 0x09, 0x44, 0x72, 0x6f, 0x70, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x14, 0x2e, + 0x64, 0x62, 0x2e, 0x44, 0x72, 0x6f, 0x70, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x64, 0x62, 0x2e, 0x44, 0x72, 0x6f, 0x70, 0x54, 0x61, 0x62, + 0x6c, 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 ( @@ -958,7 +1044,7 @@ func file_proto_db_proto_rawDescGZIP() []byte { return file_proto_db_proto_rawDescData } -var file_proto_db_proto_msgTypes = make([]protoimpl.MessageInfo, 16) +var file_proto_db_proto_msgTypes = make([]protoimpl.MessageInfo, 18) var file_proto_db_proto_goTypes = []interface{}{ (*ReadRequest)(nil), // 0: db.ReadRequest (*ReadResponse)(nil), // 1: db.ReadResponse @@ -976,12 +1062,14 @@ var file_proto_db_proto_goTypes = []interface{}{ (*RenameTableResponse)(nil), // 13: db.RenameTableResponse (*ListTablesRequest)(nil), // 14: db.ListTablesRequest (*ListTablesResponse)(nil), // 15: db.ListTablesResponse - (*_struct.Struct)(nil), // 16: google.protobuf.Struct + (*DropTableRequest)(nil), // 16: db.DropTableRequest + (*DropTableResponse)(nil), // 17: db.DropTableResponse + (*_struct.Struct)(nil), // 18: google.protobuf.Struct } var file_proto_db_proto_depIdxs = []int32{ - 16, // 0: db.ReadResponse.records:type_name -> google.protobuf.Struct - 16, // 1: db.CreateRequest.record:type_name -> google.protobuf.Struct - 16, // 2: db.UpdateRequest.record:type_name -> google.protobuf.Struct + 18, // 0: db.ReadResponse.records:type_name -> google.protobuf.Struct + 18, // 1: db.CreateRequest.record:type_name -> google.protobuf.Struct + 18, // 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 @@ -990,16 +1078,18 @@ var file_proto_db_proto_depIdxs = []int32{ 10, // 8: db.Db.Count:input_type -> db.CountRequest 12, // 9: db.Db.RenameTable:input_type -> db.RenameTableRequest 14, // 10: db.Db.ListTables:input_type -> db.ListTablesRequest - 3, // 11: db.Db.Create:output_type -> db.CreateResponse - 1, // 12: db.Db.Read:output_type -> db.ReadResponse - 5, // 13: db.Db.Update:output_type -> db.UpdateResponse - 7, // 14: db.Db.Delete:output_type -> db.DeleteResponse - 9, // 15: db.Db.Truncate:output_type -> db.TruncateResponse - 11, // 16: db.Db.Count:output_type -> db.CountResponse - 13, // 17: db.Db.RenameTable:output_type -> db.RenameTableResponse - 15, // 18: db.Db.ListTables:output_type -> db.ListTablesResponse - 11, // [11:19] is the sub-list for method output_type - 3, // [3:11] is the sub-list for method input_type + 16, // 11: db.Db.DropTable:input_type -> db.DropTableRequest + 3, // 12: db.Db.Create:output_type -> db.CreateResponse + 1, // 13: db.Db.Read:output_type -> db.ReadResponse + 5, // 14: db.Db.Update:output_type -> db.UpdateResponse + 7, // 15: db.Db.Delete:output_type -> db.DeleteResponse + 9, // 16: db.Db.Truncate:output_type -> db.TruncateResponse + 11, // 17: db.Db.Count:output_type -> db.CountResponse + 13, // 18: db.Db.RenameTable:output_type -> db.RenameTableResponse + 15, // 19: db.Db.ListTables:output_type -> db.ListTablesResponse + 17, // 20: db.Db.DropTable:output_type -> db.DropTableResponse + 12, // [12:21] is the sub-list for method output_type + 3, // [3:12] 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 @@ -1203,6 +1293,30 @@ func file_proto_db_proto_init() { return nil } } + file_proto_db_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DropTableRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_db_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DropTableResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -1210,7 +1324,7 @@ func file_proto_db_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_proto_db_proto_rawDesc, NumEnums: 0, - NumMessages: 16, + NumMessages: 18, NumExtensions: 0, NumServices: 1, }, diff --git a/db/proto/db.pb.micro.go b/db/proto/db.pb.micro.go index ce6e655..ede31e0 100644 --- a/db/proto/db.pb.micro.go +++ b/db/proto/db.pb.micro.go @@ -51,6 +51,7 @@ type DbService interface { Count(ctx context.Context, in *CountRequest, opts ...client.CallOption) (*CountResponse, error) RenameTable(ctx context.Context, in *RenameTableRequest, opts ...client.CallOption) (*RenameTableResponse, error) ListTables(ctx context.Context, in *ListTablesRequest, opts ...client.CallOption) (*ListTablesResponse, error) + DropTable(ctx context.Context, in *DropTableRequest, opts ...client.CallOption) (*DropTableResponse, error) } type dbService struct { @@ -145,6 +146,16 @@ func (c *dbService) ListTables(ctx context.Context, in *ListTablesRequest, opts return out, nil } +func (c *dbService) DropTable(ctx context.Context, in *DropTableRequest, opts ...client.CallOption) (*DropTableResponse, error) { + req := c.c.NewRequest(c.name, "Db.DropTable", in) + out := new(DropTableResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // Server API for Db service type DbHandler interface { @@ -156,6 +167,7 @@ type DbHandler interface { Count(context.Context, *CountRequest, *CountResponse) error RenameTable(context.Context, *RenameTableRequest, *RenameTableResponse) error ListTables(context.Context, *ListTablesRequest, *ListTablesResponse) error + DropTable(context.Context, *DropTableRequest, *DropTableResponse) error } func RegisterDbHandler(s server.Server, hdlr DbHandler, opts ...server.HandlerOption) error { @@ -168,6 +180,7 @@ func RegisterDbHandler(s server.Server, hdlr DbHandler, opts ...server.HandlerOp Count(ctx context.Context, in *CountRequest, out *CountResponse) error RenameTable(ctx context.Context, in *RenameTableRequest, out *RenameTableResponse) error ListTables(ctx context.Context, in *ListTablesRequest, out *ListTablesResponse) error + DropTable(ctx context.Context, in *DropTableRequest, out *DropTableResponse) error } type Db struct { db @@ -211,3 +224,7 @@ func (h *dbHandler) RenameTable(ctx context.Context, in *RenameTableRequest, out func (h *dbHandler) ListTables(ctx context.Context, in *ListTablesRequest, out *ListTablesResponse) error { return h.DbHandler.ListTables(ctx, in, out) } + +func (h *dbHandler) DropTable(ctx context.Context, in *DropTableRequest, out *DropTableResponse) error { + return h.DbHandler.DropTable(ctx, in, out) +} diff --git a/db/proto/db.proto b/db/proto/db.proto index 8f79429..8490940 100644 --- a/db/proto/db.proto +++ b/db/proto/db.proto @@ -14,6 +14,7 @@ service Db { rpc Count(CountRequest) returns (CountResponse) {} rpc RenameTable(RenameTableRequest) returns (RenameTableResponse) {} rpc ListTables(ListTablesRequest) returns (ListTablesResponse) {} + rpc DropTable(DropTableRequest) returns (DropTableResponse) {} } @@ -83,13 +84,10 @@ message DeleteResponse { // Truncate the records in a table message TruncateRequest { - // Optional table name. Defaults to 'default' string table = 1; } message TruncateResponse { - // The table truncated - string table = 1; } // Count records in a table @@ -124,3 +122,12 @@ message ListTablesResponse { // list of tables repeated string tables = 1; } + +// Drop a table in the DB +message DropTableRequest { + string table = 1; +} + +message DropTableResponse { +} +