Parse parses the given CREATE FUNCTION string (which must be the entire string, not just the body) into a Block containing the contents of the body.
(fullCreateFunctionString string)
| 24 | // Parse parses the given CREATE FUNCTION string (which must be the entire string, not just the body) into a Block |
| 25 | // containing the contents of the body. |
| 26 | func Parse(fullCreateFunctionString string) ([]InterpreterOperation, error) { |
| 27 | var functions []function |
| 28 | parsedBody, err := pg_query.ParsePlPgSqlToJSON(fullCreateFunctionString) |
| 29 | if err != nil { |
| 30 | return nil, err |
| 31 | } |
| 32 | err = json.Unmarshal([]byte(parsedBody), &functions) |
| 33 | if err != nil { |
| 34 | return nil, err |
| 35 | } |
| 36 | if len(functions) != 1 { |
| 37 | return nil, errors.New("CREATE FUNCTION parsed multiple blocks") |
| 38 | } |
| 39 | block, err := jsonConvert(functions[0].Function) |
| 40 | if err != nil { |
| 41 | return nil, err |
| 42 | } |
| 43 | ops := make([]InterpreterOperation, 0, len(block.Body)+len(block.Variables)) |
| 44 | stack := NewInterpreterStack(nil) |
| 45 | if err = block.AppendOperations(&ops, &stack); err != nil { |
| 46 | return nil, err |
| 47 | } |
| 48 | if err = reconcileLabels(ops); err != nil { |
| 49 | return nil, err |
| 50 | } |
| 51 | return ops, nil |
| 52 | } |
no test coverage detected