Created
March 10, 2024 11:50
-
-
Save capaj/270a4acaf649cc1242fc09e993c95f50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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