Dynamic function get use typed column names using getTableConfig

I have both UUIDs and NanoIDs on every one of my tables. I am considering adding utils to map from uuid -> nanoID & vice versa. how would i make a dynamic function like this? basically under the assumption every table has a id and shortId column which is the nanoid
export async function getUuidFromShortId(table: PgTable, shortId: string) {
const { columns, name, schema } = getTableConfig(table)
const [result] = await db
.select({ id: columns.id })
.from(name)
.where(eq(columns.shortId, shortId))
.limit(1)
return result[0]?.id ?? null
}
export async function getUuidFromShortId(table: PgTable, shortId: string) {
const { columns, name, schema } = getTableConfig(table)
const [result] = await db
.select({ id: columns.id })
.from(name)
.where(eq(columns.shortId, shortId))
.limit(1)
return result[0]?.id ?? null
}
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server