Creating Custom Primary Key Generated Column Value
See original GitHub issueLooking for a way to create some custom Primary Key value generated for Column in entity and that should be auto incremented.
Ex: @Entity(“DemandRecord”) export class DemandRecord {
@CustomColumn()
demandRecordNumber: number;
Ex:- demandRecordNumber values should be like YYYYMMDD001,YYYYMMDD002..like this where YYYYMMDD is year,month and date.
Am i not able to find any approach for this. In Hibernate we have ways to this but in TypeORM..i am not able to find any documents regarding this
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:15 (10 by maintainers)
Top Results From Across the Web
sql - How to create a custom auto generated ID number for a ...
If you want to make Product_No the primary key - just use this SQL syntax: CREATE TABLE Product ( ID INTEGER IDENTITY(1,1) NOT...
Read more >How to Automatically Generate Primary Key Values Using ...
This database uses the auto-increment field, so Vertabelo provides a straightforward way of creating a primary key. First, go to Table ...
Read more >Defining an Auto Increment Primary Key in SQL Server - Chartio
The first is PRIMARY KEY , which as the name suggests, forces the specified column to behave as a completely unique index for...
Read more >Generated Values - EF Core - Microsoft Learn
Database columns can have their values generated in various ways: primary key columns are frequently auto-incrementing integers, ...
Read more >Auto-generated primary keys: UUID, serial or identity column?
But typically, there is no such attribute, and you have to generate an artificial primary key. Some people even argue that you should...
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
There is no need for additional functionality in there.
Alternative to that approach you can do:
@pleerock for example in SQLite (primary column in SQLite is autogenerated too) if I try to do something like this (saving multiply objects at once)
Such log will be produced:
And all objects with undefined
id
will get id2
, because all@AfterInsert
executes after all insert queries.