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
feat: rewrite Data Types #14505
feat: rewrite Data Types #14505
Conversation
converts data-types to TS
* meta: update unit tests from #14505 * meta: update typing tests * meta: update integration tests from #14505 * meta: fix ibmi/db2 unit test * meta: fix failing integration tests * meta: undo integration/utils changes * meta: undo index order * meta: remove incorrect mention of bigint * meta: fix index order test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I've gone through all tests and most of the implementation as well and I think that once I resolve all my comments we should be good to merge. Like you mentioned before there are indeed still a lot of TODOs but let's not make this PR even larger.
Also; I hope that we won't have any PRs of this size again soon
I can't agree more. This was one hell of a PR. Thankfully even files like |
All 3 are done. All that remains is sorting out the failing integration tests (dialects trying to use the "timezone" option but it's unsupported) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the tests agree I think we should be good to go! 🚀
PR Description
This PR migrates DataTypes to TypeScript.
It continues the work that was started in the previous DataType PRs by @allawesome497
Closes #14240 - @allawesome497's refactor
Closes #14239 - @allawesome497's refactor
Closes #14238 - @allawesome497's refactor
Closes #14220 - @allawesome497's refactor
Closes #14081 - @allawesome497's refactor
Closes #13981 - @allawesome497's refactor
Closes #13970 - @allawesome497's refactor
Closes #13799 - @allawesome497's refactor
Closes #12941 - initial refactor
Closes #14438
Closes #9786
Closes #8356
Closes #8963
Closes #13065
Closes #11828
Closes #11550
Closes #11266
Closes #11177
Closes #10946
Closes #10493
Closes #10383
Closes #8702
Closes #7930
Closes #10982
I'm doing the whole migration in one PR.
Notable Changes
.validate
on all of its DataTypes instead of just a single hardcoded one for strings.DataTypes.postgres.JSON
directly.DataTypes
are now fully responsible for properly escaping values that are injected in queries. This has been done because:SQLString.escape
delegates to DataTypes now. DataTypes are the one true source of truth for serialization.AcceptedType
. This was done because the previous 3 types added a lot of complexity with little to no benefit over just usingunknown
. Especially because we can't guarantee what we will be receiving from connectors. It's better to useunknown
and be defensive when treating the input.escape
key altogether. All DataTypes must properly escape their values themselves. No magic.JSONTYPE
. It was just an alias forJSON
, and should not be used.NUMERIC
, it was an alias forDECIMAL
DOUBLE PRECISION
, it was an alias forDOUBLE
DataTypes.ENUM
is able to generate its SQL type name.DataTypes.TIME
DataTypes.REAL
.DataTypes.FLOAT
is always single-precision floating point.DataTypes.DOUBLE
is always double-precision floating point. FLOAT & REAL are redundant, but we did not normalize so users needed all 3:JSON
support to all dialects. Basic means that the JSON value will be serialized/deserialized into a text column. No query support.DataTypes.DATE
in mssql & postgresMerge Squash Commit Message Body (for breaking changes)
Don't forget the empty line at the start of the body
Some explanations for above breaking change
values
outside ofENUM
. i.e. the following is no longer possible:Date
object if no JS DataType is specified.DataTypes.DATE
,DataTypes.DATETIME.ZONED
would both map to the Postgres DataTypetimestamptz
. We do a minimal amount of parsing based on the DB type, and if a JS DataType is specified, do extra parsing (such as converting to a Date object forDataTypes.DATE
, and a temporal object forDataTypes.DATETIME.ZONED
)DataTypes.DECIMAL
has very different meaning from one dialect to the other. In MySQL, it's defaulted toDataTypes.DECIMAL(10, 0)
(meaning a 10 digit number, with no decimal part). In postgres, it means "unconstrained". There are no way to have an unconstrained decimal any other way, soDataTypes.DECIMAL
is now interpreted as "unconstrained", and dialects that do not support unconstrained decimals now throw when no parameter is specified. This will require updating https://sequelize.org/docs/v7/other-topics/other-data-types/#exact-decimal-numbersTODO
ibmiimpossible to know, no DB availablesnowflakeimpossible to know, no DB availableThings to extract to other PRs
To reduce the weight of this one
_dialect
->dialect
inQueryGenerator
constructors meta: refactor _dialect to dialect in queryGenerator #15069classToInvokable
to its own filelogQuery
stringifies its parametersUtils.now()
&Utils.toDefaultValue()
accept a dialect instead of a dialect name meta: makeUtils.now()
andUtils.toDefaultValue()
accept a dialect #15072An error occured while normalizing attribute ${this.name}#${name}
).Blocking PRs
Follow Up Tasks