Skip to content

Mark query parameters as nullable #1155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kyleconroy opened this issue Aug 28, 2021 · 4 comments
Closed

Mark query parameters as nullable #1155

kyleconroy opened this issue Aug 28, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@kyleconroy
Copy link
Collaborator

kyleconroy commented Aug 28, 2021

For the following query, sqlc will generate a function signature with a string for parameter $1.

CREATE TABLE users ( name TEXT NOT NULL );

-- name: ListUsers :many
SELECT *
FROM users
WHERE name = $1;
func (q *Queries) ListUsers(ctx context.Context, name string) ([]string, error) {
    // ...
}

How should we indicate that parameter $1 should be nullable?

Option 1: Add a parameter to the sqlc.arg function

CREATE TABLE users ( name TEXT NOT NULL );

-- name: ListUsers :many
SELECT *
FROM users
WHERE name = sqlc.arg('name', nullable => true);

Originally reported in #200

@kyleconroy kyleconroy added the enhancement New feature or request label Aug 28, 2021
@kyleconroy kyleconroy added the triage New issues that hasn't been reviewed label Aug 28, 2021
@imraan-go
Copy link

Option 1 seems to be the best way to implement this feature.

@mrsufgi
Copy link

mrsufgi commented Aug 29, 2021

how would you go about the shorthand for @param? new syntax? no shorthand?

@kyleconroy
Copy link
Collaborator Author

@mrsufgi the shorthand syntax is problematic (see #605), so for now this would only work when using sqlc.arg.

@kyleconroy
Copy link
Collaborator Author

Fixed by #1536

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants