ParseSubscriptionSQL parses the given SQL statement and returns a SubscriptionConfig.
(sql string)
| 70 | |
| 71 | // ParseSubscriptionSQL parses the given SQL statement and returns a SubscriptionConfig. |
| 72 | func parseSubscriptionSQL(sql string) (*SubscriptionConfig, error) { |
| 73 | var config SubscriptionConfig |
| 74 | switch { |
| 75 | case createRegex.MatchString(sql): |
| 76 | matches := createRegex.FindStringSubmatch(sql) |
| 77 | config.Action = Create |
| 78 | config.SubscriptionName = matches[1] |
| 79 | if len(matches) > 3 { |
| 80 | config.PublicationName = matches[3] |
| 81 | } |
| 82 | conn, err := parseConnectionString(matches[2]) |
| 83 | if err != nil { |
| 84 | return nil, err |
| 85 | } |
| 86 | config.Connection = conn |
| 87 | |
| 88 | case alterRegex.MatchString(sql): |
| 89 | matches := alterRegex.FindStringSubmatch(sql) |
| 90 | config.SubscriptionName = matches[1] |
| 91 | switch strings.ToUpper(matches[2]) { |
| 92 | case string(AlterDisable): |
| 93 | config.Action = AlterDisable |
| 94 | case string(AlterEnable): |
| 95 | config.Action = AlterEnable |
| 96 | default: |
| 97 | return nil, fmt.Errorf("invalid ALTER SUBSCRIPTION action: %s", matches[2]) |
| 98 | } |
| 99 | |
| 100 | case dropRegex.MatchString(sql): |
| 101 | matches := dropRegex.FindStringSubmatch(sql) |
| 102 | config.Action = Drop |
| 103 | config.SubscriptionName = matches[1] |
| 104 | |
| 105 | default: |
| 106 | return nil, nil |
| 107 | } |
| 108 | |
| 109 | return &config, nil |
| 110 | } |
| 111 | |
| 112 | // parseConnectionString parses the given connection string and returns a ConnectionDetails. |
| 113 | func parseConnectionString(connStr string) (*ConnectionDetails, error) { |
no test coverage detected