Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit c865235

Browse files
committed
fix: include columns param on bulk INSERT
1 parent c5f4bb7 commit c865235

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/lib/PostgrestQueryBuilder.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
107107

108108
this.headers['Prefer'] = prefersHeaders.join(',')
109109

110+
if (Array.isArray(values)) {
111+
const columns = values.reduce((acc, x) => acc.concat(Object.keys(x)), [] as string[])
112+
const uniqueColumns = [...new Set(columns)]
113+
this.url.searchParams.set('columns', uniqueColumns.join(','))
114+
}
115+
110116
return new PostgrestFilterBuilder(this)
111117
}
112118

test/basic.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,8 @@ describe("insert, update, delete with count: 'exact'", () => {
234234
expect(res).toMatchSnapshot()
235235
})
236236
})
237+
238+
test('insert includes columns param', async () => {
239+
const client = postgrest.from('users').insert([{ foo: 1 }, { bar: 2 }])
240+
expect((client as any).url.searchParams.get('columns')).toMatchInlineSnapshot(`"foo,bar"`)
241+
})

0 commit comments

Comments
 (0)