LeftRight Return left, right values if is of form `table.column` or `schema`.`table` also return true/false for if it even has left/right
(val string)
| 23 | // LeftRight Return left, right values if is of form `table.column` or `schema`.`table` |
| 24 | // also return true/false for if it even has left/right |
| 25 | func LeftRight(val string) (string, string, bool) { |
| 26 | if len(val) < 2 { |
| 27 | return "", val, false |
| 28 | } |
| 29 | switch by := val[0]; by { |
| 30 | case '`': |
| 31 | vals := strings.Split(val, "`.`") |
| 32 | if len(vals) == 1 { |
| 33 | return "", IdentityTrim(val), false |
| 34 | } else if len(vals) == 2 { |
| 35 | return IdentityTrim(vals[0]), IdentityTrim(vals[1]), true |
| 36 | } |
| 37 | // wat, no idea what this is |
| 38 | return "", val, false |
| 39 | case '[': |
| 40 | vals := strings.Split(val, "].[") |
| 41 | if len(vals) == 1 { |
| 42 | return "", IdentityTrim(val), false |
| 43 | } else if len(vals) == 2 { |
| 44 | return IdentityTrim(vals[0]), IdentityTrim(vals[1]), true |
| 45 | } |
| 46 | // wat, no idea what this is |
| 47 | return "", val, false |
| 48 | default: |
| 49 | vals := strings.SplitN(val, ".", 2) |
| 50 | if len(vals) == 1 { |
| 51 | return "", val, false |
| 52 | } else if len(vals) == 2 { |
| 53 | return IdentityTrim(vals[0]), IdentityTrim(vals[1]), true |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | return "", val, false |
| 58 | } |
| 59 | |
| 60 | // IdentityTrim trims the leading/trailing identity quote marks ` or [] |
| 61 | func IdentityTrim(ident string) string { |