Reputation: 184
how can I autogenerate a timestamp in Postgres via Loopback 4? I tried this but it didn't work:
@property({ type: 'Date', generated: true, autoGenerated: true, postgresql: { dataType: 'timestamp with time zone', extension: 'now()' }, }) timestamp?: Date;
Upvotes: 0
Views: 309
Reputation: 44
There is two ways to achieve this.
Solution 1: Specify it directly in your database, for example
created_on timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL
Solution 2: Add it in your model
@property({
type: 'date',
default: () => new Date()
})
created? : Date;
Upvotes: 1