© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago
Marťafiixek

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
column.name
returns name of a column as it is in database itself (
column_name
column_name
). However, for the purpose above I need to get the column name in the schema format
columnName
columnName
. How can I achieve this?
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

dynamic table name
Drizzle TeamDTDrizzle Team / help
3y ago
Column name alias
Drizzle TeamDTDrizzle Team / help
3y ago
Mapped column name and relation with the original name
Drizzle TeamDTDrizzle Team / help
3y ago
cannot insert into column "id"
Drizzle TeamDTDrizzle Team / help
11mo ago