Skip to content
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

ParseJSONResultsPlugin creates type-safety issues #1275

Closed
myndzi opened this issue Nov 22, 2024 · 2 comments
Closed

ParseJSONResultsPlugin creates type-safety issues #1275

myndzi opened this issue Nov 22, 2024 · 2 comments

Comments

@myndzi
Copy link

myndzi commented Nov 22, 2024

Hi there. Thanks for this library, it's very much exactly what I was looking for :)

I'm prototyping something with SQLite -- so maybe it's a little my fault for even using it -- but I feel like this is a weird gotcha with a plausibly meaningful improvement to-hand.

I added the ParseJSONResultsPlugin for use in some queries I've written, and later encountered the unexpected behavior that it yolo-parses all columns if they "look like" JSON, whether I wanted it to or not. Because of the way Kysely works, I had typed that table with a string column, but was getting an object and crashing out, without TypeScript warning me about this behavior.

I feel like this is weird behavior that goes against the intent of the library, and would be improved by opting in to JSON parsing on a column so that the expectations (and the types) are correct and explicit. Obviously, Kysely can't know that the string column contains JSON, but that's why it's particularly weird that it can turn any text column into an object without the query itself saying to do so. This all-or-nothing behavior makes the plugin kinda useless, because it creates a scenario where you can't rely on the query builder to give you the types you've told it to give you.

I recognize that I can write my own transforms to behave how I want them to, but since this plugin is included in the library itself, it seems that it should be a bit tighter than it currently is. In particular, I was thrown by the examples, e.g. on this page which seem to indicate this sort of opt-in behavior.

Thoughts?

@igalklebanov
Copy link
Member

Hey 👋

These concerns are being explored at #1170.

@myndzi
Copy link
Author

myndzi commented Nov 22, 2024

Ah, sorry. I did some searches but didn't find it. Thank you :)

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

No branches or pull requests

2 participants