Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions internal/codegen/golang/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,16 +312,16 @@ func buildQueries(req *plugin.GenerateRequest, options *opts.Options, structs []
return qs, nil
}

var cmdReturnsData = map[string]struct{}{
metadata.CmdBatchMany: {},
metadata.CmdBatchOne: {},
metadata.CmdMany: {},
metadata.CmdOne: {},
}

func putOutColumns(query *plugin.Query) bool {
if len(query.Columns) > 0 {
return true
}
for _, allowed := range []string{metadata.CmdMany, metadata.CmdOne, metadata.CmdBatchMany} {
if query.Cmd == allowed {
return true
}
}
return false
_, found := cmdReturnsData[query.Cmd]
return found
}

// It's possible that this method will generate duplicate JSON tag values
Expand Down
2 changes: 1 addition & 1 deletion internal/codegen/golang/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestPutOutColumns_ForZeroColumns(t *testing.T) {
},
{
cmd: metadata.CmdBatchOne,
want: false,
want: true,
},
}
for _, tc := range tests {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/endtoend/testdata/exec_no_return_struct/issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/sqlc-dev/sqlc/issues/2970

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- name: ResetTaskRun :exec
UPDATE job
SET last_run = NOW()
FROM (
SELECT last_run,
task_name
FROM job AS o
WHERE o.task_name = $1
FOR UPDATE
) AS old_values
WHERE job.task_name = $1
RETURNING job.last_run AS this_run,
old_values.last_run AS last_run;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE IF NOT EXISTS job
(
task_name text NOT NULL,
last_run timestamp with time zone DEFAULT now() NOT NULL
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "2"
sql:
- engine: "postgresql"
schema: "schema.sql"
queries: "query.sql"
gen:
go:
package: "querytest"
out: "go"
sql_package: "pgx/v5"
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ UPDATE foo SET id = $2 WHERE id = $1;

-- name: InsertFoo :one
INSERT INTO foo (id) VALUES ($1);

-- name: InsertFoo :batchone
INSERT INTO foo (id) VALUES ($1);
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ query.sql:5:1: invalid query comment: -- name: ListFoos :one :many
query.sql:8:1: invalid query type: :two
query.sql:11:1: query "DeleteFoo" specifies parameter ":one" without containing a RETURNING clause
query.sql:14:1: query "UpdateFoo" specifies parameter ":one" without containing a RETURNING clause
query.sql:17:1: query "InsertFoo" specifies parameter ":one" without containing a RETURNING clause
query.sql:17:1: query "InsertFoo" specifies parameter ":one" without containing a RETURNING clause
query.sql:20:1: query "InsertFoo" specifies parameter ":batchone" without containing a RETURNING clause
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ UPDATE foo SET id = $2 WHERE id = $1;

-- name: InsertFoo :one
INSERT INTO foo (id) VALUES ($1);

-- name: InsertFoo :batchone
INSERT INTO foo (id) VALUES ($1);
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ query.sql:5:1: invalid query comment: -- name: ListFoos :one :many
query.sql:8:1: invalid query type: :two
query.sql:11:1: query "DeleteFoo" specifies parameter ":one" without containing a RETURNING clause
query.sql:14:1: query "UpdateFoo" specifies parameter ":one" without containing a RETURNING clause
query.sql:17:1: query "InsertFoo" specifies parameter ":one" without containing a RETURNING clause
query.sql:17:1: query "InsertFoo" specifies parameter ":one" without containing a RETURNING clause
query.sql:20:1: query "InsertFoo" specifies parameter ":batchone" without containing a RETURNING clause
6 changes: 4 additions & 2 deletions internal/sql/validate/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ func Cmd(n ast.Node, name, cmd string) error {
return validateCopyfrom(n)
}
if (cmd == metadata.CmdBatchExec || cmd == metadata.CmdBatchMany) || cmd == metadata.CmdBatchOne {
return validateBatch(n)
if err := validateBatch(n); err != nil {
return err
}
}
if !(cmd == metadata.CmdMany || cmd == metadata.CmdOne) {
if !(cmd == metadata.CmdMany || cmd == metadata.CmdOne || cmd == metadata.CmdBatchMany || cmd == metadata.CmdBatchOne) {
return nil
}
var list *ast.List
Expand Down