@@ -58,10 +58,28 @@ export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
58
58
* Performs an INSERT into the table.
59
59
*
60
60
* @param values The values to insert.
61
- * @param upsert If `true`, performs an UPSERT.
62
- * @param onConflict By specifying the `on_conflict` query parameter, you can make UPSERT work on a column(s) that has a UNIQUE constraint.
63
61
* @param returning By default the new record is returned. Set this to 'minimal' if you don't need this value.
62
+ * @param count Count algorithm to use to count rows in a table.
64
63
*/
64
+ insert (
65
+ values : Partial < T > | Partial < T > [ ] ,
66
+ options ?: {
67
+ returning ?: 'minimal' | 'representation'
68
+ count ?: null | 'exact' | 'planned' | 'estimated'
69
+ }
70
+ ) : PostgrestFilterBuilder < T >
71
+ /**
72
+ * @deprecated Use `upsert()` instead.
73
+ */
74
+ insert (
75
+ values : Partial < T > | Partial < T > [ ] ,
76
+ options ?: {
77
+ upsert ?: boolean
78
+ onConflict ?: string
79
+ returning ?: 'minimal' | 'representation'
80
+ count ?: null | 'exact' | 'planned' | 'estimated'
81
+ }
82
+ ) : PostgrestFilterBuilder < T >
65
83
insert (
66
84
values : Partial < T > | Partial < T > [ ] ,
67
85
{
@@ -78,18 +96,52 @@ export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
78
96
) : PostgrestFilterBuilder < T > {
79
97
this . method = 'POST'
80
98
81
- let prefersHeaders = [ ]
82
- prefersHeaders . push ( `return=${ returning } ` )
99
+ const prefersHeaders = [ `return=${ returning } ` ]
83
100
if ( upsert ) prefersHeaders . push ( 'resolution=merge-duplicates' )
84
101
85
102
if ( upsert && onConflict !== undefined ) this . url . searchParams . set ( 'on_conflict' , onConflict )
86
103
this . body = values
87
104
if ( count ) {
88
105
prefersHeaders . push ( `count=${ count } ` )
89
106
}
90
-
107
+
91
108
this . headers [ 'Prefer' ] = prefersHeaders . join ( ',' )
92
-
109
+
110
+ return new PostgrestFilterBuilder ( this )
111
+ }
112
+
113
+ /**
114
+ * Performs an UPSERT into the table.
115
+ *
116
+ * @param values The values to insert.
117
+ * @param onConflict By specifying the `on_conflict` query parameter, you can make UPSERT work on a column(s) that has a UNIQUE constraint.
118
+ * @param returning By default the new record is returned. Set this to 'minimal' if you don't need this value.
119
+ * @param count Count algorithm to use to count rows in a table.
120
+ */
121
+ upsert (
122
+ values : Partial < T > | Partial < T > [ ] ,
123
+ {
124
+ onConflict,
125
+ returning = 'representation' ,
126
+ count = null ,
127
+ } : {
128
+ onConflict ?: string
129
+ returning ?: 'minimal' | 'representation'
130
+ count ?: null | 'exact' | 'planned' | 'estimated'
131
+ } = { }
132
+ ) : PostgrestFilterBuilder < T > {
133
+ this . method = 'POST'
134
+
135
+ const prefersHeaders = [ 'resolution=merge-duplicates' , `return=${ returning } ` ]
136
+
137
+ if ( onConflict !== undefined ) this . url . searchParams . set ( 'on_conflict' , onConflict )
138
+ this . body = values
139
+ if ( count ) {
140
+ prefersHeaders . push ( `count=${ count } ` )
141
+ }
142
+
143
+ this . headers [ 'Prefer' ] = prefersHeaders . join ( ',' )
144
+
93
145
return new PostgrestFilterBuilder ( this )
94
146
}
95
147
@@ -98,6 +150,7 @@ export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
98
150
*
99
151
* @param values The values to update.
100
152
* @param returning By default the updated record is returned. Set this to 'minimal' if you don't need this value.
153
+ * @param count Count algorithm to use to count rows in a table.
101
154
*/
102
155
update (
103
156
values : Partial < T > ,
@@ -110,8 +163,7 @@ export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
110
163
} = { }
111
164
) : PostgrestFilterBuilder < T > {
112
165
this . method = 'PATCH'
113
- let prefersHeaders = [ ]
114
- prefersHeaders . push ( `return=${ returning } ` )
166
+ const prefersHeaders = [ `return=${ returning } ` ]
115
167
this . body = values
116
168
if ( count ) {
117
169
prefersHeaders . push ( `count=${ count } ` )
@@ -124,6 +176,7 @@ export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
124
176
* Performs a DELETE on the table.
125
177
*
126
178
* @param returning If `true`, return the deleted row(s) in the response.
179
+ * @param count Count algorithm to use to count rows in a table.
127
180
*/
128
181
delete ( {
129
182
returning = 'representation' ,
@@ -133,8 +186,7 @@ export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
133
186
count ?: null | 'exact' | 'planned' | 'estimated'
134
187
} = { } ) : PostgrestFilterBuilder < T > {
135
188
this . method = 'DELETE'
136
- let prefersHeaders = [ ]
137
- prefersHeaders . push ( `return=${ returning } ` )
189
+ const prefersHeaders = [ `return=${ returning } ` ]
138
190
if ( count ) {
139
191
prefersHeaders . push ( `count=${ count } ` )
140
192
}
0 commit comments