forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd.go
More file actions
32 lines (29 loc) · 693 Bytes
/
cmd.go
File metadata and controls
32 lines (29 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package validate
import (
"fmt"
"github.com/kyleconroy/sqlc/internal/sql/ast"
"github.com/kyleconroy/sqlc/internal/sql/ast/pg"
)
func Cmd(n ast.Node, name, cmd string) error {
// TODO: Convert cmd to an enum
if !(cmd == ":many" || cmd == ":one") {
return nil
}
var list *ast.List
switch stmt := n.(type) {
case *pg.SelectStmt:
return nil
case *pg.DeleteStmt:
list = stmt.ReturningList
case *pg.InsertStmt:
list = stmt.ReturningList
case *pg.UpdateStmt:
list = stmt.ReturningList
default:
return nil
}
if list == nil || len(list.Items) == 0 {
return fmt.Errorf("query %q specifies parameter %q without containing a RETURNING clause", name, cmd)
}
return nil
}