Skip to content

Instantly share code, notes, and snippets.

@capaj
Created March 10, 2024 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save capaj/270a4acaf649cc1242fc09e993c95f50 to your computer and use it in GitHub Desktop.
Save capaj/270a4acaf649cc1242fc09e993c95f50 to your computer and use it in GitHub Desktop.
import { Column, sql } from 'drizzle-orm'
import { SQLiteTable, SQLiteUpdateSetSource } from 'drizzle-orm/sqlite-core'
export function conflictUpdateSet<TTable extends SQLiteTable>(
table: TTable,
columns: (keyof TTable['_']['columns'] & keyof TTable)[]
): SQLiteUpdateSetSource<TTable> {
return Object.assign(
{},
...columns.map((k) => ({
[k]: sql.raw(`excluded.${(table[k] as Column).name}`)
}))
) as SQLiteUpdateSetSource<TTable>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment