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'
2
2
3
3
/**
4
4
* Error format
5
- *
5
+ *
6
6
* {@link https://postgrest.org/en/stable/api.html?highlight=options#errors-and-http-status-codes}
7
7
*/
8
8
interface PostgrestError {
@@ -12,9 +12,9 @@ interface PostgrestError {
12
12
code : string
13
13
}
14
14
15
- /**
15
+ /**
16
16
* Response format
17
- *
17
+ *
18
18
* {@link https://github.com/supabase/supabase-js/issues/32}
19
19
*/
20
20
interface PostgrestResponse < T > {
@@ -130,14 +130,14 @@ export class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
130
130
insert (
131
131
values : Partial < T > | Partial < T > [ ] ,
132
132
{ upsert = false , onConflict } : { upsert ?: boolean ; onConflict ?: string } = { }
133
- ) : PostgrestBuilder < T > {
133
+ ) : PostgrestFilterBuilder < T > {
134
134
this . method = 'POST'
135
135
this . headers [ 'Prefer' ] = upsert
136
136
? 'return=representation,resolution=merge-duplicates'
137
137
: 'return=representation'
138
138
if ( upsert && onConflict !== undefined ) this . url . searchParams . set ( 'on_conflict' , onConflict )
139
139
this . body = values
140
- return this
140
+ return new PostgrestFilterBuilder ( this )
141
141
}
142
142
143
143
/**
Original file line number Diff line number Diff line change @@ -169,3 +169,25 @@ Object {
169
169
" statusText" : " OK" ,
170
170
}
171
171
` ;
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 () => {
21
21
const res = await postgrest . from ( 'users' ) . select ( ) . limit ( 1 ) . single ( )
22
22
expect ( res ) . toMatchSnapshot ( )
23
23
} )
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