调用示例

    DML/DDL 语句执行并备份示例

    1. // Set up a connection to the server.
    2. conn, err := grpc.Dial(address, grpc.WithInsecure())
    3. if err != nil {
    4. log.Fatalf("did not connect: %v", err)
    5. }
    6. defer conn.Close()
    7. c := pb.NewJunoClient(conn)
    8. ctx, cancel := context.WithTimeout(context.Background(), time.Second)
    9. defer cancel()
    10. r, err := c.OrderDDLExec(ctx, order)
    11. if err != nil {
    12. log.Fatalf("could not connect: %v", err)
    13. }
    14. fmt.Println(r.Message)
    15. }
    16. func ExDMLClient(order *pb.YearningAuditOrder) {
    17. // Set up a connection to the server.
    18. conn, err := grpc.Dial(address, grpc.WithInsecure())
    19. log.Fatalf("did not connect: %v", err)
    20. defer conn.Close()
    21. c := pb.NewJunoClient(conn)
    22. ctx, cancel := context.WithTimeout(context.Background(), time.Second)
    23. defer cancel()
    24. r, err := c.OrderDMLExec(ctx, order)
    25. if err != nil {
    26. log.Fatalf("could not connect: %v", err)
    27. }
    28. fmt.Println(r.Message)
    29. }
    30. func TestExDDLClient(t *testing.T) {
    31. s := pb.YearningAuditOrder{
    32. SQL: "CREATE TABLE `core_grai32ned` (`id` int unsigned AUTO_INCREMENT PRIMARY KEY COMMENT 'id',`username` varchar(50) NOT NULL COMMENT 'xxx')",
    33. DataBase: "test01",
    34. Source: &pb.Source{
    35. Addr: "127.0.0.1",
    36. User: "root",
    37. Password: "xxxxxxxx",
    38. Port: 3306,
    39. },
    40. Execute: true,
    41. WorkId: "201907292801",
    42. }
    43. ExDDLClient(&s)
    44. }
    45. func TestExDMLClient(t *testing.T) {
    46. s := pb.YearningAuditOrder{
    47. SQL: "INSERT INTO `Yearning`.`b_test`(`id`,`idx`,`dateux`) VALUES(66732326,'321',NULL);",
    48. DataBase: "test01",
    49. Table: "b_test",
    50. Source: &pb.Source{
    51. Addr: "127.0.0.1",
    52. User: "root",
    53. Password: "xxxxxxx",
    54. Port: 3306,
    55. },
    56. IsDML: true,
    57. Backup: true,
    58. Execute: true,
    59. WorkId: "201907292801",
    60. }
    61. ExDMLClient(&s)