-
-
Notifications
You must be signed in to change notification settings - Fork 621
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
RFC: deprecate typeCast and introduce resultsMapper ( exact name TBD ) #1446
Comments
Although I am not currently maintaining Sequelize, I think apart from some refactor work in Sequelize this new implementation can be adopted without much effort, given that Note : (for sequelize team) this line will be changed to this new API. One issue could be custom buffer parsing for Geometry type |
Also please think of how we can make the roundtrip of the parameter as well. Let's say we use tinybit to represent a boolean value, how can we take a boolean value to insert it back into the database. |
I didn't think about that being a symmetric part of node-mysql2/lib/packets/execute.js Line 22 in 04cee65
|
If you want to do something like that, I think it will be much more performant if we allow the client to map only specific type. Unmapped types would be serialized/deserialized with the default logic without calling into the custom code every time. |
Hello 👋. Is this still being pursued? We're grappling with normalizing the results of our API to all boolean literals instead of 1/0 and would really appreciate this for handling the results of our prepared statements for |
@Parsonswy what's currently stopping you from using This is still being pursued though at a relatively low priority, happy to put a bit more attention if there is enough interest |
Thank you for the quick response. Yes, |
correct @Parsonswy , there isn't currently. The way typecast works is not 100% compatible between protocols if we just add it to execute. typeCast callbacks are allowed to call Ope possible option is to have |
That makes sense @sidorares. A general Could I'd be willing to help with an implementation for either of these approaches after some of these details are ironed out and adoption green lit. I am not sure what the support threshold is for adopting these changes. |
If we go that route we'll probably keep typeCast and only deprecate .string() / .number() etc methods |
Maybe worth making compatible with https://github.com/planetscale/database-js#custom-type-casting-function |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry I did not see this back in January, @wellwelwel. Now that typeCast: (field, next) => {
if (field.type === 'TINY' && field.length === 1) {
return field.string() === '1';
}
return next();
}
It seems like the general conscientious is still to deprecate typecast because these sorts of issues are inherent when this level of control is available, but as it stands this is sort of a bc break since the API behavior changed. I don't think it is possible for the hook to know if it is operating on binary or text results and choose to skip or change I think the |
What if we have a bit higher and call
This api would allow flexibility to configure base object for a row ( #2090 (comment) @nachogiljaldo ). It also makes possible to combine multiple column into single mapped object ( Point from a pair or doubles etc ). It also allows to emulate |
There are few issues with
typeCast
currently, and most of them better solved by moving it to a different level where it sits in the driver, I think it applies both tomysql2
/mysqljs/mysql
Problems I'd like to solve with the change:
execute()
.typeCast
in its current form expects user to know binary serialization format of results and data forexecute()
if often encoded differently from data forquery()
typeCast
is called before every column of a row is readMost importantly: almost every use case I see is "map rows from default types into something that works best for our use case" and not "I wan't to change / extend parsing logic".
Proposed solution
Introduce
resultsMapper
config function (happy to hear better name suggestions). If set, it's applied to every row and result of the function is then used as returned row.signature:
Deprecation strategy
typeCast
- note in the documentationCC ( not sure if I'm tagging correct people, if you know who is better suited to comment please let me know )
sequelize - @sushantdhiman , @papb
knex - @tgriesser , @kibertoad
mysqljs/mysql @dougwilson
The text was updated successfully, but these errors were encountered: