Closed thelinuxlich closed 11 months ago
In case someone stumbles upon this issue wanting the same, this is how I found a way to disable it (but not entirely, still creates TableID)
// .kanelrc.js
generateIdentifierType: (c, d, config) => {
// Id columns are already prefixed with the table name, so we don't need to add it here
const name = toPascalCase(c.name);
const innerType = resolveType(c, d, {
...config,
generateIdentifierType: undefined,
});
return {
declarationType: 'typeDeclaration',
name,
exportAs: 'named',
typeDefinition: [innerType],
comment: []
};
}
I wasted a lot of time spinning my wheels on this. TDLR for those having issues,
export type UsersId = string & { __brand: "UsersId" }
vs.
export type UsersId = string
The former type declaration forces you to explicity indicate that the value is a UsersId
. For the latter any string will build fine. It's meant to make you sure you are aware the value you are passing is a pkey and not something else. This stackoverflow discussion explains it in more depth.
@kristiandupont Can this be added to documentation or README? I wasn't familiar with typescript intersections before using Kanel.
I am sorry that you had a frustrating experience! Yes, this should be optional and documented. Sorry that I haven't been able to fix it yet!
All good. kanel has saved me so much time generating kysely schema.
I added PR #461 with a small note that would've helped me. Hope that helps!
Not every user knows about branded IDs or wants the extra check through type guards. Kanel should have a option to generate the ID column as any other column, without a TableNameID.