@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.
package/dist/index.mjs CHANGED
@@ -875,6 +875,760 @@ var PostgrestQueryBuilder = class {
875
875
  * @remarks
876
876
  * When using `count` with `.range()` or `.limit()`, the returned `count` is the total number of rows
877
877
  * that match your filters, not the number of rows in the current page. Use this to build pagination UI.
878
+
879
+ * - 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.
880
+ * - `select()` can be combined with [Filters](/docs/reference/javascript/using-filters)
881
+ * - `select()` can be combined with [Modifiers](/docs/reference/javascript/using-modifiers)
882
+ * - `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). *
883
+ * @category Database
884
+ *
885
+ * @example Getting your data
886
+ * ```js
887
+ * const { data, error } = await supabase
888
+ * .from('characters')
889
+ * .select()
890
+ * ```
891
+ *
892
+ * @exampleSql Getting your data
893
+ * ```sql
894
+ * create table
895
+ * characters (id int8 primary key, name text);
896
+ *
897
+ * insert into
898
+ * characters (id, name)
899
+ * values
900
+ * (1, 'Harry'),
901
+ * (2, 'Frodo'),
902
+ * (3, 'Katniss');
903
+ * ```
904
+ *
905
+ * @exampleResponse Getting your data
906
+ * ```json
907
+ * {
908
+ * "data": [
909
+ * {
910
+ * "id": 1,
911
+ * "name": "Harry"
912
+ * },
913
+ * {
914
+ * "id": 2,
915
+ * "name": "Frodo"
916
+ * },
917
+ * {
918
+ * "id": 3,
919
+ * "name": "Katniss"
920
+ * }
921
+ * ],
922
+ * "status": 200,
923
+ * "statusText": "OK"
924
+ * }
925
+ * ```
926
+ *
927
+ * @example Selecting specific columns
928
+ * ```js
929
+ * const { data, error } = await supabase
930
+ * .from('characters')
931
+ * .select('name')
932
+ * ```
933
+ *
934
+ * @exampleSql Selecting specific columns
935
+ * ```sql
936
+ * create table
937
+ * characters (id int8 primary key, name text);
938
+ *
939
+ * insert into
940
+ * characters (id, name)
941
+ * values
942
+ * (1, 'Frodo'),
943
+ * (2, 'Harry'),
944
+ * (3, 'Katniss');
945
+ * ```
946
+ *
947
+ * @exampleResponse Selecting specific columns
948
+ * ```json
949
+ * {
950
+ * "data": [
951
+ * {
952
+ * "name": "Frodo"
953
+ * },
954
+ * {
955
+ * "name": "Harry"
956
+ * },
957
+ * {
958
+ * "name": "Katniss"
959
+ * }
960
+ * ],
961
+ * "status": 200,
962
+ * "statusText": "OK"
963
+ * }
964
+ * ```
965
+ *
966
+ * @exampleDescription Query referenced tables
967
+ * If your database has foreign key relationships, you can query related tables too.
968
+ *
969
+ * @example Query referenced tables
970
+ * ```js
971
+ * const { data, error } = await supabase
972
+ * .from('orchestral_sections')
973
+ * .select(`
974
+ * name,
975
+ * instruments (
976
+ * name
977
+ * )
978
+ * `)
979
+ * ```
980
+ *
981
+ * @exampleSql Query referenced tables
982
+ * ```sql
983
+ * create table
984
+ * orchestral_sections (id int8 primary key, name text);
985
+ * create table
986
+ * instruments (
987
+ * id int8 primary key,
988
+ * section_id int8 not null references orchestral_sections,
989
+ * name text
990
+ * );
991
+ *
992
+ * insert into
993
+ * orchestral_sections (id, name)
994
+ * values
995
+ * (1, 'strings'),
996
+ * (2, 'woodwinds');
997
+ * insert into
998
+ * instruments (id, section_id, name)
999
+ * values
1000
+ * (1, 2, 'flute'),
1001
+ * (2, 1, 'violin');
1002
+ * ```
1003
+ *
1004
+ * @exampleResponse Query referenced tables
1005
+ * ```json
1006
+ * {
1007
+ * "data": [
1008
+ * {
1009
+ * "name": "strings",
1010
+ * "instruments": [
1011
+ * {
1012
+ * "name": "violin"
1013
+ * }
1014
+ * ]
1015
+ * },
1016
+ * {
1017
+ * "name": "woodwinds",
1018
+ * "instruments": [
1019
+ * {
1020
+ * "name": "flute"
1021
+ * }
1022
+ * ]
1023
+ * }
1024
+ * ],
1025
+ * "status": 200,
1026
+ * "statusText": "OK"
1027
+ * }
1028
+ * ```
1029
+ *
1030
+ * @exampleDescription Query referenced tables with spaces in their names
1031
+ * If your table name contains spaces, you must use double quotes in the `select` statement to reference the table.
1032
+ *
1033
+ * @example Query referenced tables with spaces in their names
1034
+ * ```js
1035
+ * const { data, error } = await supabase
1036
+ * .from('orchestral sections')
1037
+ * .select(`
1038
+ * name,
1039
+ * "musical instruments" (
1040
+ * name
1041
+ * )
1042
+ * `)
1043
+ * ```
1044
+ *
1045
+ * @exampleSql Query referenced tables with spaces in their names
1046
+ * ```sql
1047
+ * create table
1048
+ * "orchestral sections" (id int8 primary key, name text);
1049
+ * create table
1050
+ * "musical instruments" (
1051
+ * id int8 primary key,
1052
+ * section_id int8 not null references "orchestral sections",
1053
+ * name text
1054
+ * );
1055
+ *
1056
+ * insert into
1057
+ * "orchestral sections" (id, name)
1058
+ * values
1059
+ * (1, 'strings'),
1060
+ * (2, 'woodwinds');
1061
+ * insert into
1062
+ * "musical instruments" (id, section_id, name)
1063
+ * values
1064
+ * (1, 2, 'flute'),
1065
+ * (2, 1, 'violin');
1066
+ * ```
1067
+ *
1068
+ * @exampleResponse Query referenced tables with spaces in their names
1069
+ * ```json
1070
+ * {
1071
+ * "data": [
1072
+ * {
1073
+ * "name": "strings",
1074
+ * "musical instruments": [
1075
+ * {
1076
+ * "name": "violin"
1077
+ * }
1078
+ * ]
1079
+ * },
1080
+ * {
1081
+ * "name": "woodwinds",
1082
+ * "musical instruments": [
1083
+ * {
1084
+ * "name": "flute"
1085
+ * }
1086
+ * ]
1087
+ * }
1088
+ * ],
1089
+ * "status": 200,
1090
+ * "statusText": "OK"
1091
+ * }
1092
+ * ```
1093
+ *
1094
+ * @exampleDescription Query referenced tables through a join table
1095
+ * If you're in a situation where your tables are **NOT** directly
1096
+ * related, but instead are joined by a _join table_, you can still use
1097
+ * the `select()` method to query the related data. The join table needs
1098
+ * to have the foreign keys as part of its composite primary key.
1099
+ *
1100
+ * @example Query referenced tables through a join table
1101
+ * ```ts
1102
+ * const { data, error } = await supabase
1103
+ * .from('users')
1104
+ * .select(`
1105
+ * name,
1106
+ * teams (
1107
+ * name
1108
+ * )
1109
+ * `)
1110
+ *
1111
+ * ```
1112
+ *
1113
+ * @exampleSql Query referenced tables through a join table
1114
+ * ```sql
1115
+ * create table
1116
+ * users (
1117
+ * id int8 primary key,
1118
+ * name text
1119
+ * );
1120
+ * create table
1121
+ * teams (
1122
+ * id int8 primary key,
1123
+ * name text
1124
+ * );
1125
+ * -- join table
1126
+ * create table
1127
+ * users_teams (
1128
+ * user_id int8 not null references users,
1129
+ * team_id int8 not null references teams,
1130
+ * -- both foreign keys must be part of a composite primary key
1131
+ * primary key (user_id, team_id)
1132
+ * );
1133
+ *
1134
+ * insert into
1135
+ * users (id, name)
1136
+ * values
1137
+ * (1, 'Kiran'),
1138
+ * (2, 'Evan');
1139
+ * insert into
1140
+ * teams (id, name)
1141
+ * values
1142
+ * (1, 'Green'),
1143
+ * (2, 'Blue');
1144
+ * insert into
1145
+ * users_teams (user_id, team_id)
1146
+ * values
1147
+ * (1, 1),
1148
+ * (1, 2),
1149
+ * (2, 2);
1150
+ * ```
1151
+ *
1152
+ * @exampleResponse Query referenced tables through a join table
1153
+ * ```json
1154
+ * {
1155
+ * "data": [
1156
+ * {
1157
+ * "name": "Kiran",
1158
+ * "teams": [
1159
+ * {
1160
+ * "name": "Green"
1161
+ * },
1162
+ * {
1163
+ * "name": "Blue"
1164
+ * }
1165
+ * ]
1166
+ * },
1167
+ * {
1168
+ * "name": "Evan",
1169
+ * "teams": [
1170
+ * {
1171
+ * "name": "Blue"
1172
+ * }
1173
+ * ]
1174
+ * }
1175
+ * ],
1176
+ * "status": 200,
1177
+ * "statusText": "OK"
1178
+ * }
1179
+ *
1180
+ * ```
1181
+ *
1182
+ * @exampleDescription Query the same referenced table multiple times
1183
+ * If you need to query the same referenced table twice, use the name of the
1184
+ * joined column to identify which join to use. You can also give each
1185
+ * column an alias.
1186
+ *
1187
+ * @example Query the same referenced table multiple times
1188
+ * ```ts
1189
+ * const { data, error } = await supabase
1190
+ * .from('messages')
1191
+ * .select(`
1192
+ * content,
1193
+ * from:sender_id(name),
1194
+ * to:receiver_id(name)
1195
+ * `)
1196
+ *
1197
+ * // To infer types, use the name of the table (in this case `users`) and
1198
+ * // the name of the foreign key constraint.
1199
+ * const { data, error } = await supabase
1200
+ * .from('messages')
1201
+ * .select(`
1202
+ * content,
1203
+ * from:users!messages_sender_id_fkey(name),
1204
+ * to:users!messages_receiver_id_fkey(name)
1205
+ * `)
1206
+ * ```
1207
+ *
1208
+ * @exampleSql Query the same referenced table multiple times
1209
+ * ```sql
1210
+ * create table
1211
+ * users (id int8 primary key, name text);
1212
+ *
1213
+ * create table
1214
+ * messages (
1215
+ * sender_id int8 not null references users,
1216
+ * receiver_id int8 not null references users,
1217
+ * content text
1218
+ * );
1219
+ *
1220
+ * insert into
1221
+ * users (id, name)
1222
+ * values
1223
+ * (1, 'Kiran'),
1224
+ * (2, 'Evan');
1225
+ *
1226
+ * insert into
1227
+ * messages (sender_id, receiver_id, content)
1228
+ * values
1229
+ * (1, 2, '👋');
1230
+ * ```
1231
+ * ```
1232
+ *
1233
+ * @exampleResponse Query the same referenced table multiple times
1234
+ * ```json
1235
+ * {
1236
+ * "data": [
1237
+ * {
1238
+ * "content": "👋",
1239
+ * "from": {
1240
+ * "name": "Kiran"
1241
+ * },
1242
+ * "to": {
1243
+ * "name": "Evan"
1244
+ * }
1245
+ * }
1246
+ * ],
1247
+ * "status": 200,
1248
+ * "statusText": "OK"
1249
+ * }
1250
+ * ```
1251
+ *
1252
+ * @exampleDescription Query nested foreign tables through a join table
1253
+ * You can use the result of a joined table to gather data in
1254
+ * another foreign table. With multiple references to the same foreign
1255
+ * table you must specify the column on which to conduct the join.
1256
+ *
1257
+ * @example Query nested foreign tables through a join table
1258
+ * ```ts
1259
+ * const { data, error } = await supabase
1260
+ * .from('games')
1261
+ * .select(`
1262
+ * game_id:id,
1263
+ * away_team:teams!games_away_team_fkey (
1264
+ * users (
1265
+ * id,
1266
+ * name
1267
+ * )
1268
+ * )
1269
+ * `)
1270
+ *
1271
+ * ```
1272
+ *
1273
+ * @exampleSql Query nested foreign tables through a join table
1274
+ * ```sql
1275
+ * ```sql
1276
+ * create table
1277
+ * users (
1278
+ * id int8 primary key,
1279
+ * name text
1280
+ * );
1281
+ * create table
1282
+ * teams (
1283
+ * id int8 primary key,
1284
+ * name text
1285
+ * );
1286
+ * -- join table
1287
+ * create table
1288
+ * users_teams (
1289
+ * user_id int8 not null references users,
1290
+ * team_id int8 not null references teams,
1291
+ *
1292
+ * primary key (user_id, team_id)
1293
+ * );
1294
+ * create table
1295
+ * games (
1296
+ * id int8 primary key,
1297
+ * home_team int8 not null references teams,
1298
+ * away_team int8 not null references teams,
1299
+ * name text
1300
+ * );
1301
+ *
1302
+ * insert into users (id, name)
1303
+ * values
1304
+ * (1, 'Kiran'),
1305
+ * (2, 'Evan');
1306
+ * insert into
1307
+ * teams (id, name)
1308
+ * values
1309
+ * (1, 'Green'),
1310
+ * (2, 'Blue');
1311
+ * insert into
1312
+ * users_teams (user_id, team_id)
1313
+ * values
1314
+ * (1, 1),
1315
+ * (1, 2),
1316
+ * (2, 2);
1317
+ * insert into
1318
+ * games (id, home_team, away_team, name)
1319
+ * values
1320
+ * (1, 1, 2, 'Green vs Blue'),
1321
+ * (2, 2, 1, 'Blue vs Green');
1322
+ * ```
1323
+ *
1324
+ * @exampleResponse Query nested foreign tables through a join table
1325
+ * ```json
1326
+ * {
1327
+ * "data": [
1328
+ * {
1329
+ * "game_id": 1,
1330
+ * "away_team": {
1331
+ * "users": [
1332
+ * {
1333
+ * "id": 1,
1334
+ * "name": "Kiran"
1335
+ * },
1336
+ * {
1337
+ * "id": 2,
1338
+ * "name": "Evan"
1339
+ * }
1340
+ * ]
1341
+ * }
1342
+ * },
1343
+ * {
1344
+ * "game_id": 2,
1345
+ * "away_team": {
1346
+ * "users": [
1347
+ * {
1348
+ * "id": 1,
1349
+ * "name": "Kiran"
1350
+ * }
1351
+ * ]
1352
+ * }
1353
+ * }
1354
+ * ],
1355
+ * "status": 200,
1356
+ * "statusText": "OK"
1357
+ * }
1358
+ *
1359
+ * ```
1360
+ *
1361
+ * @exampleDescription Filtering through referenced tables
1362
+ * If the filter on a referenced table's column is not satisfied, the referenced
1363
+ * table returns `[]` or `null` but the parent table is not filtered out.
1364
+ * If you want to filter out the parent table rows, use the `!inner` hint
1365
+ *
1366
+ * @example Filtering through referenced tables
1367
+ * ```ts
1368
+ * const { data, error } = await supabase
1369
+ * .from('instruments')
1370
+ * .select('name, orchestral_sections(*)')
1371
+ * .eq('orchestral_sections.name', 'percussion')
1372
+ * ```
1373
+ *
1374
+ * @exampleSql Filtering through referenced tables
1375
+ * ```sql
1376
+ * create table
1377
+ * orchestral_sections (id int8 primary key, name text);
1378
+ * create table
1379
+ * instruments (
1380
+ * id int8 primary key,
1381
+ * section_id int8 not null references orchestral_sections,
1382
+ * name text
1383
+ * );
1384
+ *
1385
+ * insert into
1386
+ * orchestral_sections (id, name)
1387
+ * values
1388
+ * (1, 'strings'),
1389
+ * (2, 'woodwinds');
1390
+ * insert into
1391
+ * instruments (id, section_id, name)
1392
+ * values
1393
+ * (1, 2, 'flute'),
1394
+ * (2, 1, 'violin');
1395
+ * ```
1396
+ *
1397
+ * @exampleResponse Filtering through referenced tables
1398
+ * ```json
1399
+ * {
1400
+ * "data": [
1401
+ * {
1402
+ * "name": "flute",
1403
+ * "orchestral_sections": null
1404
+ * },
1405
+ * {
1406
+ * "name": "violin",
1407
+ * "orchestral_sections": null
1408
+ * }
1409
+ * ],
1410
+ * "status": 200,
1411
+ * "statusText": "OK"
1412
+ * }
1413
+ * ```
1414
+ *
1415
+ * @exampleDescription Querying referenced table with count
1416
+ * You can get the number of rows in a related table by using the
1417
+ * **count** property.
1418
+ *
1419
+ * @example Querying referenced table with count
1420
+ * ```ts
1421
+ * const { data, error } = await supabase
1422
+ * .from('orchestral_sections')
1423
+ * .select(`*, instruments(count)`)
1424
+ * ```
1425
+ *
1426
+ * @exampleSql Querying referenced table with count
1427
+ * ```sql
1428
+ * create table orchestral_sections (
1429
+ * "id" "uuid" primary key default "extensions"."uuid_generate_v4"() not null,
1430
+ * "name" text
1431
+ * );
1432
+ *
1433
+ * create table characters (
1434
+ * "id" "uuid" primary key default "extensions"."uuid_generate_v4"() not null,
1435
+ * "name" text,
1436
+ * "section_id" "uuid" references public.orchestral_sections on delete cascade
1437
+ * );
1438
+ *
1439
+ * with section as (
1440
+ * insert into orchestral_sections (name)
1441
+ * values ('strings') returning id
1442
+ * )
1443
+ * insert into instruments (name, section_id) values
1444
+ * ('violin', (select id from section)),
1445
+ * ('viola', (select id from section)),
1446
+ * ('cello', (select id from section)),
1447
+ * ('double bass', (select id from section));
1448
+ * ```
1449
+ *
1450
+ * @exampleResponse Querying referenced table with count
1451
+ * ```json
1452
+ * [
1453
+ * {
1454
+ * "id": "693694e7-d993-4360-a6d7-6294e325d9b6",
1455
+ * "name": "strings",
1456
+ * "instruments": [
1457
+ * {
1458
+ * "count": 4
1459
+ * }
1460
+ * ]
1461
+ * }
1462
+ * ]
1463
+ * ```
1464
+ *
1465
+ * @exampleDescription Querying with count option
1466
+ * You can get the number of rows by using the
1467
+ * [count](/docs/reference/javascript/select#parameters) option.
1468
+ *
1469
+ * @example Querying with count option
1470
+ * ```ts
1471
+ * const { count, error } = await supabase
1472
+ * .from('characters')
1473
+ * .select('*', { count: 'exact', head: true })
1474
+ * ```
1475
+ *
1476
+ * @exampleSql Querying with count option
1477
+ * ```sql
1478
+ * create table
1479
+ * characters (id int8 primary key, name text);
1480
+ *
1481
+ * insert into
1482
+ * characters (id, name)
1483
+ * values
1484
+ * (1, 'Luke'),
1485
+ * (2, 'Leia'),
1486
+ * (3, 'Han');
1487
+ * ```
1488
+ *
1489
+ * @exampleResponse Querying with count option
1490
+ * ```json
1491
+ * {
1492
+ * "count": 3,
1493
+ * "status": 200,
1494
+ * "statusText": "OK"
1495
+ * }
1496
+ * ```
1497
+ *
1498
+ * @exampleDescription Querying JSON data
1499
+ * You can select and filter data inside of
1500
+ * [JSON](/docs/guides/database/json) columns. Postgres offers some
1501
+ * [operators](/docs/guides/database/json#query-the-jsonb-data) for
1502
+ * querying JSON data.
1503
+ *
1504
+ * @example Querying JSON data
1505
+ * ```ts
1506
+ * const { data, error } = await supabase
1507
+ * .from('users')
1508
+ * .select(`
1509
+ * id, name,
1510
+ * address->city
1511
+ * `)
1512
+ * ```
1513
+ *
1514
+ * @exampleSql Querying JSON data
1515
+ * ```sql
1516
+ * create table
1517
+ * users (
1518
+ * id int8 primary key,
1519
+ * name text,
1520
+ * address jsonb
1521
+ * );
1522
+ *
1523
+ * insert into
1524
+ * users (id, name, address)
1525
+ * values
1526
+ * (1, 'Frodo', '{"city":"Hobbiton"}');
1527
+ * ```
1528
+ *
1529
+ * @exampleResponse Querying JSON data
1530
+ * ```json
1531
+ * {
1532
+ * "data": [
1533
+ * {
1534
+ * "id": 1,
1535
+ * "name": "Frodo",
1536
+ * "city": "Hobbiton"
1537
+ * }
1538
+ * ],
1539
+ * "status": 200,
1540
+ * "statusText": "OK"
1541
+ * }
1542
+ * ```
1543
+ *
1544
+ * @exampleDescription Querying referenced table with inner join
1545
+ * If you don't want to return the referenced table contents, you can leave the parenthesis empty.
1546
+ * Like `.select('name, orchestral_sections!inner()')`.
1547
+ *
1548
+ * @example Querying referenced table with inner join
1549
+ * ```ts
1550
+ * const { data, error } = await supabase
1551
+ * .from('instruments')
1552
+ * .select('name, orchestral_sections!inner(name)')
1553
+ * .eq('orchestral_sections.name', 'woodwinds')
1554
+ * .limit(1)
1555
+ * ```
1556
+ *
1557
+ * @exampleSql Querying referenced table with inner join
1558
+ * ```sql
1559
+ * create table orchestral_sections (
1560
+ * "id" "uuid" primary key default "extensions"."uuid_generate_v4"() not null,
1561
+ * "name" text
1562
+ * );
1563
+ *
1564
+ * create table instruments (
1565
+ * "id" "uuid" primary key default "extensions"."uuid_generate_v4"() not null,
1566
+ * "name" text,
1567
+ * "section_id" "uuid" references public.orchestral_sections on delete cascade
1568
+ * );
1569
+ *
1570
+ * with section as (
1571
+ * insert into orchestral_sections (name)
1572
+ * values ('woodwinds') returning id
1573
+ * )
1574
+ * insert into instruments (name, section_id) values
1575
+ * ('flute', (select id from section)),
1576
+ * ('clarinet', (select id from section)),
1577
+ * ('bassoon', (select id from section)),
1578
+ * ('piccolo', (select id from section));
1579
+ * ```
1580
+ *
1581
+ * @exampleResponse Querying referenced table with inner join
1582
+ * ```json
1583
+ * {
1584
+ * "data": [
1585
+ * {
1586
+ * "name": "flute",
1587
+ * "orchestral_sections": {"name": "woodwinds"}
1588
+ * }
1589
+ * ],
1590
+ * "status": 200,
1591
+ * "statusText": "OK"
1592
+ * }
1593
+ * ```
1594
+ *
1595
+ * @exampleDescription Switching schemas per query
1596
+ * In addition to setting the schema during initialization, you can also switch schemas on a per-query basis.
1597
+ * Make sure you've set up your [database privileges and API settings](/docs/guides/api/using-custom-schemas).
1598
+ *
1599
+ * @example Switching schemas per query
1600
+ * ```ts
1601
+ * const { data, error } = await supabase
1602
+ * .schema('myschema')
1603
+ * .from('mytable')
1604
+ * .select()
1605
+ * ```
1606
+ *
1607
+ * @exampleSql Switching schemas per query
1608
+ * ```sql
1609
+ * create schema myschema;
1610
+ *
1611
+ * create table myschema.mytable (
1612
+ * id uuid primary key default gen_random_uuid(),
1613
+ * data text
1614
+ * );
1615
+ *
1616
+ * insert into myschema.mytable (data) values ('mydata');
1617
+ * ```
1618
+ *
1619
+ * @exampleResponse Switching schemas per query
1620
+ * ```json
1621
+ * {
1622
+ * "data": [
1623
+ * {
1624
+ * "id": "4162e008-27b0-4c0f-82dc-ccaeee9a624d",
1625
+ * "data": "mydata"
1626
+ * }
1627
+ * ],
1628
+ * "status": 200,
1629
+ * "statusText": "OK"
1630
+ * }
1631
+ * ```
878
1632
  */
879
1633
  select(columns, options) {
880
1634
  const { head = false, count } = options !== null && options !== void 0 ? options : {};
@@ -922,6 +1676,91 @@ var PostgrestQueryBuilder = class {
922
1676
  * @param options.defaultToNull - Make missing fields default to `null`.
923
1677
  * Otherwise, use the default value for the column. Only applies for bulk
924
1678
  * inserts.
1679
+ *
1680
+ * @category Database
1681
+ *
1682
+ * @example Create a record
1683
+ * ```ts
1684
+ * const { error } = await supabase
1685
+ * .from('countries')
1686
+ * .insert({ id: 1, name: 'Mordor' })
1687
+ * ```
1688
+ *
1689
+ * @exampleSql Create a record
1690
+ * ```sql
1691
+ * create table
1692
+ * countries (id int8 primary key, name text);
1693
+ * ```
1694
+ *
1695
+ * @exampleResponse Create a record
1696
+ * ```json
1697
+ * {
1698
+ * "status": 201,
1699
+ * "statusText": "Created"
1700
+ * }
1701
+ * ```
1702
+ *
1703
+ * @example Create a record and return it
1704
+ * ```ts
1705
+ * const { data, error } = await supabase
1706
+ * .from('countries')
1707
+ * .insert({ id: 1, name: 'Mordor' })
1708
+ * .select()
1709
+ * ```
1710
+ *
1711
+ * @exampleSql Create a record and return it
1712
+ * ```sql
1713
+ * create table
1714
+ * countries (id int8 primary key, name text);
1715
+ * ```
1716
+ *
1717
+ * @exampleResponse Create a record and return it
1718
+ * ```json
1719
+ * {
1720
+ * "data": [
1721
+ * {
1722
+ * "id": 1,
1723
+ * "name": "Mordor"
1724
+ * }
1725
+ * ],
1726
+ * "status": 201,
1727
+ * "statusText": "Created"
1728
+ * }
1729
+ * ```
1730
+ *
1731
+ * @exampleDescription Bulk create
1732
+ * A bulk create operation is handled in a single transaction.
1733
+ * If any of the inserts fail, none of the rows are inserted.
1734
+ *
1735
+ * @example Bulk create
1736
+ * ```ts
1737
+ * const { error } = await supabase
1738
+ * .from('countries')
1739
+ * .insert([
1740
+ * { id: 1, name: 'Mordor' },
1741
+ * { id: 1, name: 'The Shire' },
1742
+ * ])
1743
+ * ```
1744
+ *
1745
+ * @exampleSql Bulk create
1746
+ * ```sql
1747
+ * create table
1748
+ * countries (id int8 primary key, name text);
1749
+ * ```
1750
+ *
1751
+ * @exampleResponse Bulk create
1752
+ * ```json
1753
+ * {
1754
+ * "error": {
1755
+ * "code": "23505",
1756
+ * "details": "Key (id)=(1) already exists.",
1757
+ * "hint": null,
1758
+ * "message": "duplicate key value violates unique constraint \"countries_pkey\""
1759
+ * },
1760
+ * "status": 409,
1761
+ * "statusText": "Conflict"
1762
+ * }
1763
+ * ```
925
1764
  */
926
1765
  insert(values, { count, defaultToNull = true } = {}) {
927
1766
  var _this$fetch;
@@ -1030,6 +1869,129 @@ var PostgrestQueryBuilder = class {
1030
1869
  * // error: null
1031
1870
  * // }
1032
1871
  * ```
1872
+ *
1873
+ * @category Database
1874
+ *
1875
+ * @remarks
1876
+ * - Primary keys must be included in `values` to use upsert.
1877
+ *
1878
+ * @example Upsert your data
1879
+ * ```ts
1880
+ * const { data, error } = await supabase
1881
+ * .from('instruments')
1882
+ * .upsert({ id: 1, name: 'piano' })
1883
+ * .select()
1884
+ * ```
1885
+ *
1886
+ * @exampleSql Upsert your data
1887
+ * ```sql
1888
+ * create table
1889
+ * instruments (id int8 primary key, name text);
1890
+ *
1891
+ * insert into
1892
+ * instruments (id, name)
1893
+ * values
1894
+ * (1, 'harpsichord');
1895
+ * ```
1896
+ *
1897
+ * @exampleResponse Upsert your data
1898
+ * ```json
1899
+ * {
1900
+ * "data": [
1901
+ * {
1902
+ * "id": 1,
1903
+ * "name": "piano"
1904
+ * }
1905
+ * ],
1906
+ * "status": 201,
1907
+ * "statusText": "Created"
1908
+ * }
1909
+ * ```
1910
+ *
1911
+ * @example Bulk Upsert your data
1912
+ * ```ts
1913
+ * const { data, error } = await supabase
1914
+ * .from('instruments')
1915
+ * .upsert([
1916
+ * { id: 1, name: 'piano' },
1917
+ * { id: 2, name: 'harp' },
1918
+ * ])
1919
+ * .select()
1920
+ * ```
1921
+ *
1922
+ * @exampleSql Bulk Upsert your data
1923
+ * ```sql
1924
+ * create table
1925
+ * instruments (id int8 primary key, name text);
1926
+ *
1927
+ * insert into
1928
+ * instruments (id, name)
1929
+ * values
1930
+ * (1, 'harpsichord');
1931
+ * ```
1932
+ *
1933
+ * @exampleResponse Bulk Upsert your data
1934
+ * ```json
1935
+ * {
1936
+ * "data": [
1937
+ * {
1938
+ * "id": 1,
1939
+ * "name": "piano"
1940
+ * },
1941
+ * {
1942
+ * "id": 2,
1943
+ * "name": "harp"
1944
+ * }
1945
+ * ],
1946
+ * "status": 201,
1947
+ * "statusText": "Created"
1948
+ * }
1949
+ * ```
1950
+ *
1951
+ * @exampleDescription Upserting into tables with constraints
1952
+ * In the following query, `upsert()` implicitly uses the `id`
1953
+ * (primary key) column to determine conflicts. If there is no existing
1954
+ * row with the same `id`, `upsert()` inserts a new row, which
1955
+ * will fail in this case as there is already a row with `handle` `"saoirse"`.
1956
+ * Using the `onConflict` option, you can instruct `upsert()` to use
1957
+ * another column with a unique constraint to determine conflicts.
1958
+ *
1959
+ * @example Upserting into tables with constraints
1960
+ * ```ts
1961
+ * const { data, error } = await supabase
1962
+ * .from('users')
1963
+ * .upsert({ id: 42, handle: 'saoirse', display_name: 'Saoirse' })
1964
+ * .select()
1965
+ * ```
1966
+ *
1967
+ * @exampleSql Upserting into tables with constraints
1968
+ * ```sql
1969
+ * create table
1970
+ * users (
1971
+ * id int8 generated by default as identity primary key,
1972
+ * handle text not null unique,
1973
+ * display_name text
1974
+ * );
1975
+ *
1976
+ * insert into
1977
+ * users (id, handle, display_name)
1978
+ * values
1979
+ * (1, 'saoirse', null);
1980
+ * ```
1981
+ *
1982
+ * @exampleResponse Upserting into tables with constraints
1983
+ * ```json
1984
+ * {
1985
+ * "error": {
1986
+ * "code": "23505",
1987
+ * "details": "Key (handle)=(saoirse) already exists.",
1988
+ * "hint": null,
1989
+ * "message": "duplicate key value violates unique constraint \"users_handle_key\""
1990
+ * },
1991
+ * "status": 409,
1992
+ * "statusText": "Conflict"
1993
+ * }
1994
+ * ```
1033
1995
  */
1034
1996
  upsert(values, { onConflict, ignoreDuplicates = false, count, defaultToNull = true } = {}) {
1035
1997
  var _this$fetch2;
@@ -1076,6 +2038,124 @@ var PostgrestQueryBuilder = class {
1076
2038
  *
1077
2039
  * `"estimated"`: Uses exact count for low numbers and planned count for high
1078
2040
  * numbers.
2041
+ *
2042
+ * @category Database
2043
+ *
2044
+ * @remarks
2045
+ * - `update()` should always be combined with [Filters](/docs/reference/javascript/using-filters) to target the item(s) you wish to update.
2046
+ *
2047
+ * @example Updating your data
2048
+ * ```ts
2049
+ * const { error } = await supabase
2050
+ * .from('instruments')
2051
+ * .update({ name: 'piano' })
2052
+ * .eq('id', 1)
2053
+ * ```
2054
+ *
2055
+ * @exampleSql Updating your data
2056
+ * ```sql
2057
+ * create table
2058
+ * instruments (id int8 primary key, name text);
2059
+ *
2060
+ * insert into
2061
+ * instruments (id, name)
2062
+ * values
2063
+ * (1, 'harpsichord');
2064
+ * ```
2065
+ *
2066
+ * @exampleResponse Updating your data
2067
+ * ```json
2068
+ * {
2069
+ * "status": 204,
2070
+ * "statusText": "No Content"
2071
+ * }
2072
+ * ```
2073
+ *
2074
+ * @example Update a record and return it
2075
+ * ```ts
2076
+ * const { data, error } = await supabase
2077
+ * .from('instruments')
2078
+ * .update({ name: 'piano' })
2079
+ * .eq('id', 1)
2080
+ * .select()
2081
+ * ```
2082
+ *
2083
+ * @exampleSql Update a record and return it
2084
+ * ```sql
2085
+ * create table
2086
+ * instruments (id int8 primary key, name text);
2087
+ *
2088
+ * insert into
2089
+ * instruments (id, name)
2090
+ * values
2091
+ * (1, 'harpsichord');
2092
+ * ```
2093
+ *
2094
+ * @exampleResponse Update a record and return it
2095
+ * ```json
2096
+ * {
2097
+ * "data": [
2098
+ * {
2099
+ * "id": 1,
2100
+ * "name": "piano"
2101
+ * }
2102
+ * ],
2103
+ * "status": 200,
2104
+ * "statusText": "OK"
2105
+ * }
2106
+ * ```
2107
+ *
2108
+ * @exampleDescription Updating JSON data
2109
+ * Postgres offers some
2110
+ * [operators](/docs/guides/database/json#query-the-jsonb-data) for
2111
+ * working with JSON data. Currently, it is only possible to update the entire JSON document.
2112
+ *
2113
+ * @example Updating JSON data
2114
+ * ```ts
2115
+ * const { data, error } = await supabase
2116
+ * .from('users')
2117
+ * .update({
2118
+ * address: {
2119
+ * street: 'Melrose Place',
2120
+ * postcode: 90210
2121
+ * }
2122
+ * })
2123
+ * .eq('address->postcode', 90210)
2124
+ * .select()
2125
+ * ```
2126
+ *
2127
+ * @exampleSql Updating JSON data
2128
+ * ```sql
2129
+ * create table
2130
+ * users (
2131
+ * id int8 primary key,
2132
+ * name text,
2133
+ * address jsonb
2134
+ * );
2135
+ *
2136
+ * insert into
2137
+ * users (id, name, address)
2138
+ * values
2139
+ * (1, 'Michael', '{ "postcode": 90210 }');
2140
+ * ```
2141
+ *
2142
+ * @exampleResponse Updating JSON data
2143
+ * ```json
2144
+ * {
2145
+ * "data": [
2146
+ * {
2147
+ * "id": 1,
2148
+ * "name": "Michael",
2149
+ * "address": {
2150
+ * "street": "Melrose Place",
2151
+ * "postcode": 90210
2152
+ * }
2153
+ * }
2154
+ * ],
2155
+ * "status": 200,
2156
+ * "statusText": "OK"
2157
+ * }
2158
+ * ```
1079
2159
  */
1080
2160
  update(values, { count } = {}) {
1081
2161
  var _this$fetch3;