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

Commit 106bb7e

Browse files
committed
CSV Response
1 parent e14461c commit 106bb7e

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/lib/PostgrestTransformBuilder.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,12 @@ export default class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
9393
this.headers['Accept'] = 'application/vnd.pgrst.object+json'
9494
return this as PromiseLike<PostgrestSingleResponse<T>>
9595
}
96+
97+
/**
98+
* Set the response type to CSV.
99+
*/
100+
csv(): this {
101+
this.headers['Accept'] = 'text/csv'
102+
return this
103+
}
96104
}

src/lib/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export abstract class PostgrestBuilder<T> implements PromiseLike<PostgrestRespon
9191
const isReturnMinimal = this.headers['Prefer']?.split(',').includes('return=minimal')
9292
if (this.method !== 'HEAD' && !isReturnMinimal) {
9393
const text = await res.text()
94-
if (text && text !== '') data = JSON.parse(text)
94+
if (text && text !== '' && this.headers['Accept'] !== 'text/csv') data = JSON.parse(text)
9595
}
9696

9797
const countHeader = this.headers['Prefer']?.match(/count=(exact|planned|estimated)/)

0 commit comments

Comments
 (0)