Dynamic column name and insert

Hi, how can I work with dynamic column names? I woud love to be able to do the following:
export const insertMultipleToJoinTable = async (
media: number[],
table: PgTable,
column: PgColumn,
entityId: number,
REDACTED: number | null,
REDACTED: number | null
) => {
await Promise.all(
media.map(async (mediaId) => {
await db.insert(table).values({
[column.name]: entityId,
mediaId,
})

await REDACTED(mediaId, REDACTED, REDACTED)
})
)
}
export const insertMultipleToJoinTable = async (
media: number[],
table: PgTable,
column: PgColumn,
entityId: number,
REDACTED: number | null,
REDACTED: number | null
) => {
await Promise.all(
media.map(async (mediaId) => {
await db.insert(table).values({
[column.name]: entityId,
mediaId,
})

await REDACTED(mediaId, REDACTED, REDACTED)
})
)
}
However, the following will not work as column.name returns name of a column as it is in database itself (column_name). However, for the purpose above I need to get the column name in the schema format columnName. How can I achieve this?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server