Typing for checking column is foreign-key or not
Hi, is there any way to check if the column is foreign-key or not which return true or false by using typing. Check the example of primary-key attachment
5 Replies
Hi is there any help. Thanks
👋 not sure 🤔
Your isPrimaryColumn will not work with primary keys defined in table options and / or composite PK
I made https://drizzle.run/visualizer so I can tell that finding what is what is not easy 😅
What is your use case?
Drizzle Run
Visualizer - Drizzle Run
Hi @Raphaël M (@rphlmr) ⚡
Yah thanks for replying my question, so my case is:
You can see my example here, I want to write some functions for querying based on FK only, so want to force the typescript to only allow these FK key.
so for the articles table, id is PK, userId is FK
so for the PK we have
isPrimaryKey
returning type true or false
, not boolean. That's why the id
passed to the function is acceptable, userId
is not acceptable.
so I want to know which attr can check this userID
is FK or notI don't know if it's possible because even
getTableConfig
(where you find what is what) has no generic for ForeignKey[]