We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hi, I find sqlc and sqlc-gen-typescirpt are amazing!
Currently, the null type is used to indicate optional parameters, so the following query
null
-- name: CreateBook :one INSERT INTO book (title, description) VALUES (@title, COALESCE(@description, '':text)) RETURNING *;
generates the following argument type
export interface CreateBookArgs { title: string; description: string | null; } export async function createBook(client: Client, args: CreateBookArgs): Promise<CreateBookRow | null> {
which does not allow us to omit the empty fields so you have to always specify null.
createBook(client, { title: "a book" }); // error createBook(client, { title: "a book", description: null });
I think it would be more convenient if there's an option to use undefined instead.
undefined
export interface CreateBookArgs { title: string; description: string | undefined; // or description?: string }
With this type, you can write
createBook(client, { title: "a book" });
The option should also be useful for the users who use such request parser that coalesces empty inputs as undefined.
The same applies to the returning type (potentially empty row and potentially empty fields).
For implementation, I find pg handles undefined as null so it is purely a type issue, but I have no idea about other engines for now.
pg
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Hi, I find sqlc and sqlc-gen-typescirpt are amazing!
Currently, the
null
type is used to indicate optional parameters, so the following querygenerates the following argument type
which does not allow us to omit the empty fields so you have to always specify
null
.I think it would be more convenient if there's an option to use
undefined
instead.With this type, you can write
The option should also be useful for the users who use such request parser that coalesces empty inputs as
undefined
.The same applies to the returning type (potentially empty row and potentially empty fields).
For implementation, I find
pg
handlesundefined
asnull
so it is purely a type issue, but I have no idea about other engines for now.The text was updated successfully, but these errors were encountered: