Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/lib/PostgrestQueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {

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

if (Array.isArray(values)) {
const columns = values.reduce((acc, x) => acc.concat(Object.keys(x)), [] as string[])
const uniqueColumns = [...new Set(columns)]
this.url.searchParams.set('columns', uniqueColumns.join(','))
}

return new PostgrestFilterBuilder(this)
}

Expand Down
5 changes: 5 additions & 0 deletions test/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,8 @@ describe("insert, update, delete with count: 'exact'", () => {
expect(res).toMatchSnapshot()
})
})

test('insert includes columns param', async () => {
const client = postgrest.from('users').insert([{ foo: 1 }, { bar: 2 }])
expect((client as any).url.searchParams.get('columns')).toMatchInlineSnapshot(`"foo,bar"`)
})