This repository was archived by the owner on Oct 9, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +34
-5
lines changed Expand file tree Collapse file tree 3 files changed +34
-5
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import fetch from 'cross-fetch'
22
33/**
44 * Error format
5- *
5+ *
66 * {@link https://postgrest.org/en/stable/api.html?highlight=options#errors-and-http-status-codes}
77 */
88interface PostgrestError {
@@ -12,9 +12,9 @@ interface PostgrestError {
1212 code : string
1313}
1414
15- /**
15+ /**
1616 * Response format
17- *
17+ *
1818 * {@link https://github.com/supabase/supabase-js/issues/32}
1919 */
2020interface PostgrestResponse < T > {
@@ -130,14 +130,14 @@ export class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
130130 insert (
131131 values : Partial < T > | Partial < T > [ ] ,
132132 { upsert = false , onConflict } : { upsert ?: boolean ; onConflict ?: string } = { }
133- ) : PostgrestBuilder < T > {
133+ ) : PostgrestFilterBuilder < T > {
134134 this . method = 'POST'
135135 this . headers [ 'Prefer' ] = upsert
136136 ? 'return=representation,resolution=merge-duplicates'
137137 : 'return=representation'
138138 if ( upsert && onConflict !== undefined ) this . url . searchParams . set ( 'on_conflict' , onConflict )
139139 this . body = values
140- return this
140+ return new PostgrestFilterBuilder ( this )
141141 }
142142
143143 /**
Original file line number Diff line number Diff line change @@ -169,3 +169,25 @@ Object {
169169 " statusText" : " OK" ,
170170}
171171` ;
172+
173+ exports [` single on insert 1` ] = `
174+ Object {
175+ " body" : Object {
176+ " age_range" : null ,
177+ " catchphrase" : null ,
178+ " data" : null ,
179+ " status" : " ONLINE" ,
180+ " username" : " foo" ,
181+ },
182+ " data" : Object {
183+ " age_range" : null ,
184+ " catchphrase" : null ,
185+ " data" : null ,
186+ " status" : " ONLINE" ,
187+ " username" : " foo" ,
188+ },
189+ " error" : null ,
190+ " status" : 201 ,
191+ " statusText" : " Created" ,
192+ }
193+ ` ;
Original file line number Diff line number Diff line change @@ -21,3 +21,10 @@ test('single', async () => {
2121 const res = await postgrest . from ( 'users' ) . select ( ) . limit ( 1 ) . single ( )
2222 expect ( res ) . toMatchSnapshot ( )
2323} )
24+
25+ test ( 'single on insert' , async ( ) => {
26+ const res = await postgrest . from ( 'users' ) . insert ( { username : 'foo' } ) . single ( )
27+ expect ( res ) . toMatchSnapshot ( )
28+
29+ await postgrest . from ( 'users' ) . delete ( ) . eq ( 'username' , 'foo' )
30+ } )
You can’t perform that action at this time.
0 commit comments