[feature request] insert/update params type nullability
See original GitHub issuecurrently, input types for insert and update queries (the ones in SET column_name = :param
) are always defined as param: Type | null | void
.
ideally, pgtyped should infer nullability. but you said in #118 that can’t be done easily.
you could implement a new syntax for explicitly specifying nullability and generate nullable types accordingly, e.g:
:param
-> current behaviour (no breaking changes), emit warning if ambiguous (possibly behind a flag):?param
or:param?
-> force nullable type:!param
or:param!
-> force non nullable type
also, when you generate properties as name: Type | null | void
, parameters are required by TS (have to explicitly set the to undefined), it would be better to generate them as name?: Type | null
(undefined
is still accepted by TS, but you can also omit that property).
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:7 (4 by maintainers)
Top Results From Across the Web
not-null columns in insert queries · Issue #118 · adelsz/pgtyped
We have table items with field name, which is not nullable. We also have query: INSERT INTO ... [feature request] insert/update params type...
Read more >Parameter defined as nullable, but no default value provided
The rule checks T-SQL code for procedures and functions parameters, which are defined as null-able, but have no default value provided. Even defined...
Read more >Insert, update, and delete data using data manipulation ...
This page describes how to insert, update, and delete Spanner data using Data Manipulation Language (DML) statements. You can run DML statements using...
Read more >query in sqlx - Rust - Docs.rs
Bind parameters in the SQL string are specific to the database backend: ... Option::None will be bound as NULL , so if binding...
Read more >15: 34.3. Command Execution Functions - PostgreSQL
PQexecParams is like PQexec , but offers additional functionality: parameter values can be ... It is ignored for null parameters and text-format parameters....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I was quite intrigued by the idea and think this would be a great expansion for
pgtyped
. Since I wanted to dive into pgtyped anyway, I went ahead and created a small prototype (https://github.com/JohnnyCrazy/pgtyped/tree/param-nullability) with the following syntax:Scalar
Since
:id
is required at least once, it will not be nullable:Array
We can also handle array spread syntax in the query itself
Pick
In the pick syntax we have to declare required keys in the param declaration, since the object itself is required anyway
Array Pick
In the pick syntax we have to declare required keys in the param declaration, since the array itself is required anyway
The
TS
version is pretty much the same principle,$userId! $$users! $user(id!, body)
. I didn’t find any mayor deal breakers and it should be non-breaking (I don’t think!
behind a variable is any valid postgres query). So in the end depends on @adelsz if he would like to see this in the project, I could clean up the branch and PR it.Thanks @JohnnyCrazy, that is a great proposal. I like the suffix modificator approach and will be happy to review & merge if you are willing to put together a draft PR.