question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to store timestamp without @Create/UpdateDateColumn?

See original GitHub issue

Issue type:

[x] question [ ] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [ ] mysql / mariadb [ ] oracle [x] postgres [ ] sqlite [ ] sqljs [ ] websql

TypeORM version:

[ ] latest [x] @next [ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

@Entity()
export class Recipient {
  @ManyToOne(type => User, user => user.recipients, { primary: true })
  user: User;

  @ManyToOne(type => Message, message => message.recipients, { primary: true })
  message: Message;

  @Column({nullable: true})
  receivedAt;

  @Column({nullable: true})
  readAt;
}

I want to store a server-generated timestamp into the db. When the recipient gets inserted into the db receivedAt and readAt must be initiallty null, but once I’ll later update them I want them to be the actual date. How do I achieve it?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (15 by maintainers)

github_iconTop GitHub Comments

10reactions
pleerockcommented, Feb 15, 2018

Its solvable using DEFAULT constraint on a column:

@Column({ default: () => `now()` })
  receivedAt
2reactions
pleerockcommented, Feb 20, 2018
@Column()
receivingDate: Date

the following code is already “db-agnostic”. If you don’t specify a type “Date” automatically will find its database related type.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeORM When updating a specific column, save without ...
I want to save without affecting UpdateDateColumn when updating view column. This table is a post table and the view is a hit....
Read more >
Managing date and time with PostgreSQL and TypeORM
Under the hood, Postgres stores timestamps as numbers that represent a specific moment in time. The way they are displayed is based on...
Read more >
11.2.5 Automatic Initialization and Updating for TIMESTAMP ...
In this case, the column has no automatic properties at all. CREATE TABLE t1 ( ts TIMESTAMP DEFAULT 0, dt DATETIME DEFAULT 0...
Read more >
Date & Time Data Types - Snowflake Documentation
Snowflake supports a single DATE data type for storing dates (with no time ... TIMESTAMP WITHOUT TIME ZONE ... Create table using different...
Read more >
TypeORM: Adding created_at and updated_at columns
... the CreateDateColumn and UpdateDateColumn decorators, respectively. ... to the current date and time (that is, the current timestamp).
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