-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
Infer TypeScript literals when possible #269
Comments
As stated in previous issues, doing something like this is equivalent to do Currently, you have 2 options:
Another approach which is currently not supported is to infer from table constraints (`col text CONSTRAINT union CHECK (col IN ('a', 'b', 'c')) |
Oh, is this still true with my example above (generated column / field data)? I thought that this would be a different case, because of the "generated" part... 🤔 To be clear, |
Oh, I'm sorry. I missed that. I think this could be achievable, but it would require some adjustments when comparing actual with expected. |
I believe I am running into the same limitation. await pool.query(sql.typeAlias('void')`
UPDATE recommendation_request
SET
created_at = (now() - ${`${daysOld} days`}::interval),
status = ${status}
WHERE id = ${recommendationRequestDatabaseId}
`); Table column
This is currently producing a syntax error: /Users/gajus/Developer/contra/gaia/apps/contra-api/testV2/workflows/expireRecommendationRequestsV1.test.ts
48:16 error Invalid Query: Error: syntax error at or near "IN" @ts-safeql/check-sql Posting here to calibrate on whether new issue or same, since the original issue does not mention syntax error. Casting |
Different issue that was introduced in 3.5.0 due to the way safeql handles union of literals. I'll push a fix in the next few days. Edit - fixed in 3.5.1 |
Amazing. Thank you! |
@Newbie012 thanks for this! Can confirm that this works for my case above! (needed to add // ✅
await sql<{ video_type: 'personal_intro' | 'tech_achievements' | null }[]>`
SELECT
CASE
WHEN personal_intro_vimeo_video_id = ${vimeoVideoId} THEN 'personal_intro'
WHEN tech_achievements_vimeo_video_id = ${vimeoVideoId} THEN 'tech_achievements'
END AS video_type
FROM
users
`; However, it seems to have introduced some new regressions: A) Missing type on
|
B) Some
|
Addressing both the of issues in #354 |
Is your feature request related to a problem? Please describe.
Previously, there were requests for support for TypeScript literal types in #120 and #119, which were not accepted, as they did not follow the SafeQL philosophy.
It would be nice for there to be partial support for literals (eg. string literals, number literals), to enable stricter types in applications.
An example:
Describe the solution you'd like
If there are inferable literal values in the query, infer literal values instead of
string
ornumber
Describe alternatives you've considered
--
Additional context
--
The text was updated successfully, but these errors were encountered: