@@ -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.
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.
64
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
{
@@ -92,6 +110,41 @@ export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
92
110
return new PostgrestFilterBuilder ( this )
93
111
}
94
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
+
145
+ return new PostgrestFilterBuilder ( this )
146
+ }
147
+
95
148
/**
96
149
* Performs an UPDATE on the table.
97
150
*
0 commit comments