You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[X ] latest
[ ] @next
[ ] 0.x.x (or put your version here)
Steps to reproduce or a small repository showing the problem:
It would be very useful to export DateUtils in the typeorm module in order to aid in raw sql queries. Raw queries are particularly useful for me, because I am in the gradual process of moving sql tables into TypeORM, but it's just not feasible (or CI/CD-approach) to do it all in one release of my app. If I should elaborate more, please let me know.
Right now you can import it, but it requires a bit more complex statement: import { DateUtils } from "typeorm/util/DateUtils";. If you want to make it exported directyle from typeorm - make a PR :)
Thanks @Kononnable. I think the import you suggested is fine. I didn't realize that anyway typeorm is not pre-bundled, so it's not necessary to export from typeorm.
TypeORM is now pre-bundled. @jacobg what do you mean? there hasn't been any recent change in overall file structure of the published package, nor in the exports defined in package.json.
BTW, how are you using DateUtils?
We need to improve the way data types (especially dates) are handled - this might happen in a minor (not a major) release, depending if the overall change is breaking or not (but I would not consider DateUtils as public API, so if it breaks, it breaks).
That was added in 2022 when ESM support was added: 3a694dd
Our app uses DateUtils to help with db migration like this:
exportfunctionprepareValueForMigration(value: any,column: TableColumnOptions){if(value==='true')return1if(value==='false')return0if(value==='')returnnullif(column.type==='datetime'){constepoch=Date.parse(value)if(!isNaN(epoch)){// Make sure we save date as string in TypeORM's expected format of// '2018-03-14 02:33:33.906'. Because if it's in ISO 8601 format,// it can corrupt the string by adding a Z to a datetime string that// already has timezone at the end.// https://github.com/typeorm/typeorm/blob/master/src/driver/sqlite-abstract/AbstractSqliteDriver.ts#L273value=DateUtils.mixedDateToUtcDatetimeString(newDate(epoch))}}returnvalue}
@jacobg Okay, so you are doing something like Driver.preparePersistentValue. You are then passing this as a parameter, right? Via e.g. QueryRunner.query?
Any reason why you can't use that function directly?
@jacobg Okay, so you are doing something like Driver.preparePersistentValue. You are then passing this as a parameter, right? Via e.g. QueryRunner.query?
Any reason why you can't use that function directly?
I'm not sure if we'll be able to get the ColumnMetadata that preparePersistentValue requires, since an older migration might not have the same metadata as current entity class.
Activity
Kononnable commentedon Apr 20, 2019
Right now you can import it, but it requires a bit more complex statement:
import { DateUtils } from "typeorm/util/DateUtils";. If you want to make it exported directyle fromtypeorm- make a PR :)jacobg commentedon Apr 23, 2019
Thanks @Kononnable. I think the import you suggested is fine. I didn't realize that anyway typeorm is not pre-bundled, so it's not necessary to export from
typeorm.jacobg commentedon May 13, 2026
Re-opening this issue, as TypeORM is now pre-bundled.
alumni commentedon Jul 13, 2026
BTW, how are you using
DateUtils?We need to improve the way data types (especially dates) are handled - this might happen in a minor (not a major) release, depending if the overall change is breaking or not (but I would not consider
DateUtilsas public API, so if it breaks, it breaks).jacobg commentedon Jul 13, 2026
@alumni
This:
causes this error:
unless I do this:
Is it because now typeorm's package.json defines its exports?
typeorm/package.json
Lines 19 to 45 in 0caca21
That was added in 2022 when ESM support was added:
3a694dd
Our app uses DateUtils to help with db migration like this:
alumni commentedon Jul 13, 2026
@jacobg Okay, so you are doing something like
Driver.preparePersistentValue. You are then passing this as a parameter, right? Via e.g.QueryRunner.query?Any reason why you can't use that function directly?
jacobg commentedon Jul 14, 2026
I'm not sure if we'll be able to get the
ColumnMetadatathatpreparePersistentValuerequires, since an older migration might not have the same metadata as current entity class.