- Abstract shared sql code to a new drizzle package - Adds sqlite package, not ready to publish until drizzle patches some issues - Add `transactionOptions` to allow customizing or disabling db transactions - Adds "experimental" label to the `schemaName` property until drizzle patches an issue
20 lines
479 B
TypeScript
20 lines
479 B
TypeScript
import type { Insert } from './types.js'
|
|
|
|
export const insert: Insert = async function insert({
|
|
db,
|
|
onConflictDoUpdate,
|
|
tableName,
|
|
values,
|
|
}): Promise<Record<string, unknown>[]> {
|
|
const table = this.tables[tableName]
|
|
let result
|
|
|
|
if (onConflictDoUpdate) {
|
|
result = db.insert(table).values(values).onConflictDoUpdate(onConflictDoUpdate).returning()
|
|
} else {
|
|
result = db.insert(table).values(values).returning()
|
|
}
|
|
result = await result
|
|
return result
|
|
}
|