Repository navigation
WIP: Datatypes system refactor - #4186
Conversation
There was a problem hiding this comment.
Instead of calling util.inherits after each datatype, I added an inherits function to the abstract datatype, which inherits both prototype and static methods. Its also a utility method which creates the constructor for the new type, in cases where the constructor doesn't do anything interesting - saves a lot of copy-pasta
|
Ref #2042 |
d961003 to
5da4ffc
Compare
There was a problem hiding this comment.
This prints a deprecation notice but it's not really deprecated. It's just not the right type used. And the line provided by the module is the one from the DataTypes but it should be the line where the user inserted the wrong type. So this should probably be reconsidered.
There was a problem hiding this comment.
Agree, should be a warning more than a deprecation since we do want to normalize, but people should be aware that stuff might happen.
There was a problem hiding this comment.
But it haz suzh nize colorz!
Alright, I'll change it back to console.log...
This is a general problem with depd though - I actually thought it printed there line where the user did something wrong, but it always references a sequelize internal line number
There was a problem hiding this comment.
I thought it did that aswell, otherwise it's quite useless.
There was a problem hiding this comment.
If I'm not mistaken the issue with the call stack is that the warning is on the prototype and called from a internal function. That way depd is going to look at the next upper level and find the internal function that called it and prints that as the wrong line. So the depd call would have to happen in the function itself. It might work if you do something like that (I'm not sure though):
ABSTRACT.warn = function (text) {
return text + '\n>> Check: ' + this.dialectTypes;
};
// And now somehwere where the warning is triggered:
function trigger (value) {
if (typeof value !== 'number') {
deprecate(this.warn(text));
}
}But it would not solve the fact that it's not really a deprecation :) (and you can't suppress that word). If you want the colors that's easy to implement without the library. Just use something like console.log('\x1b[36mCOLORED_WORDS\x1b[0m');
There was a problem hiding this comment.
@BridgeAR Yep, you're right.
I just did a check, and everywhere we use depd is actually called from internally (e.g. here), so it never works as intended :D
I was thinking of writing my own version of depd, which basically traverses up the stack until it meets a filename that's not node_modules/sequelize/lib/**. Dunno how hard its going to be, but right now depd is not working any better than what we had before :D
There was a problem hiding this comment.
https://www.npmjs.com/package/stack-trace looks promising, and we don't have to mess with the error object ourselves.
Anyhow, any review comments on the other million changes in this PR ;) ?
|
I only had a short glimpse over the changes but this is looking very promising and I really like the overall idea behind it. |
|
@mikeringrose Just want to point your attention to this PR. Once its merged, all that needs to be done to add geometry support for sqlite and mssql is hopefully to add parse and stringify functions for the two dialects |
|
This is going to be a bitch to rebase - looking at you @mickhansen ! |
|
@mickhansen This also fixes the issues mentioned by #4822, but by parsing the raw value instead of selecting it as text. hint hint |
There was a problem hiding this comment.
Should $hexify not handle toString('hex')?
|
I can't seem to locate exactly where generic types are swapped for database specific types, can you point me to that? |
|
@janmeier Ah, so that didn't change. Not sure i fully comprehend the entire changeset but it seems well reasoned and i didn't spot any obvious mistakes. LGTM, lets rebase and i'll merge. |
|
@mickhansen Rebased Still a couple of loose ends to tie up with regards to documentation, and a couple more issues that couple be solved by this, but let's merge it and I'll look at the rest later |
|
@janmeier needs another one ;p |
…uple of unused vars. Fix a couple of datatypes related unit tests
WIP: Datatypes system refactor
|
<3 |
|
Up/Down mecanism for datatypes is not included in the docs yet?, I'm having troubles with mysql when parsing a BLOB from the database, it triggers my parse method even for TEXT fields and is not passing a Buffer as value as I expected, instead, it is passing an specific Field object from the mysql driver on which I have to call value.parser._buffer in order to get the buffer and I have no clue about the type of the field from this object. |

Phew - this turned out to be a bit more work than I had anticipated - but I think its for the better!
I still need to write the docs for the user facing parts (parse / stringify), but I want to get a review on the API before doing so.
Datatypes can now have
parseandstringifyfunctions.stringifyis called inQueryGenerator.escapeto convert the value into a DB representation. I've moved some of the code from sql-string directly into data-types. We might be able to move some more later.Parse is called when values are recieved from the DB. The parse part is not tied up to any model, meaning it also works for raw queries. Instead it is connected to type id (postgres and mssql) or type string (mysql and sqlite). This means that if two types use the same backing type in the DB, they cannot have two different parse functions, because we can't tell the difference when parsing. Which types this is is different from dialect to dialect - but we throw an error up front if a parse function is not supported for a particular dialect to make the error obvious to the user.
While I was messing around I also rewrote how type identification works in sqlite - it's a bit smarter now, and I've fixed a couple of bugs where dates weren't parsed properly in includes. We still issue
PRAGMA table_infobefore each query though - this could probably be cached - but I don't want to go into that now :)