Custom precision on CreateDateColumn and UpdateDateColumn

See original GitHub issue

MySQL 5.6 and later releases provide support for fractional timestamps via the DATETIME(1) to DATETIME(6) column types. It would be nice for TypeORM to support them on CreateDateColumn and UpdateDateColumn decorators:

@CreateDateColumn('datetime(6)')  // does not work because default has to be CURRENT_TIMESTAMP(6) instead of CURRENT_TIMESTAMP
createdAt: Date;

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
TheRealAmircommented, Apr 17, 2020

@svicalifornia in 5.7 we create DATETIME with precision of 6 to make it more accurate. For backward compatibility with 5.5 I add in typeorm@0.2.0-alpha.42 support for precision: null which means that DATETIME or another date type column will be created without any precision.

@CreateDateColumn({ precision: null, type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
createDate: Date;

Hi Alex while your soultion fixed the problem for CreateDateColumn, UpdateDateColumn still suffers from the same problem.

I have used it like so: @UpdateDateColumn({ precision: null, type: "timestamp", default: () => "CURRENT_TIMESTAMP" }) createdAt: Date;

Am I missing something or this is still an issue? Thanks

1reaction
pleerockcommented, Mar 28, 2018

in latest @next you are able to do following:

@CreateDateColumn({ precision: 4 /* or any other */, default: () => "CURRENT_TIMESTAMP" })

To make this functionality to work on old mysql versions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - Custom precision on CreateDateColumn and ...
Custom precision on CreateDateColumn and UpdateDateColumn. ... TypeORM to support them on CreateDateColumn and UpdateDateColumn decorators:
Read more >
TypeORM Timestamp Date equality not working - Stack Overflow
I recently ran into the same problem and fixed it by adding precision: 3 to the column decorator. Please note that this is...
Read more >
Decorator reference - typeorm - GitBook
precision : number - The precision for a decimal (exact numeric) column (applies only for ... @PrimaryColumn() supports custom primary key constraint name:....
Read more >
typeorm/typeorm - Gitter
I want to invalidate the precision of "datetime (6)" of @CreateDateColumn. ... createdAt: Date; @UpdateDateColumn({name: 'updated_at', precision: 0, ...
Read more >
PostgreSQL and typeorm - Advanced Querying
This is to ensure that the seconds precision stored in postgres ... @UpdateDateColumn() updatedDate: Date // typeorm will use this to do ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found