-
Notifications
You must be signed in to change notification settings - Fork 280
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
add more control through configuration @ ParseJSONResultsPlugin
.
#1170
base: v0.28
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
ParseJSONResultsPlugin
.
d3cbb64
to
3a1825e
Compare
37c8404
to
54d4013
Compare
3a1825e
to
66b4fa4
Compare
66b4fa4
to
29d9e0f
Compare
29d9e0f
to
1b8164f
Compare
Coming from #1275 for context I know you are doing some absolute black magic with the types, so I'm not sure how cleanly this can be done with respect to revivers (though possibly it'd be cleaner?) I'd much prefer explicit opt-in than an opt-out list by column names. const rows = db.selectFrom('table').select(eb => eb.json('column_name')).execute(); Since the expression builder has the capability to pass forward its column's expected type, this should allow for syntax like: const rows = db.selectFrom('table').select(eb => eb.json('column_name', reviver)).execute(); Obviously this is less convenient, but it is more safe and flexible since you can define a type-safe reviver (or validation) function, type guard, etc. at the point of use. This means that you can see clearly what the query is doing and what you expect to receive. For convenience's sake, if you wanted to globally define JSON parsing behavior at the plugin level, you could potentially do something like this: interface ParseJSONResultsPluginOptions<Database> {
revivers: Partial<{
[Table in keyof Database]:
Partial<{
[Column in keyof Table]:
Table[Column] extends Reviver<infer P> ? P : never
}>
}>
} (not fully sure if that syntax would work, and of course it could be extracted into further generics) The idea being that, if you supply the plugin with your database interface (which is expected to match the same interface that you provide to the Kysely instance, and this should be enforceable?) - then you can define revivers for specific columns on specific tables, both of which are fully type-safe, and ensure that the reviver supplied returns the type defined on the table's interface. |
…kysely-org#1085) * add reusable helpers recipe and implement missing expression features * force node 22.4.1 in CI because of an npm bug
* feat: add postgres range types (kysely-org#1086) * feat: support refresh naterialized view * fix tests by adding .materialized() to remove the matview * fix failing test * fix: References typo (kysely-org#1092) * chore: refresh-view-node.ts => refresh-materialized-view-node.ts * chore: export node in index.ts --------- Co-authored-by: Isak <[email protected]> Co-authored-by: Jonathan Wu <[email protected]>
Co-authored-by: Igal Klebanov <[email protected]>
1b8164f
to
33ffc44
Compare
Open in Stackblitz • kysely_koa_example
commit: |
Hey 👋
This PR revisits
ParseJSONResultsPlugin
and attempts to provide more fine-grained control to consumers.skipKeys
allows you to specify columns to not parse in a result object.reviver
allows passing a custom reviver function to theJSON.parse
invocations. This can allow you to instantiate native Dates, or omit keys.__proto__
keys are always deleted to deny prototype pollution.isJSON
allows overriding what is or what isn't considered a JSON string before attempting toJSON.parse
it.