How to store timestamp without @Create/UpdateDateColumn?
See original GitHub issueIssue 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:
- Created 6 years ago
- Comments:16 (15 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Its solvable using DEFAULT constraint on a column:
the following code is already “db-agnostic”. If you don’t specify a type “Date” automatically will find its database related type.