(stmt ast.Node, src string, o opts.Parser)
| 16 | ) |
| 17 | |
| 18 | func (c *Compiler) parseQuery(stmt ast.Node, src string, o opts.Parser) (*Query, error) { |
| 19 | ctx := context.Background() |
| 20 | |
| 21 | if o.Debug.DumpAST { |
| 22 | debug.Dump(stmt) |
| 23 | } |
| 24 | |
| 25 | // validate sqlc-specific syntax |
| 26 | if err := validate.SqlcFunctions(stmt); err != nil { |
| 27 | return nil, err |
| 28 | } |
| 29 | |
| 30 | // rewrite queries to remove sqlc.* functions |
| 31 | |
| 32 | raw, ok := stmt.(*ast.RawStmt) |
| 33 | if !ok { |
| 34 | return nil, errors.New("node is not a statement") |
| 35 | } |
| 36 | rawSQL, err := source.Pluck(src, raw.StmtLocation, raw.StmtLen) |
| 37 | if err != nil { |
| 38 | return nil, err |
| 39 | } |
| 40 | if rawSQL == "" { |
| 41 | return nil, errors.New("missing semicolon at end of file") |
| 42 | } |
| 43 | |
| 44 | name, cmd, err := metadata.ParseQueryNameAndType(rawSQL, metadata.CommentSyntax(c.parser.CommentSyntax())) |
| 45 | if err != nil { |
| 46 | return nil, err |
| 47 | } |
| 48 | |
| 49 | if name == "" { |
| 50 | return nil, nil |
| 51 | } |
| 52 | |
| 53 | if err := validate.Cmd(raw.Stmt, name, cmd); err != nil { |
| 54 | return nil, err |
| 55 | } |
| 56 | |
| 57 | md := metadata.Metadata{ |
| 58 | Name: name, |
| 59 | Cmd: cmd, |
| 60 | } |
| 61 | |
| 62 | // TODO eventually can use this for name and type/cmd parsing too |
| 63 | cleanedComments, err := source.CleanedComments(rawSQL, c.parser.CommentSyntax()) |
| 64 | if err != nil { |
| 65 | return nil, err |
| 66 | } |
| 67 | |
| 68 | md.Params, md.Flags, md.RuleSkiplist, err = metadata.ParseCommentFlags(cleanedComments) |
| 69 | if err != nil { |
| 70 | return nil, err |
| 71 | } |
| 72 | |
| 73 | var anlys *analysis |
| 74 | if c.databaseOnlyMode && c.expander != nil { |
| 75 | // In database-only mode, use the expander for star expansion |
no test coverage detected