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
31 lines (28 loc) · 647 Bytes
/
cmd.go
File metadata and controls
31 lines (28 loc) · 647 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
package validate
import (
"fmt"
"github.com/kyleconroy/sqlc/internal/sql/ast"
)
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 *ast.SelectStmt:
return nil
case *ast.DeleteStmt:
list = stmt.ReturningList
case *ast.InsertStmt:
list = stmt.ReturningList
case *ast.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
}