调用示例

SQL检测调用示例

  1. func TsClient(order *pb.YearningAuditOrder) {
  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.OrderDeal(ctx, order)
  11. if err != nil {
  12. log.Fatalf("could not connect: %v", err)
  13. }
  14. for _, i := range r.Record {
  15. fmt.Println(i.SQL) // SQL语句
  16. fmt.Println(i.Status) //审核状态
  17. fmt.Println(i.Level) // 错误等级
  18. fmt.Println(i.Error) // 错误信息
  19. fmt.Println(i.AffectRows) //影响行数
  20. }
  21. }
  22. func TestTsClient(t *testing.T) {
  23. s := pb.YearningAuditOrder{
  24. SQL: "CREATE TABLE `core_test` (`id` int unsigned AUTO_INCREMENT PRIMARY KEY COMMENT 'id',`username` varchar(50) NOT NULL COMMENT 'xxx')",
  25. DataBase: "test01",
  26. Source: &pb.Source{
  27. Addr: "127.0.0.1",
  28. User: "root",
  29. Password: "xxxxxxx",
  30. Port: 3306,
  31. },
  32. Check: true,
  33. WorkId: "201907292801",
  34. }
  35. TsClient(&s)
  36. }

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

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