Skip to content

Commit

Permalink
Cast sql limit to bigint to force sqlc to generate NullInt64 (#2490)
Browse files Browse the repository at this point in the history
Signed-off-by: Vyom-Yadav <[email protected]>
  • Loading branch information
Vyom-Yadav authored Mar 7, 2024
1 parent f0c2571 commit 04a8002
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion database/query/repositories.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SELECT * FROM repositories
WHERE provider = $1 AND project_id = $2
AND (repo_id >= sqlc.narg('repo_id') OR sqlc.narg('repo_id') IS NULL)
ORDER BY project_id, provider, repo_id
LIMIT sqlc.narg('limit');
LIMIT sqlc.narg('limit')::bigint;

-- name: ListRegisteredRepositoriesByProjectIDAndProvider :many
SELECT * FROM repositories
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/ref/proto.md

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

6 changes: 3 additions & 3 deletions internal/controlplane/handlers_repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ func (s *Server) ListRepositories(ctx context.Context,
repoId = sql.NullInt64{Valid: true, Int64: reqRepoCursor.RepoId}
}

limit := sql.NullInt32{Valid: false, Int32: 0}
limit := sql.NullInt64{Valid: false, Int64: 0}
reqLimit := in.GetLimit()
if reqLimit > 0 {
if reqLimit > maxFetchLimit {
return nil, util.UserVisibleError(codes.InvalidArgument, "limit too high, max is %d", maxFetchLimit)
}
limit = sql.NullInt32{Valid: true, Int32: reqLimit + 1}
limit = sql.NullInt64{Valid: true, Int64: reqLimit + 1}
}

repos, err := s.store.ListRepositoriesByProjectID(ctx, db.ListRepositoriesByProjectIDParams{
Expand Down Expand Up @@ -205,7 +205,7 @@ func (s *Server) ListRepositories(ctx context.Context,
}

var respRepoCursor *cursorutil.RepoCursor
if limit.Valid && len(repos) == int(limit.Int32) {
if limit.Valid && int64(len(repos)) == limit.Int64 {
lastRepo := repos[len(repos)-1]
respRepoCursor = &cursorutil.RepoCursor{
ProjectId: projectID.String(),
Expand Down
4 changes: 2 additions & 2 deletions internal/db/repositories.sql.go

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

8 changes: 4 additions & 4 deletions pkg/api/openapi/minder/v1/minder.swagger.json

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

6 changes: 3 additions & 3 deletions pkg/api/protobuf/go/minder/v1/minder.pb.go

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

2 changes: 1 addition & 1 deletion proto/buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ breaking:
- WIRE_JSON
except:
# Upgrading an int32 to an int64; still accept int32 input, output shape changes
# Undo after #2415
# Undo after #2490
- FIELD_WIRE_JSON_COMPATIBLE_TYPE
lint:
use:
Expand Down
2 changes: 1 addition & 1 deletion proto/minder/v1/minder.proto
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ message DeleteRepositoryByNameResponse {

message ListRepositoriesRequest {
string provider = 1 [deprecated=true];
int32 limit = 3;
int64 limit = 3;
Context context = 5;
string cursor = 6;

Expand Down

0 comments on commit 04a8002

Please sign in to comment.