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