@supabase/postgrest-js 2.99.0 → 2.99.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -67,30 +67,784 @@ export default class PostgrestQueryBuilder<
67
67
  }
68
68
 
69
69
  /**
70
- * Perform a SELECT query on the table or view.
71
- *
72
- * @param columns - The columns to retrieve, separated by commas. Columns can be renamed when returned with `customName:columnName`
73
- *
74
- * @param options - Named parameters
75
- *
76
- * @param options.head - When set to `true`, `data` will not be returned.
77
- * Useful if you only need the count.
78
- *
79
- * @param options.count - Count algorithm to use to count rows in the table or view.
80
- *
81
- * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
82
- * hood.
83
- *
84
- * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
85
- * statistics under the hood.
86
- *
87
- * `"estimated"`: Uses exact count for low numbers and planned count for high
88
- * numbers.
89
- *
90
- * @remarks
91
- * When using `count` with `.range()` or `.limit()`, the returned `count` is the total number of rows
92
- * that match your filters, not the number of rows in the current page. Use this to build pagination UI.
93
- */
70
+ * Perform a SELECT query on the table or view.
71
+ *
72
+ * @param columns - The columns to retrieve, separated by commas. Columns can be renamed when returned with `customName:columnName`
73
+ *
74
+ * @param options - Named parameters
75
+ *
76
+ * @param options.head - When set to `true`, `data` will not be returned.
77
+ * Useful if you only need the count.
78
+ *
79
+ * @param options.count - Count algorithm to use to count rows in the table or view.
80
+ *
81
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
82
+ * hood.
83
+ *
84
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
85
+ * statistics under the hood.
86
+ *
87
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
88
+ * numbers.
89
+ *
90
+ * @remarks
91
+ * When using `count` with `.range()` or `.limit()`, the returned `count` is the total number of rows
92
+ * that match your filters, not the number of rows in the current page. Use this to build pagination UI.
93
+
94
+ * - By default, Supabase projects return a maximum of 1,000 rows. This setting can be changed in your project's [API settings](/dashboard/project/_/settings/api). It's recommended that you keep it low to limit the payload size of accidental or malicious requests. You can use `range()` queries to paginate through your data.
95
+ * - `select()` can be combined with [Filters](/docs/reference/javascript/using-filters)
96
+ * - `select()` can be combined with [Modifiers](/docs/reference/javascript/using-modifiers)
97
+ * - `apikey` is a reserved keyword if you're using the [Supabase Platform](/docs/guides/platform) and [should be avoided as a column name](https://github.com/supabase/supabase/issues/5465). *
98
+ * @category Database
99
+ *
100
+ * @example Getting your data
101
+ * ```js
102
+ * const { data, error } = await supabase
103
+ * .from('characters')
104
+ * .select()
105
+ * ```
106
+ *
107
+ * @exampleSql Getting your data
108
+ * ```sql
109
+ * create table
110
+ * characters (id int8 primary key, name text);
111
+ *
112
+ * insert into
113
+ * characters (id, name)
114
+ * values
115
+ * (1, 'Harry'),
116
+ * (2, 'Frodo'),
117
+ * (3, 'Katniss');
118
+ * ```
119
+ *
120
+ * @exampleResponse Getting your data
121
+ * ```json
122
+ * {
123
+ * "data": [
124
+ * {
125
+ * "id": 1,
126
+ * "name": "Harry"
127
+ * },
128
+ * {
129
+ * "id": 2,
130
+ * "name": "Frodo"
131
+ * },
132
+ * {
133
+ * "id": 3,
134
+ * "name": "Katniss"
135
+ * }
136
+ * ],
137
+ * "status": 200,
138
+ * "statusText": "OK"
139
+ * }
140
+ * ```
141
+ *
142
+ * @example Selecting specific columns
143
+ * ```js
144
+ * const { data, error } = await supabase
145
+ * .from('characters')
146
+ * .select('name')
147
+ * ```
148
+ *
149
+ * @exampleSql Selecting specific columns
150
+ * ```sql
151
+ * create table
152
+ * characters (id int8 primary key, name text);
153
+ *
154
+ * insert into
155
+ * characters (id, name)
156
+ * values
157
+ * (1, 'Frodo'),
158
+ * (2, 'Harry'),
159
+ * (3, 'Katniss');
160
+ * ```
161
+ *
162
+ * @exampleResponse Selecting specific columns
163
+ * ```json
164
+ * {
165
+ * "data": [
166
+ * {
167
+ * "name": "Frodo"
168
+ * },
169
+ * {
170
+ * "name": "Harry"
171
+ * },
172
+ * {
173
+ * "name": "Katniss"
174
+ * }
175
+ * ],
176
+ * "status": 200,
177
+ * "statusText": "OK"
178
+ * }
179
+ * ```
180
+ *
181
+ * @exampleDescription Query referenced tables
182
+ * If your database has foreign key relationships, you can query related tables too.
183
+ *
184
+ * @example Query referenced tables
185
+ * ```js
186
+ * const { data, error } = await supabase
187
+ * .from('orchestral_sections')
188
+ * .select(`
189
+ * name,
190
+ * instruments (
191
+ * name
192
+ * )
193
+ * `)
194
+ * ```
195
+ *
196
+ * @exampleSql Query referenced tables
197
+ * ```sql
198
+ * create table
199
+ * orchestral_sections (id int8 primary key, name text);
200
+ * create table
201
+ * instruments (
202
+ * id int8 primary key,
203
+ * section_id int8 not null references orchestral_sections,
204
+ * name text
205
+ * );
206
+ *
207
+ * insert into
208
+ * orchestral_sections (id, name)
209
+ * values
210
+ * (1, 'strings'),
211
+ * (2, 'woodwinds');
212
+ * insert into
213
+ * instruments (id, section_id, name)
214
+ * values
215
+ * (1, 2, 'flute'),
216
+ * (2, 1, 'violin');
217
+ * ```
218
+ *
219
+ * @exampleResponse Query referenced tables
220
+ * ```json
221
+ * {
222
+ * "data": [
223
+ * {
224
+ * "name": "strings",
225
+ * "instruments": [
226
+ * {
227
+ * "name": "violin"
228
+ * }
229
+ * ]
230
+ * },
231
+ * {
232
+ * "name": "woodwinds",
233
+ * "instruments": [
234
+ * {
235
+ * "name": "flute"
236
+ * }
237
+ * ]
238
+ * }
239
+ * ],
240
+ * "status": 200,
241
+ * "statusText": "OK"
242
+ * }
243
+ * ```
244
+ *
245
+ * @exampleDescription Query referenced tables with spaces in their names
246
+ * If your table name contains spaces, you must use double quotes in the `select` statement to reference the table.
247
+ *
248
+ * @example Query referenced tables with spaces in their names
249
+ * ```js
250
+ * const { data, error } = await supabase
251
+ * .from('orchestral sections')
252
+ * .select(`
253
+ * name,
254
+ * "musical instruments" (
255
+ * name
256
+ * )
257
+ * `)
258
+ * ```
259
+ *
260
+ * @exampleSql Query referenced tables with spaces in their names
261
+ * ```sql
262
+ * create table
263
+ * "orchestral sections" (id int8 primary key, name text);
264
+ * create table
265
+ * "musical instruments" (
266
+ * id int8 primary key,
267
+ * section_id int8 not null references "orchestral sections",
268
+ * name text
269
+ * );
270
+ *
271
+ * insert into
272
+ * "orchestral sections" (id, name)
273
+ * values
274
+ * (1, 'strings'),
275
+ * (2, 'woodwinds');
276
+ * insert into
277
+ * "musical instruments" (id, section_id, name)
278
+ * values
279
+ * (1, 2, 'flute'),
280
+ * (2, 1, 'violin');
281
+ * ```
282
+ *
283
+ * @exampleResponse Query referenced tables with spaces in their names
284
+ * ```json
285
+ * {
286
+ * "data": [
287
+ * {
288
+ * "name": "strings",
289
+ * "musical instruments": [
290
+ * {
291
+ * "name": "violin"
292
+ * }
293
+ * ]
294
+ * },
295
+ * {
296
+ * "name": "woodwinds",
297
+ * "musical instruments": [
298
+ * {
299
+ * "name": "flute"
300
+ * }
301
+ * ]
302
+ * }
303
+ * ],
304
+ * "status": 200,
305
+ * "statusText": "OK"
306
+ * }
307
+ * ```
308
+ *
309
+ * @exampleDescription Query referenced tables through a join table
310
+ * If you're in a situation where your tables are **NOT** directly
311
+ * related, but instead are joined by a _join table_, you can still use
312
+ * the `select()` method to query the related data. The join table needs
313
+ * to have the foreign keys as part of its composite primary key.
314
+ *
315
+ * @example Query referenced tables through a join table
316
+ * ```ts
317
+ * const { data, error } = await supabase
318
+ * .from('users')
319
+ * .select(`
320
+ * name,
321
+ * teams (
322
+ * name
323
+ * )
324
+ * `)
325
+ *
326
+ * ```
327
+ *
328
+ * @exampleSql Query referenced tables through a join table
329
+ * ```sql
330
+ * create table
331
+ * users (
332
+ * id int8 primary key,
333
+ * name text
334
+ * );
335
+ * create table
336
+ * teams (
337
+ * id int8 primary key,
338
+ * name text
339
+ * );
340
+ * -- join table
341
+ * create table
342
+ * users_teams (
343
+ * user_id int8 not null references users,
344
+ * team_id int8 not null references teams,
345
+ * -- both foreign keys must be part of a composite primary key
346
+ * primary key (user_id, team_id)
347
+ * );
348
+ *
349
+ * insert into
350
+ * users (id, name)
351
+ * values
352
+ * (1, 'Kiran'),
353
+ * (2, 'Evan');
354
+ * insert into
355
+ * teams (id, name)
356
+ * values
357
+ * (1, 'Green'),
358
+ * (2, 'Blue');
359
+ * insert into
360
+ * users_teams (user_id, team_id)
361
+ * values
362
+ * (1, 1),
363
+ * (1, 2),
364
+ * (2, 2);
365
+ * ```
366
+ *
367
+ * @exampleResponse Query referenced tables through a join table
368
+ * ```json
369
+ * {
370
+ * "data": [
371
+ * {
372
+ * "name": "Kiran",
373
+ * "teams": [
374
+ * {
375
+ * "name": "Green"
376
+ * },
377
+ * {
378
+ * "name": "Blue"
379
+ * }
380
+ * ]
381
+ * },
382
+ * {
383
+ * "name": "Evan",
384
+ * "teams": [
385
+ * {
386
+ * "name": "Blue"
387
+ * }
388
+ * ]
389
+ * }
390
+ * ],
391
+ * "status": 200,
392
+ * "statusText": "OK"
393
+ * }
394
+ *
395
+ * ```
396
+ *
397
+ * @exampleDescription Query the same referenced table multiple times
398
+ * If you need to query the same referenced table twice, use the name of the
399
+ * joined column to identify which join to use. You can also give each
400
+ * column an alias.
401
+ *
402
+ * @example Query the same referenced table multiple times
403
+ * ```ts
404
+ * const { data, error } = await supabase
405
+ * .from('messages')
406
+ * .select(`
407
+ * content,
408
+ * from:sender_id(name),
409
+ * to:receiver_id(name)
410
+ * `)
411
+ *
412
+ * // To infer types, use the name of the table (in this case `users`) and
413
+ * // the name of the foreign key constraint.
414
+ * const { data, error } = await supabase
415
+ * .from('messages')
416
+ * .select(`
417
+ * content,
418
+ * from:users!messages_sender_id_fkey(name),
419
+ * to:users!messages_receiver_id_fkey(name)
420
+ * `)
421
+ * ```
422
+ *
423
+ * @exampleSql Query the same referenced table multiple times
424
+ * ```sql
425
+ * create table
426
+ * users (id int8 primary key, name text);
427
+ *
428
+ * create table
429
+ * messages (
430
+ * sender_id int8 not null references users,
431
+ * receiver_id int8 not null references users,
432
+ * content text
433
+ * );
434
+ *
435
+ * insert into
436
+ * users (id, name)
437
+ * values
438
+ * (1, 'Kiran'),
439
+ * (2, 'Evan');
440
+ *
441
+ * insert into
442
+ * messages (sender_id, receiver_id, content)
443
+ * values
444
+ * (1, 2, '👋');
445
+ * ```
446
+ * ```
447
+ *
448
+ * @exampleResponse Query the same referenced table multiple times
449
+ * ```json
450
+ * {
451
+ * "data": [
452
+ * {
453
+ * "content": "👋",
454
+ * "from": {
455
+ * "name": "Kiran"
456
+ * },
457
+ * "to": {
458
+ * "name": "Evan"
459
+ * }
460
+ * }
461
+ * ],
462
+ * "status": 200,
463
+ * "statusText": "OK"
464
+ * }
465
+ * ```
466
+ *
467
+ * @exampleDescription Query nested foreign tables through a join table
468
+ * You can use the result of a joined table to gather data in
469
+ * another foreign table. With multiple references to the same foreign
470
+ * table you must specify the column on which to conduct the join.
471
+ *
472
+ * @example Query nested foreign tables through a join table
473
+ * ```ts
474
+ * const { data, error } = await supabase
475
+ * .from('games')
476
+ * .select(`
477
+ * game_id:id,
478
+ * away_team:teams!games_away_team_fkey (
479
+ * users (
480
+ * id,
481
+ * name
482
+ * )
483
+ * )
484
+ * `)
485
+ *
486
+ * ```
487
+ *
488
+ * @exampleSql Query nested foreign tables through a join table
489
+ * ```sql
490
+ * ```sql
491
+ * create table
492
+ * users (
493
+ * id int8 primary key,
494
+ * name text
495
+ * );
496
+ * create table
497
+ * teams (
498
+ * id int8 primary key,
499
+ * name text
500
+ * );
501
+ * -- join table
502
+ * create table
503
+ * users_teams (
504
+ * user_id int8 not null references users,
505
+ * team_id int8 not null references teams,
506
+ *
507
+ * primary key (user_id, team_id)
508
+ * );
509
+ * create table
510
+ * games (
511
+ * id int8 primary key,
512
+ * home_team int8 not null references teams,
513
+ * away_team int8 not null references teams,
514
+ * name text
515
+ * );
516
+ *
517
+ * insert into users (id, name)
518
+ * values
519
+ * (1, 'Kiran'),
520
+ * (2, 'Evan');
521
+ * insert into
522
+ * teams (id, name)
523
+ * values
524
+ * (1, 'Green'),
525
+ * (2, 'Blue');
526
+ * insert into
527
+ * users_teams (user_id, team_id)
528
+ * values
529
+ * (1, 1),
530
+ * (1, 2),
531
+ * (2, 2);
532
+ * insert into
533
+ * games (id, home_team, away_team, name)
534
+ * values
535
+ * (1, 1, 2, 'Green vs Blue'),
536
+ * (2, 2, 1, 'Blue vs Green');
537
+ * ```
538
+ *
539
+ * @exampleResponse Query nested foreign tables through a join table
540
+ * ```json
541
+ * {
542
+ * "data": [
543
+ * {
544
+ * "game_id": 1,
545
+ * "away_team": {
546
+ * "users": [
547
+ * {
548
+ * "id": 1,
549
+ * "name": "Kiran"
550
+ * },
551
+ * {
552
+ * "id": 2,
553
+ * "name": "Evan"
554
+ * }
555
+ * ]
556
+ * }
557
+ * },
558
+ * {
559
+ * "game_id": 2,
560
+ * "away_team": {
561
+ * "users": [
562
+ * {
563
+ * "id": 1,
564
+ * "name": "Kiran"
565
+ * }
566
+ * ]
567
+ * }
568
+ * }
569
+ * ],
570
+ * "status": 200,
571
+ * "statusText": "OK"
572
+ * }
573
+ *
574
+ * ```
575
+ *
576
+ * @exampleDescription Filtering through referenced tables
577
+ * If the filter on a referenced table's column is not satisfied, the referenced
578
+ * table returns `[]` or `null` but the parent table is not filtered out.
579
+ * If you want to filter out the parent table rows, use the `!inner` hint
580
+ *
581
+ * @example Filtering through referenced tables
582
+ * ```ts
583
+ * const { data, error } = await supabase
584
+ * .from('instruments')
585
+ * .select('name, orchestral_sections(*)')
586
+ * .eq('orchestral_sections.name', 'percussion')
587
+ * ```
588
+ *
589
+ * @exampleSql Filtering through referenced tables
590
+ * ```sql
591
+ * create table
592
+ * orchestral_sections (id int8 primary key, name text);
593
+ * create table
594
+ * instruments (
595
+ * id int8 primary key,
596
+ * section_id int8 not null references orchestral_sections,
597
+ * name text
598
+ * );
599
+ *
600
+ * insert into
601
+ * orchestral_sections (id, name)
602
+ * values
603
+ * (1, 'strings'),
604
+ * (2, 'woodwinds');
605
+ * insert into
606
+ * instruments (id, section_id, name)
607
+ * values
608
+ * (1, 2, 'flute'),
609
+ * (2, 1, 'violin');
610
+ * ```
611
+ *
612
+ * @exampleResponse Filtering through referenced tables
613
+ * ```json
614
+ * {
615
+ * "data": [
616
+ * {
617
+ * "name": "flute",
618
+ * "orchestral_sections": null
619
+ * },
620
+ * {
621
+ * "name": "violin",
622
+ * "orchestral_sections": null
623
+ * }
624
+ * ],
625
+ * "status": 200,
626
+ * "statusText": "OK"
627
+ * }
628
+ * ```
629
+ *
630
+ * @exampleDescription Querying referenced table with count
631
+ * You can get the number of rows in a related table by using the
632
+ * **count** property.
633
+ *
634
+ * @example Querying referenced table with count
635
+ * ```ts
636
+ * const { data, error } = await supabase
637
+ * .from('orchestral_sections')
638
+ * .select(`*, instruments(count)`)
639
+ * ```
640
+ *
641
+ * @exampleSql Querying referenced table with count
642
+ * ```sql
643
+ * create table orchestral_sections (
644
+ * "id" "uuid" primary key default "extensions"."uuid_generate_v4"() not null,
645
+ * "name" text
646
+ * );
647
+ *
648
+ * create table characters (
649
+ * "id" "uuid" primary key default "extensions"."uuid_generate_v4"() not null,
650
+ * "name" text,
651
+ * "section_id" "uuid" references public.orchestral_sections on delete cascade
652
+ * );
653
+ *
654
+ * with section as (
655
+ * insert into orchestral_sections (name)
656
+ * values ('strings') returning id
657
+ * )
658
+ * insert into instruments (name, section_id) values
659
+ * ('violin', (select id from section)),
660
+ * ('viola', (select id from section)),
661
+ * ('cello', (select id from section)),
662
+ * ('double bass', (select id from section));
663
+ * ```
664
+ *
665
+ * @exampleResponse Querying referenced table with count
666
+ * ```json
667
+ * [
668
+ * {
669
+ * "id": "693694e7-d993-4360-a6d7-6294e325d9b6",
670
+ * "name": "strings",
671
+ * "instruments": [
672
+ * {
673
+ * "count": 4
674
+ * }
675
+ * ]
676
+ * }
677
+ * ]
678
+ * ```
679
+ *
680
+ * @exampleDescription Querying with count option
681
+ * You can get the number of rows by using the
682
+ * [count](/docs/reference/javascript/select#parameters) option.
683
+ *
684
+ * @example Querying with count option
685
+ * ```ts
686
+ * const { count, error } = await supabase
687
+ * .from('characters')
688
+ * .select('*', { count: 'exact', head: true })
689
+ * ```
690
+ *
691
+ * @exampleSql Querying with count option
692
+ * ```sql
693
+ * create table
694
+ * characters (id int8 primary key, name text);
695
+ *
696
+ * insert into
697
+ * characters (id, name)
698
+ * values
699
+ * (1, 'Luke'),
700
+ * (2, 'Leia'),
701
+ * (3, 'Han');
702
+ * ```
703
+ *
704
+ * @exampleResponse Querying with count option
705
+ * ```json
706
+ * {
707
+ * "count": 3,
708
+ * "status": 200,
709
+ * "statusText": "OK"
710
+ * }
711
+ * ```
712
+ *
713
+ * @exampleDescription Querying JSON data
714
+ * You can select and filter data inside of
715
+ * [JSON](/docs/guides/database/json) columns. Postgres offers some
716
+ * [operators](/docs/guides/database/json#query-the-jsonb-data) for
717
+ * querying JSON data.
718
+ *
719
+ * @example Querying JSON data
720
+ * ```ts
721
+ * const { data, error } = await supabase
722
+ * .from('users')
723
+ * .select(`
724
+ * id, name,
725
+ * address->city
726
+ * `)
727
+ * ```
728
+ *
729
+ * @exampleSql Querying JSON data
730
+ * ```sql
731
+ * create table
732
+ * users (
733
+ * id int8 primary key,
734
+ * name text,
735
+ * address jsonb
736
+ * );
737
+ *
738
+ * insert into
739
+ * users (id, name, address)
740
+ * values
741
+ * (1, 'Frodo', '{"city":"Hobbiton"}');
742
+ * ```
743
+ *
744
+ * @exampleResponse Querying JSON data
745
+ * ```json
746
+ * {
747
+ * "data": [
748
+ * {
749
+ * "id": 1,
750
+ * "name": "Frodo",
751
+ * "city": "Hobbiton"
752
+ * }
753
+ * ],
754
+ * "status": 200,
755
+ * "statusText": "OK"
756
+ * }
757
+ * ```
758
+ *
759
+ * @exampleDescription Querying referenced table with inner join
760
+ * If you don't want to return the referenced table contents, you can leave the parenthesis empty.
761
+ * Like `.select('name, orchestral_sections!inner()')`.
762
+ *
763
+ * @example Querying referenced table with inner join
764
+ * ```ts
765
+ * const { data, error } = await supabase
766
+ * .from('instruments')
767
+ * .select('name, orchestral_sections!inner(name)')
768
+ * .eq('orchestral_sections.name', 'woodwinds')
769
+ * .limit(1)
770
+ * ```
771
+ *
772
+ * @exampleSql Querying referenced table with inner join
773
+ * ```sql
774
+ * create table orchestral_sections (
775
+ * "id" "uuid" primary key default "extensions"."uuid_generate_v4"() not null,
776
+ * "name" text
777
+ * );
778
+ *
779
+ * create table instruments (
780
+ * "id" "uuid" primary key default "extensions"."uuid_generate_v4"() not null,
781
+ * "name" text,
782
+ * "section_id" "uuid" references public.orchestral_sections on delete cascade
783
+ * );
784
+ *
785
+ * with section as (
786
+ * insert into orchestral_sections (name)
787
+ * values ('woodwinds') returning id
788
+ * )
789
+ * insert into instruments (name, section_id) values
790
+ * ('flute', (select id from section)),
791
+ * ('clarinet', (select id from section)),
792
+ * ('bassoon', (select id from section)),
793
+ * ('piccolo', (select id from section));
794
+ * ```
795
+ *
796
+ * @exampleResponse Querying referenced table with inner join
797
+ * ```json
798
+ * {
799
+ * "data": [
800
+ * {
801
+ * "name": "flute",
802
+ * "orchestral_sections": {"name": "woodwinds"}
803
+ * }
804
+ * ],
805
+ * "status": 200,
806
+ * "statusText": "OK"
807
+ * }
808
+ * ```
809
+ *
810
+ * @exampleDescription Switching schemas per query
811
+ * In addition to setting the schema during initialization, you can also switch schemas on a per-query basis.
812
+ * Make sure you've set up your [database privileges and API settings](/docs/guides/api/using-custom-schemas).
813
+ *
814
+ * @example Switching schemas per query
815
+ * ```ts
816
+ * const { data, error } = await supabase
817
+ * .schema('myschema')
818
+ * .from('mytable')
819
+ * .select()
820
+ * ```
821
+ *
822
+ * @exampleSql Switching schemas per query
823
+ * ```sql
824
+ * create schema myschema;
825
+ *
826
+ * create table myschema.mytable (
827
+ * id uuid primary key default gen_random_uuid(),
828
+ * data text
829
+ * );
830
+ *
831
+ * insert into myschema.mytable (data) values ('mydata');
832
+ * ```
833
+ *
834
+ * @exampleResponse Switching schemas per query
835
+ * ```json
836
+ * {
837
+ * "data": [
838
+ * {
839
+ * "id": "4162e008-27b0-4c0f-82dc-ccaeee9a624d",
840
+ * "data": "mydata"
841
+ * }
842
+ * ],
843
+ * "status": 200,
844
+ * "statusText": "OK"
845
+ * }
846
+ * ```
847
+ */
94
848
  select<
95
849
  Query extends string = '*',
96
850
  ResultOne = GetResult<
@@ -206,6 +960,91 @@ export default class PostgrestQueryBuilder<
206
960
  * @param options.defaultToNull - Make missing fields default to `null`.
207
961
  * Otherwise, use the default value for the column. Only applies for bulk
208
962
  * inserts.
963
+ *
964
+ * @category Database
965
+ *
966
+ * @example Create a record
967
+ * ```ts
968
+ * const { error } = await supabase
969
+ * .from('countries')
970
+ * .insert({ id: 1, name: 'Mordor' })
971
+ * ```
972
+ *
973
+ * @exampleSql Create a record
974
+ * ```sql
975
+ * create table
976
+ * countries (id int8 primary key, name text);
977
+ * ```
978
+ *
979
+ * @exampleResponse Create a record
980
+ * ```json
981
+ * {
982
+ * "status": 201,
983
+ * "statusText": "Created"
984
+ * }
985
+ * ```
986
+ *
987
+ * @example Create a record and return it
988
+ * ```ts
989
+ * const { data, error } = await supabase
990
+ * .from('countries')
991
+ * .insert({ id: 1, name: 'Mordor' })
992
+ * .select()
993
+ * ```
994
+ *
995
+ * @exampleSql Create a record and return it
996
+ * ```sql
997
+ * create table
998
+ * countries (id int8 primary key, name text);
999
+ * ```
1000
+ *
1001
+ * @exampleResponse Create a record and return it
1002
+ * ```json
1003
+ * {
1004
+ * "data": [
1005
+ * {
1006
+ * "id": 1,
1007
+ * "name": "Mordor"
1008
+ * }
1009
+ * ],
1010
+ * "status": 201,
1011
+ * "statusText": "Created"
1012
+ * }
1013
+ * ```
1014
+ *
1015
+ * @exampleDescription Bulk create
1016
+ * A bulk create operation is handled in a single transaction.
1017
+ * If any of the inserts fail, none of the rows are inserted.
1018
+ *
1019
+ * @example Bulk create
1020
+ * ```ts
1021
+ * const { error } = await supabase
1022
+ * .from('countries')
1023
+ * .insert([
1024
+ * { id: 1, name: 'Mordor' },
1025
+ * { id: 1, name: 'The Shire' },
1026
+ * ])
1027
+ * ```
1028
+ *
1029
+ * @exampleSql Bulk create
1030
+ * ```sql
1031
+ * create table
1032
+ * countries (id int8 primary key, name text);
1033
+ * ```
1034
+ *
1035
+ * @exampleResponse Bulk create
1036
+ * ```json
1037
+ * {
1038
+ * "error": {
1039
+ * "code": "23505",
1040
+ * "details": "Key (id)=(1) already exists.",
1041
+ * "hint": null,
1042
+ * "message": "duplicate key value violates unique constraint \"countries_pkey\""
1043
+ * },
1044
+ * "status": 409,
1045
+ * "statusText": "Conflict"
1046
+ * }
1047
+ * ```
209
1048
  */
210
1049
  insert<Row extends Relation extends { Insert: unknown } ? Relation['Insert'] : never>(
211
1050
  values: Row | Row[],
@@ -372,6 +1211,129 @@ export default class PostgrestQueryBuilder<
372
1211
  * // error: null
373
1212
  * // }
374
1213
  * ```
1214
+ *
1215
+ * @category Database
1216
+ *
1217
+ * @remarks
1218
+ * - Primary keys must be included in `values` to use upsert.
1219
+ *
1220
+ * @example Upsert your data
1221
+ * ```ts
1222
+ * const { data, error } = await supabase
1223
+ * .from('instruments')
1224
+ * .upsert({ id: 1, name: 'piano' })
1225
+ * .select()
1226
+ * ```
1227
+ *
1228
+ * @exampleSql Upsert your data
1229
+ * ```sql
1230
+ * create table
1231
+ * instruments (id int8 primary key, name text);
1232
+ *
1233
+ * insert into
1234
+ * instruments (id, name)
1235
+ * values
1236
+ * (1, 'harpsichord');
1237
+ * ```
1238
+ *
1239
+ * @exampleResponse Upsert your data
1240
+ * ```json
1241
+ * {
1242
+ * "data": [
1243
+ * {
1244
+ * "id": 1,
1245
+ * "name": "piano"
1246
+ * }
1247
+ * ],
1248
+ * "status": 201,
1249
+ * "statusText": "Created"
1250
+ * }
1251
+ * ```
1252
+ *
1253
+ * @example Bulk Upsert your data
1254
+ * ```ts
1255
+ * const { data, error } = await supabase
1256
+ * .from('instruments')
1257
+ * .upsert([
1258
+ * { id: 1, name: 'piano' },
1259
+ * { id: 2, name: 'harp' },
1260
+ * ])
1261
+ * .select()
1262
+ * ```
1263
+ *
1264
+ * @exampleSql Bulk Upsert your data
1265
+ * ```sql
1266
+ * create table
1267
+ * instruments (id int8 primary key, name text);
1268
+ *
1269
+ * insert into
1270
+ * instruments (id, name)
1271
+ * values
1272
+ * (1, 'harpsichord');
1273
+ * ```
1274
+ *
1275
+ * @exampleResponse Bulk Upsert your data
1276
+ * ```json
1277
+ * {
1278
+ * "data": [
1279
+ * {
1280
+ * "id": 1,
1281
+ * "name": "piano"
1282
+ * },
1283
+ * {
1284
+ * "id": 2,
1285
+ * "name": "harp"
1286
+ * }
1287
+ * ],
1288
+ * "status": 201,
1289
+ * "statusText": "Created"
1290
+ * }
1291
+ * ```
1292
+ *
1293
+ * @exampleDescription Upserting into tables with constraints
1294
+ * In the following query, `upsert()` implicitly uses the `id`
1295
+ * (primary key) column to determine conflicts. If there is no existing
1296
+ * row with the same `id`, `upsert()` inserts a new row, which
1297
+ * will fail in this case as there is already a row with `handle` `"saoirse"`.
1298
+ * Using the `onConflict` option, you can instruct `upsert()` to use
1299
+ * another column with a unique constraint to determine conflicts.
1300
+ *
1301
+ * @example Upserting into tables with constraints
1302
+ * ```ts
1303
+ * const { data, error } = await supabase
1304
+ * .from('users')
1305
+ * .upsert({ id: 42, handle: 'saoirse', display_name: 'Saoirse' })
1306
+ * .select()
1307
+ * ```
1308
+ *
1309
+ * @exampleSql Upserting into tables with constraints
1310
+ * ```sql
1311
+ * create table
1312
+ * users (
1313
+ * id int8 generated by default as identity primary key,
1314
+ * handle text not null unique,
1315
+ * display_name text
1316
+ * );
1317
+ *
1318
+ * insert into
1319
+ * users (id, handle, display_name)
1320
+ * values
1321
+ * (1, 'saoirse', null);
1322
+ * ```
1323
+ *
1324
+ * @exampleResponse Upserting into tables with constraints
1325
+ * ```json
1326
+ * {
1327
+ * "error": {
1328
+ * "code": "23505",
1329
+ * "details": "Key (handle)=(saoirse) already exists.",
1330
+ * "hint": null,
1331
+ * "message": "duplicate key value violates unique constraint \"users_handle_key\""
1332
+ * },
1333
+ * "status": 409,
1334
+ * "statusText": "Conflict"
1335
+ * }
1336
+ * ```
375
1337
  */
376
1338
 
377
1339
  upsert<Row extends Relation extends { Insert: unknown } ? Relation['Insert'] : never>(
@@ -448,6 +1410,124 @@ export default class PostgrestQueryBuilder<
448
1410
  *
449
1411
  * `"estimated"`: Uses exact count for low numbers and planned count for high
450
1412
  * numbers.
1413
+ *
1414
+ * @category Database
1415
+ *
1416
+ * @remarks
1417
+ * - `update()` should always be combined with [Filters](/docs/reference/javascript/using-filters) to target the item(s) you wish to update.
1418
+ *
1419
+ * @example Updating your data
1420
+ * ```ts
1421
+ * const { error } = await supabase
1422
+ * .from('instruments')
1423
+ * .update({ name: 'piano' })
1424
+ * .eq('id', 1)
1425
+ * ```
1426
+ *
1427
+ * @exampleSql Updating your data
1428
+ * ```sql
1429
+ * create table
1430
+ * instruments (id int8 primary key, name text);
1431
+ *
1432
+ * insert into
1433
+ * instruments (id, name)
1434
+ * values
1435
+ * (1, 'harpsichord');
1436
+ * ```
1437
+ *
1438
+ * @exampleResponse Updating your data
1439
+ * ```json
1440
+ * {
1441
+ * "status": 204,
1442
+ * "statusText": "No Content"
1443
+ * }
1444
+ * ```
1445
+ *
1446
+ * @example Update a record and return it
1447
+ * ```ts
1448
+ * const { data, error } = await supabase
1449
+ * .from('instruments')
1450
+ * .update({ name: 'piano' })
1451
+ * .eq('id', 1)
1452
+ * .select()
1453
+ * ```
1454
+ *
1455
+ * @exampleSql Update a record and return it
1456
+ * ```sql
1457
+ * create table
1458
+ * instruments (id int8 primary key, name text);
1459
+ *
1460
+ * insert into
1461
+ * instruments (id, name)
1462
+ * values
1463
+ * (1, 'harpsichord');
1464
+ * ```
1465
+ *
1466
+ * @exampleResponse Update a record and return it
1467
+ * ```json
1468
+ * {
1469
+ * "data": [
1470
+ * {
1471
+ * "id": 1,
1472
+ * "name": "piano"
1473
+ * }
1474
+ * ],
1475
+ * "status": 200,
1476
+ * "statusText": "OK"
1477
+ * }
1478
+ * ```
1479
+ *
1480
+ * @exampleDescription Updating JSON data
1481
+ * Postgres offers some
1482
+ * [operators](/docs/guides/database/json#query-the-jsonb-data) for
1483
+ * working with JSON data. Currently, it is only possible to update the entire JSON document.
1484
+ *
1485
+ * @example Updating JSON data
1486
+ * ```ts
1487
+ * const { data, error } = await supabase
1488
+ * .from('users')
1489
+ * .update({
1490
+ * address: {
1491
+ * street: 'Melrose Place',
1492
+ * postcode: 90210
1493
+ * }
1494
+ * })
1495
+ * .eq('address->postcode', 90210)
1496
+ * .select()
1497
+ * ```
1498
+ *
1499
+ * @exampleSql Updating JSON data
1500
+ * ```sql
1501
+ * create table
1502
+ * users (
1503
+ * id int8 primary key,
1504
+ * name text,
1505
+ * address jsonb
1506
+ * );
1507
+ *
1508
+ * insert into
1509
+ * users (id, name, address)
1510
+ * values
1511
+ * (1, 'Michael', '{ "postcode": 90210 }');
1512
+ * ```
1513
+ *
1514
+ * @exampleResponse Updating JSON data
1515
+ * ```json
1516
+ * {
1517
+ * "data": [
1518
+ * {
1519
+ * "id": 1,
1520
+ * "name": "Michael",
1521
+ * "address": {
1522
+ * "street": "Melrose Place",
1523
+ * "postcode": 90210
1524
+ * }
1525
+ * }
1526
+ * ],
1527
+ * "status": 200,
1528
+ * "statusText": "OK"
1529
+ * }
1530
+ * ```
451
1531
  */
452
1532
  update<Row extends Relation extends { Update: unknown } ? Relation['Update'] : never>(
453
1533
  values: Row,