@supabase/postgrest-js 2.99.2 → 2.99.3
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 +2475 -130
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1055 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1055 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2475 -130
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/PostgrestBuilder.ts +93 -1
- package/src/PostgrestClient.ts +165 -1
- package/src/PostgrestFilterBuilder.ts +1382 -3
- package/src/PostgrestQueryBuilder.ts +112 -1
- package/src/PostgrestTransformBuilder.ts +603 -0
- package/src/version.ts +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -638,7 +638,19 @@ declare abstract class PostgrestBuilder<ClientOptions extends ClientServerOption
|
|
|
638
638
|
*
|
|
639
639
|
* @example
|
|
640
640
|
* ```ts
|
|
641
|
-
* import PostgrestQueryBuilder from '@supabase/postgrest-js'
|
|
641
|
+
* import { PostgrestQueryBuilder } from '@supabase/postgrest-js'
|
|
642
|
+
*
|
|
643
|
+
* const builder = new PostgrestQueryBuilder(
|
|
644
|
+
* new URL('https://xyzcompany.supabase.co/rest/v1/users'),
|
|
645
|
+
* { headers: new Headers({ apikey: 'public-anon-key' }) }
|
|
646
|
+
* )
|
|
647
|
+
* ```
|
|
648
|
+
*
|
|
649
|
+
* @category Database
|
|
650
|
+
*
|
|
651
|
+
* @example Example 1
|
|
652
|
+
* ```ts
|
|
653
|
+
* import { PostgrestQueryBuilder } from '@supabase/postgrest-js'
|
|
642
654
|
*
|
|
643
655
|
* const builder = new PostgrestQueryBuilder(
|
|
644
656
|
* new URL('https://xyzcompany.supabase.co/rest/v1/users'),
|
|
@@ -663,18 +675,27 @@ declare abstract class PostgrestBuilder<ClientOptions extends ClientServerOption
|
|
|
663
675
|
* throwing the error instead of returning it as part of a successful response.
|
|
664
676
|
*
|
|
665
677
|
* {@link https://github.com/supabase/supabase-js/issues/92}
|
|
678
|
+
*
|
|
679
|
+
* @category Database
|
|
666
680
|
*/
|
|
667
681
|
throwOnError(): this & PostgrestBuilder<ClientOptions, Result$1, true>;
|
|
668
682
|
/**
|
|
669
683
|
* Set an HTTP header for the request.
|
|
684
|
+
*
|
|
685
|
+
* @category Database
|
|
670
686
|
*/
|
|
671
687
|
setHeader(name: string, value: string): this;
|
|
688
|
+
/** *
|
|
689
|
+
* @category Database
|
|
690
|
+
*/
|
|
672
691
|
then<TResult1 = (ThrowOnError extends true ? PostgrestResponseSuccess<Result$1> : PostgrestSingleResponse<Result$1>), TResult2 = never>(onfulfilled?: ((value: ThrowOnError extends true ? PostgrestResponseSuccess<Result$1> : PostgrestSingleResponse<Result$1>) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<TResult1 | TResult2>;
|
|
673
692
|
/**
|
|
674
693
|
* Override the type of the returned `data`.
|
|
675
694
|
*
|
|
676
695
|
* @typeParam NewResult - The new result type to override with
|
|
677
696
|
* @deprecated Use overrideTypes<yourType, { merge: false }>() method at the end of your call chain instead
|
|
697
|
+
*
|
|
698
|
+
* @category Database
|
|
678
699
|
*/
|
|
679
700
|
returns<NewResult>(): PostgrestBuilder<ClientOptions, CheckMatchingArrayTypes<Result$1, NewResult>, ThrowOnError>;
|
|
680
701
|
/**
|
|
@@ -698,6 +719,77 @@ declare abstract class PostgrestBuilder<ClientOptions extends ClientServerOption
|
|
|
698
719
|
* .overrideTypes<{ id: number; name: string }, { merge: false }>()
|
|
699
720
|
* ```
|
|
700
721
|
* @returns A PostgrestBuilder instance with the new type
|
|
722
|
+
*
|
|
723
|
+
* @category Database
|
|
724
|
+
*
|
|
725
|
+
* @example Complete Override type of successful response
|
|
726
|
+
* ```ts
|
|
727
|
+
* const { data } = await supabase
|
|
728
|
+
* .from('countries')
|
|
729
|
+
* .select()
|
|
730
|
+
* .overrideTypes<Array<MyType>, { merge: false }>()
|
|
731
|
+
* ```
|
|
732
|
+
*
|
|
733
|
+
* @exampleResponse Complete Override type of successful response
|
|
734
|
+
* ```ts
|
|
735
|
+
* let x: typeof data // MyType[]
|
|
736
|
+
* ```
|
|
737
|
+
*
|
|
738
|
+
* @example Complete Override type of object response
|
|
739
|
+
* ```ts
|
|
740
|
+
* const { data } = await supabase
|
|
741
|
+
* .from('countries')
|
|
742
|
+
* .select()
|
|
743
|
+
* .maybeSingle()
|
|
744
|
+
* .overrideTypes<MyType, { merge: false }>()
|
|
745
|
+
* ```
|
|
746
|
+
*
|
|
747
|
+
* @exampleResponse Complete Override type of object response
|
|
748
|
+
* ```ts
|
|
749
|
+
* let x: typeof data // MyType | null
|
|
750
|
+
* ```
|
|
751
|
+
*
|
|
752
|
+
* @example Partial Override type of successful response
|
|
753
|
+
* ```ts
|
|
754
|
+
* const { data } = await supabase
|
|
755
|
+
* .from('countries')
|
|
756
|
+
* .select()
|
|
757
|
+
* .overrideTypes<Array<{ status: "A" | "B" }>>()
|
|
758
|
+
* ```
|
|
759
|
+
*
|
|
760
|
+
* @exampleResponse Partial Override type of successful response
|
|
761
|
+
* ```ts
|
|
762
|
+
* let x: typeof data // Array<CountryRowProperties & { status: "A" | "B" }>
|
|
763
|
+
* ```
|
|
764
|
+
*
|
|
765
|
+
* @example Partial Override type of object response
|
|
766
|
+
* ```ts
|
|
767
|
+
* const { data } = await supabase
|
|
768
|
+
* .from('countries')
|
|
769
|
+
* .select()
|
|
770
|
+
* .maybeSingle()
|
|
771
|
+
* .overrideTypes<{ status: "A" | "B" }>()
|
|
772
|
+
* ```
|
|
773
|
+
*
|
|
774
|
+
* @exampleResponse Partial Override type of object response
|
|
775
|
+
* ```ts
|
|
776
|
+
* let x: typeof data // CountryRowProperties & { status: "A" | "B" } | null
|
|
777
|
+
* ```
|
|
778
|
+
*
|
|
779
|
+
* @example Example 5
|
|
780
|
+
* ```typescript
|
|
781
|
+
* // Merge with existing types (default behavior)
|
|
782
|
+
* const query = supabase
|
|
783
|
+
* .from('users')
|
|
784
|
+
* .select()
|
|
785
|
+
* .overrideTypes<{ custom_field: string }>()
|
|
786
|
+
*
|
|
787
|
+
* // Replace existing types completely
|
|
788
|
+
* const replaceQuery = supabase
|
|
789
|
+
* .from('users')
|
|
790
|
+
* .select()
|
|
791
|
+
* .overrideTypes<{ id: number; name: string }, { merge: false }>()
|
|
792
|
+
* ```
|
|
701
793
|
*/
|
|
702
794
|
overrideTypes<NewResult, Options extends {
|
|
703
795
|
merge?: boolean;
|
|
@@ -849,6 +941,41 @@ declare class PostgrestTransformBuilder<ClientOptions extends ClientServerOption
|
|
|
849
941
|
* `data`.
|
|
850
942
|
*
|
|
851
943
|
* @param columns - The columns to retrieve, separated by commas
|
|
944
|
+
*
|
|
945
|
+
* @category Database
|
|
946
|
+
*
|
|
947
|
+
* @example With `upsert()`
|
|
948
|
+
* ```ts
|
|
949
|
+
* const { data, error } = await supabase
|
|
950
|
+
* .from('characters')
|
|
951
|
+
* .upsert({ id: 1, name: 'Han Solo' })
|
|
952
|
+
* .select()
|
|
953
|
+
* ```
|
|
954
|
+
*
|
|
955
|
+
* @exampleSql With `upsert()`
|
|
956
|
+
* ```sql
|
|
957
|
+
* create table
|
|
958
|
+
* characters (id int8 primary key, name text);
|
|
959
|
+
*
|
|
960
|
+
* insert into
|
|
961
|
+
* characters (id, name)
|
|
962
|
+
* values
|
|
963
|
+
* (1, 'Han');
|
|
964
|
+
* ```
|
|
965
|
+
*
|
|
966
|
+
* @exampleResponse With `upsert()`
|
|
967
|
+
* ```json
|
|
968
|
+
* {
|
|
969
|
+
* "data": [
|
|
970
|
+
* {
|
|
971
|
+
* "id": 1,
|
|
972
|
+
* "name": "Han Solo"
|
|
973
|
+
* }
|
|
974
|
+
* ],
|
|
975
|
+
* "status": 201,
|
|
976
|
+
* "statusText": "Created"
|
|
977
|
+
* }
|
|
978
|
+
* ```
|
|
852
979
|
*/
|
|
853
980
|
select<Query extends string = '*', NewResultOne = GetResult<Schema, Row, RelationName, Relationships, Query, ClientOptions>>(columns?: Query): PostgrestFilterBuilder<ClientOptions, Schema, Row, Method extends 'RPC' ? Result$1 extends unknown[] ? NewResultOne[] : NewResultOne : NewResultOne[], RelationName, Relationships, Method>;
|
|
854
981
|
order<ColumnName extends string & keyof Row>(column: ColumnName, options?: {
|
|
@@ -886,6 +1013,95 @@ declare class PostgrestTransformBuilder<ClientOptions extends ClientServerOption
|
|
|
886
1013
|
* tables instead of the parent table
|
|
887
1014
|
* @param options.foreignTable - Deprecated, use `options.referencedTable`
|
|
888
1015
|
* instead
|
|
1016
|
+
*
|
|
1017
|
+
* @category Database
|
|
1018
|
+
*
|
|
1019
|
+
* @example With `select()`
|
|
1020
|
+
* ```ts
|
|
1021
|
+
* const { data, error } = await supabase
|
|
1022
|
+
* .from('characters')
|
|
1023
|
+
* .select('name')
|
|
1024
|
+
* .limit(1)
|
|
1025
|
+
* ```
|
|
1026
|
+
*
|
|
1027
|
+
* @exampleSql With `select()`
|
|
1028
|
+
* ```sql
|
|
1029
|
+
* create table
|
|
1030
|
+
* characters (id int8 primary key, name text);
|
|
1031
|
+
*
|
|
1032
|
+
* insert into
|
|
1033
|
+
* characters (id, name)
|
|
1034
|
+
* values
|
|
1035
|
+
* (1, 'Luke'),
|
|
1036
|
+
* (2, 'Leia'),
|
|
1037
|
+
* (3, 'Han');
|
|
1038
|
+
* ```
|
|
1039
|
+
*
|
|
1040
|
+
* @exampleResponse With `select()`
|
|
1041
|
+
* ```json
|
|
1042
|
+
* {
|
|
1043
|
+
* "data": [
|
|
1044
|
+
* {
|
|
1045
|
+
* "name": "Luke"
|
|
1046
|
+
* }
|
|
1047
|
+
* ],
|
|
1048
|
+
* "status": 200,
|
|
1049
|
+
* "statusText": "OK"
|
|
1050
|
+
* }
|
|
1051
|
+
* ```
|
|
1052
|
+
*
|
|
1053
|
+
* @example On a referenced table
|
|
1054
|
+
* ```ts
|
|
1055
|
+
* const { data, error } = await supabase
|
|
1056
|
+
* .from('orchestral_sections')
|
|
1057
|
+
* .select(`
|
|
1058
|
+
* name,
|
|
1059
|
+
* instruments (
|
|
1060
|
+
* name
|
|
1061
|
+
* )
|
|
1062
|
+
* `)
|
|
1063
|
+
* .limit(1, { referencedTable: 'instruments' })
|
|
1064
|
+
* ```
|
|
1065
|
+
*
|
|
1066
|
+
* @exampleSql On a referenced table
|
|
1067
|
+
* ```sql
|
|
1068
|
+
* create table
|
|
1069
|
+
* orchestral_sections (id int8 primary key, name text);
|
|
1070
|
+
* create table
|
|
1071
|
+
* instruments (
|
|
1072
|
+
* id int8 primary key,
|
|
1073
|
+
* section_id int8 not null references orchestral_sections,
|
|
1074
|
+
* name text
|
|
1075
|
+
* );
|
|
1076
|
+
*
|
|
1077
|
+
* insert into
|
|
1078
|
+
* orchestral_sections (id, name)
|
|
1079
|
+
* values
|
|
1080
|
+
* (1, 'strings');
|
|
1081
|
+
* insert into
|
|
1082
|
+
* instruments (id, section_id, name)
|
|
1083
|
+
* values
|
|
1084
|
+
* (1, 1, 'harp'),
|
|
1085
|
+
* (2, 1, 'violin');
|
|
1086
|
+
* ```
|
|
1087
|
+
*
|
|
1088
|
+
* @exampleResponse On a referenced table
|
|
1089
|
+
* ```json
|
|
1090
|
+
* {
|
|
1091
|
+
* "data": [
|
|
1092
|
+
* {
|
|
1093
|
+
* "name": "strings",
|
|
1094
|
+
* "instruments": [
|
|
1095
|
+
* {
|
|
1096
|
+
* "name": "violin"
|
|
1097
|
+
* }
|
|
1098
|
+
* ]
|
|
1099
|
+
* }
|
|
1100
|
+
* ],
|
|
1101
|
+
* "status": 200,
|
|
1102
|
+
* "statusText": "OK"
|
|
1103
|
+
* }
|
|
1104
|
+
* ```
|
|
889
1105
|
*/
|
|
890
1106
|
limit(count: number, {
|
|
891
1107
|
foreignTable,
|
|
@@ -908,6 +1124,45 @@ declare class PostgrestTransformBuilder<ClientOptions extends ClientServerOption
|
|
|
908
1124
|
* tables instead of the parent table
|
|
909
1125
|
* @param options.foreignTable - Deprecated, use `options.referencedTable`
|
|
910
1126
|
* instead
|
|
1127
|
+
*
|
|
1128
|
+
* @category Database
|
|
1129
|
+
*
|
|
1130
|
+
* @example With `select()`
|
|
1131
|
+
* ```ts
|
|
1132
|
+
* const { data, error } = await supabase
|
|
1133
|
+
* .from('characters')
|
|
1134
|
+
* .select('name')
|
|
1135
|
+
* .range(0, 1)
|
|
1136
|
+
* ```
|
|
1137
|
+
*
|
|
1138
|
+
* @exampleSql With `select()`
|
|
1139
|
+
* ```sql
|
|
1140
|
+
* create table
|
|
1141
|
+
* characters (id int8 primary key, name text);
|
|
1142
|
+
*
|
|
1143
|
+
* insert into
|
|
1144
|
+
* characters (id, name)
|
|
1145
|
+
* values
|
|
1146
|
+
* (1, 'Luke'),
|
|
1147
|
+
* (2, 'Leia'),
|
|
1148
|
+
* (3, 'Han');
|
|
1149
|
+
* ```
|
|
1150
|
+
*
|
|
1151
|
+
* @exampleResponse With `select()`
|
|
1152
|
+
* ```json
|
|
1153
|
+
* {
|
|
1154
|
+
* "data": [
|
|
1155
|
+
* {
|
|
1156
|
+
* "name": "Luke"
|
|
1157
|
+
* },
|
|
1158
|
+
* {
|
|
1159
|
+
* "name": "Leia"
|
|
1160
|
+
* }
|
|
1161
|
+
* ],
|
|
1162
|
+
* "status": 200,
|
|
1163
|
+
* "statusText": "OK"
|
|
1164
|
+
* }
|
|
1165
|
+
* ```
|
|
911
1166
|
*/
|
|
912
1167
|
range(from: number, to: number, {
|
|
913
1168
|
foreignTable,
|
|
@@ -920,6 +1175,66 @@ declare class PostgrestTransformBuilder<ClientOptions extends ClientServerOption
|
|
|
920
1175
|
* Set the AbortSignal for the fetch request.
|
|
921
1176
|
*
|
|
922
1177
|
* @param signal - The AbortSignal to use for the fetch request
|
|
1178
|
+
*
|
|
1179
|
+
* @category Database
|
|
1180
|
+
*
|
|
1181
|
+
* @remarks
|
|
1182
|
+
* You can use this to set a timeout for the request.
|
|
1183
|
+
*
|
|
1184
|
+
* @exampleDescription Aborting requests in-flight
|
|
1185
|
+
* You can use an [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) to abort requests.
|
|
1186
|
+
* Note that `status` and `statusText` don't mean anything for aborted requests as the request wasn't fulfilled.
|
|
1187
|
+
*
|
|
1188
|
+
* @example Aborting requests in-flight
|
|
1189
|
+
* ```ts
|
|
1190
|
+
* const ac = new AbortController()
|
|
1191
|
+
*
|
|
1192
|
+
* const { data, error } = await supabase
|
|
1193
|
+
* .from('very_big_table')
|
|
1194
|
+
* .select()
|
|
1195
|
+
* .abortSignal(ac.signal)
|
|
1196
|
+
*
|
|
1197
|
+
* // Abort the request after 100 ms
|
|
1198
|
+
* setTimeout(() => ac.abort(), 100)
|
|
1199
|
+
* ```
|
|
1200
|
+
*
|
|
1201
|
+
* @exampleResponse Aborting requests in-flight
|
|
1202
|
+
* ```json
|
|
1203
|
+
* {
|
|
1204
|
+
* "error": {
|
|
1205
|
+
* "message": "AbortError: The user aborted a request.",
|
|
1206
|
+
* "details": "",
|
|
1207
|
+
* "hint": "The request was aborted locally via the provided AbortSignal.",
|
|
1208
|
+
* "code": ""
|
|
1209
|
+
* },
|
|
1210
|
+
* "status": 0,
|
|
1211
|
+
* "statusText": ""
|
|
1212
|
+
* }
|
|
1213
|
+
*
|
|
1214
|
+
* ```
|
|
1215
|
+
*
|
|
1216
|
+
* @example Set a timeout
|
|
1217
|
+
* ```ts
|
|
1218
|
+
* const { data, error } = await supabase
|
|
1219
|
+
* .from('very_big_table')
|
|
1220
|
+
* .select()
|
|
1221
|
+
* .abortSignal(AbortSignal.timeout(1000 /* ms *\/))
|
|
1222
|
+
* ```
|
|
1223
|
+
*
|
|
1224
|
+
* @exampleResponse Set a timeout
|
|
1225
|
+
* ```json
|
|
1226
|
+
* {
|
|
1227
|
+
* "error": {
|
|
1228
|
+
* "message": "FetchError: The user aborted a request.",
|
|
1229
|
+
* "details": "",
|
|
1230
|
+
* "hint": "",
|
|
1231
|
+
* "code": ""
|
|
1232
|
+
* },
|
|
1233
|
+
* "status": 400,
|
|
1234
|
+
* "statusText": "Bad Request"
|
|
1235
|
+
* }
|
|
1236
|
+
*
|
|
1237
|
+
* ```
|
|
923
1238
|
*/
|
|
924
1239
|
abortSignal(signal: AbortSignal): this;
|
|
925
1240
|
/**
|
|
@@ -927,6 +1242,41 @@ declare class PostgrestTransformBuilder<ClientOptions extends ClientServerOption
|
|
|
927
1242
|
*
|
|
928
1243
|
* Query result must be one row (e.g. using `.limit(1)`), otherwise this
|
|
929
1244
|
* returns an error.
|
|
1245
|
+
*
|
|
1246
|
+
* @category Database
|
|
1247
|
+
*
|
|
1248
|
+
* @example With `select()`
|
|
1249
|
+
* ```ts
|
|
1250
|
+
* const { data, error } = await supabase
|
|
1251
|
+
* .from('characters')
|
|
1252
|
+
* .select('name')
|
|
1253
|
+
* .limit(1)
|
|
1254
|
+
* .single()
|
|
1255
|
+
* ```
|
|
1256
|
+
*
|
|
1257
|
+
* @exampleSql With `select()`
|
|
1258
|
+
* ```sql
|
|
1259
|
+
* create table
|
|
1260
|
+
* characters (id int8 primary key, name text);
|
|
1261
|
+
*
|
|
1262
|
+
* insert into
|
|
1263
|
+
* characters (id, name)
|
|
1264
|
+
* values
|
|
1265
|
+
* (1, 'Luke'),
|
|
1266
|
+
* (2, 'Leia'),
|
|
1267
|
+
* (3, 'Han');
|
|
1268
|
+
* ```
|
|
1269
|
+
*
|
|
1270
|
+
* @exampleResponse With `select()`
|
|
1271
|
+
* ```json
|
|
1272
|
+
* {
|
|
1273
|
+
* "data": {
|
|
1274
|
+
* "name": "Luke"
|
|
1275
|
+
* },
|
|
1276
|
+
* "status": 200,
|
|
1277
|
+
* "statusText": "OK"
|
|
1278
|
+
* }
|
|
1279
|
+
* ```
|
|
930
1280
|
*/
|
|
931
1281
|
single<ResultOne = (Result$1 extends (infer ResultOne)[] ? ResultOne : never)>(): PostgrestBuilder<ClientOptions, ResultOne>;
|
|
932
1282
|
/**
|
|
@@ -934,14 +1284,83 @@ declare class PostgrestTransformBuilder<ClientOptions extends ClientServerOption
|
|
|
934
1284
|
*
|
|
935
1285
|
* Query result must be zero or one row (e.g. using `.limit(1)`), otherwise
|
|
936
1286
|
* this returns an error.
|
|
1287
|
+
*
|
|
1288
|
+
* @category Database
|
|
1289
|
+
*
|
|
1290
|
+
* @example With `select()`
|
|
1291
|
+
* ```ts
|
|
1292
|
+
* const { data, error } = await supabase
|
|
1293
|
+
* .from('characters')
|
|
1294
|
+
* .select()
|
|
1295
|
+
* .eq('name', 'Katniss')
|
|
1296
|
+
* .maybeSingle()
|
|
1297
|
+
* ```
|
|
1298
|
+
*
|
|
1299
|
+
* @exampleSql With `select()`
|
|
1300
|
+
* ```sql
|
|
1301
|
+
* create table
|
|
1302
|
+
* characters (id int8 primary key, name text);
|
|
1303
|
+
*
|
|
1304
|
+
* insert into
|
|
1305
|
+
* characters (id, name)
|
|
1306
|
+
* values
|
|
1307
|
+
* (1, 'Luke'),
|
|
1308
|
+
* (2, 'Leia'),
|
|
1309
|
+
* (3, 'Han');
|
|
1310
|
+
* ```
|
|
1311
|
+
*
|
|
1312
|
+
* @exampleResponse With `select()`
|
|
1313
|
+
* ```json
|
|
1314
|
+
* {
|
|
1315
|
+
* "status": 200,
|
|
1316
|
+
* "statusText": "OK"
|
|
1317
|
+
* }
|
|
1318
|
+
* ```
|
|
937
1319
|
*/
|
|
938
1320
|
maybeSingle<ResultOne = (Result$1 extends (infer ResultOne)[] ? ResultOne : never)>(): PostgrestBuilder<ClientOptions, ResultOne | null>;
|
|
939
1321
|
/**
|
|
940
1322
|
* Return `data` as a string in CSV format.
|
|
1323
|
+
*
|
|
1324
|
+
* @category Database
|
|
1325
|
+
*
|
|
1326
|
+
* @exampleDescription Return data as CSV
|
|
1327
|
+
* By default, the data is returned in JSON format, but can also be returned as Comma Separated Values.
|
|
1328
|
+
*
|
|
1329
|
+
* @example Return data as CSV
|
|
1330
|
+
* ```ts
|
|
1331
|
+
* const { data, error } = await supabase
|
|
1332
|
+
* .from('characters')
|
|
1333
|
+
* .select()
|
|
1334
|
+
* .csv()
|
|
1335
|
+
* ```
|
|
1336
|
+
*
|
|
1337
|
+
* @exampleSql Return data as CSV
|
|
1338
|
+
* ```sql
|
|
1339
|
+
* create table
|
|
1340
|
+
* characters (id int8 primary key, name text);
|
|
1341
|
+
*
|
|
1342
|
+
* insert into
|
|
1343
|
+
* characters (id, name)
|
|
1344
|
+
* values
|
|
1345
|
+
* (1, 'Luke'),
|
|
1346
|
+
* (2, 'Leia'),
|
|
1347
|
+
* (3, 'Han');
|
|
1348
|
+
* ```
|
|
1349
|
+
*
|
|
1350
|
+
* @exampleResponse Return data as CSV
|
|
1351
|
+
* ```json
|
|
1352
|
+
* {
|
|
1353
|
+
* "data": "id,name\n1,Luke\n2,Leia\n3,Han",
|
|
1354
|
+
* "status": 200,
|
|
1355
|
+
* "statusText": "OK"
|
|
1356
|
+
* }
|
|
1357
|
+
* ```
|
|
941
1358
|
*/
|
|
942
1359
|
csv(): PostgrestBuilder<ClientOptions, string>;
|
|
943
1360
|
/**
|
|
944
1361
|
* Return `data` as an object in [GeoJSON](https://geojson.org) format.
|
|
1362
|
+
*
|
|
1363
|
+
* @category Database
|
|
945
1364
|
*/
|
|
946
1365
|
geojson(): PostgrestBuilder<ClientOptions, Record<string, unknown>>;
|
|
947
1366
|
/**
|
|
@@ -968,6 +1387,76 @@ declare class PostgrestTransformBuilder<ClientOptions extends ClientServerOption
|
|
|
968
1387
|
*
|
|
969
1388
|
* @param options.format - The format of the output, can be `"text"` (default)
|
|
970
1389
|
* or `"json"`
|
|
1390
|
+
*
|
|
1391
|
+
* @category Database
|
|
1392
|
+
*
|
|
1393
|
+
* @exampleDescription Get the execution plan
|
|
1394
|
+
* By default, the data is returned in TEXT format, but can also be returned as JSON by using the `format` parameter.
|
|
1395
|
+
*
|
|
1396
|
+
* @example Get the execution plan
|
|
1397
|
+
* ```ts
|
|
1398
|
+
* const { data, error } = await supabase
|
|
1399
|
+
* .from('characters')
|
|
1400
|
+
* .select()
|
|
1401
|
+
* .explain()
|
|
1402
|
+
* ```
|
|
1403
|
+
*
|
|
1404
|
+
* @exampleSql Get the execution plan
|
|
1405
|
+
* ```sql
|
|
1406
|
+
* create table
|
|
1407
|
+
* characters (id int8 primary key, name text);
|
|
1408
|
+
*
|
|
1409
|
+
* insert into
|
|
1410
|
+
* characters (id, name)
|
|
1411
|
+
* values
|
|
1412
|
+
* (1, 'Luke'),
|
|
1413
|
+
* (2, 'Leia'),
|
|
1414
|
+
* (3, 'Han');
|
|
1415
|
+
* ```
|
|
1416
|
+
*
|
|
1417
|
+
* @exampleResponse Get the execution plan
|
|
1418
|
+
* ```js
|
|
1419
|
+
* Aggregate (cost=33.34..33.36 rows=1 width=112)
|
|
1420
|
+
* -> Limit (cost=0.00..18.33 rows=1000 width=40)
|
|
1421
|
+
* -> Seq Scan on characters (cost=0.00..22.00 rows=1200 width=40)
|
|
1422
|
+
* ```
|
|
1423
|
+
*
|
|
1424
|
+
* @exampleDescription Get the execution plan with analyze and verbose
|
|
1425
|
+
* By default, the data is returned in TEXT format, but can also be returned as JSON by using the `format` parameter.
|
|
1426
|
+
*
|
|
1427
|
+
* @example Get the execution plan with analyze and verbose
|
|
1428
|
+
* ```ts
|
|
1429
|
+
* const { data, error } = await supabase
|
|
1430
|
+
* .from('characters')
|
|
1431
|
+
* .select()
|
|
1432
|
+
* .explain({analyze:true,verbose:true})
|
|
1433
|
+
* ```
|
|
1434
|
+
*
|
|
1435
|
+
* @exampleSql Get the execution plan with analyze and verbose
|
|
1436
|
+
* ```sql
|
|
1437
|
+
* create table
|
|
1438
|
+
* characters (id int8 primary key, name text);
|
|
1439
|
+
*
|
|
1440
|
+
* insert into
|
|
1441
|
+
* characters (id, name)
|
|
1442
|
+
* values
|
|
1443
|
+
* (1, 'Luke'),
|
|
1444
|
+
* (2, 'Leia'),
|
|
1445
|
+
* (3, 'Han');
|
|
1446
|
+
* ```
|
|
1447
|
+
*
|
|
1448
|
+
* @exampleResponse Get the execution plan with analyze and verbose
|
|
1449
|
+
* ```js
|
|
1450
|
+
* Aggregate (cost=33.34..33.36 rows=1 width=112) (actual time=0.041..0.041 rows=1 loops=1)
|
|
1451
|
+
* Output: NULL::bigint, count(ROW(characters.id, characters.name)), COALESCE(json_agg(ROW(characters.id, characters.name)), '[]'::json), NULLIF(current_setting('response.headers'::text, true), ''::text), NULLIF(current_setting('response.status'::text, true), ''::text)
|
|
1452
|
+
* -> Limit (cost=0.00..18.33 rows=1000 width=40) (actual time=0.005..0.006 rows=3 loops=1)
|
|
1453
|
+
* Output: characters.id, characters.name
|
|
1454
|
+
* -> Seq Scan on public.characters (cost=0.00..22.00 rows=1200 width=40) (actual time=0.004..0.005 rows=3 loops=1)
|
|
1455
|
+
* Output: characters.id, characters.name
|
|
1456
|
+
* Query Identifier: -4730654291623321173
|
|
1457
|
+
* Planning Time: 0.407 ms
|
|
1458
|
+
* Execution Time: 0.119 ms
|
|
1459
|
+
* ```
|
|
971
1460
|
*/
|
|
972
1461
|
explain({
|
|
973
1462
|
analyze,
|
|
@@ -988,6 +1477,8 @@ declare class PostgrestTransformBuilder<ClientOptions extends ClientServerOption
|
|
|
988
1477
|
* Rollback the query.
|
|
989
1478
|
*
|
|
990
1479
|
* `data` will still be returned, but the query is not committed.
|
|
1480
|
+
*
|
|
1481
|
+
* @category Database
|
|
991
1482
|
*/
|
|
992
1483
|
rollback(): this;
|
|
993
1484
|
/**
|
|
@@ -995,6 +1486,38 @@ declare class PostgrestTransformBuilder<ClientOptions extends ClientServerOption
|
|
|
995
1486
|
*
|
|
996
1487
|
* @typeParam NewResult - The new result type to override with
|
|
997
1488
|
* @deprecated Use overrideTypes<yourType, { merge: false }>() method at the end of your call chain instead
|
|
1489
|
+
*
|
|
1490
|
+
* @category Database
|
|
1491
|
+
*
|
|
1492
|
+
* @remarks
|
|
1493
|
+
* - Deprecated: use overrideTypes method instead
|
|
1494
|
+
*
|
|
1495
|
+
* @example Override type of successful response
|
|
1496
|
+
* ```ts
|
|
1497
|
+
* const { data } = await supabase
|
|
1498
|
+
* .from('countries')
|
|
1499
|
+
* .select()
|
|
1500
|
+
* .returns<Array<MyType>>()
|
|
1501
|
+
* ```
|
|
1502
|
+
*
|
|
1503
|
+
* @exampleResponse Override type of successful response
|
|
1504
|
+
* ```js
|
|
1505
|
+
* let x: typeof data // MyType[]
|
|
1506
|
+
* ```
|
|
1507
|
+
*
|
|
1508
|
+
* @example Override type of object response
|
|
1509
|
+
* ```ts
|
|
1510
|
+
* const { data } = await supabase
|
|
1511
|
+
* .from('countries')
|
|
1512
|
+
* .select()
|
|
1513
|
+
* .maybeSingle()
|
|
1514
|
+
* .returns<MyType>()
|
|
1515
|
+
* ```
|
|
1516
|
+
*
|
|
1517
|
+
* @exampleResponse Override type of object response
|
|
1518
|
+
* ```js
|
|
1519
|
+
* let x: typeof data // MyType | null
|
|
1520
|
+
* ```
|
|
998
1521
|
*/
|
|
999
1522
|
returns<NewResult>(): PostgrestTransformBuilder<ClientOptions, Schema, Row, CheckMatchingArrayTypes<Result$1, NewResult>, RelationName, Relationships, Method>;
|
|
1000
1523
|
/**
|
|
@@ -1002,6 +1525,8 @@ declare class PostgrestTransformBuilder<ClientOptions extends ClientServerOption
|
|
|
1002
1525
|
* Only available in PostgREST v13+ and only works with PATCH and DELETE methods.
|
|
1003
1526
|
*
|
|
1004
1527
|
* @param value - The maximum number of rows that can be affected
|
|
1528
|
+
*
|
|
1529
|
+
* @category Database
|
|
1005
1530
|
*/
|
|
1006
1531
|
maxAffected(value: number): MaxAffectedEnabled<ClientOptions['PostgrestVersion']> extends true ? Method extends 'PATCH' | 'DELETE' | 'RPC' ? this : InvalidMethodError<'maxAffected method only available on update or delete'> : InvalidMethodError<'maxAffected method only available on postgrest 13+'>;
|
|
1007
1532
|
}
|
|
@@ -1022,6 +1547,43 @@ declare class PostgrestFilterBuilder<ClientOptions extends ClientServerOptions,
|
|
|
1022
1547
|
*
|
|
1023
1548
|
* @param column - The column to filter on
|
|
1024
1549
|
* @param value - The value to filter with
|
|
1550
|
+
*
|
|
1551
|
+
* @category Database
|
|
1552
|
+
*
|
|
1553
|
+
* @example With `select()`
|
|
1554
|
+
* ```ts
|
|
1555
|
+
* const { data, error } = await supabase
|
|
1556
|
+
* .from('characters')
|
|
1557
|
+
* .select()
|
|
1558
|
+
* .eq('name', 'Leia')
|
|
1559
|
+
* ```
|
|
1560
|
+
*
|
|
1561
|
+
* @exampleSql With `select()`
|
|
1562
|
+
* ```sql
|
|
1563
|
+
* create table
|
|
1564
|
+
* characters (id int8 primary key, name text);
|
|
1565
|
+
*
|
|
1566
|
+
* insert into
|
|
1567
|
+
* characters (id, name)
|
|
1568
|
+
* values
|
|
1569
|
+
* (1, 'Luke'),
|
|
1570
|
+
* (2, 'Leia'),
|
|
1571
|
+
* (3, 'Han');
|
|
1572
|
+
* ```
|
|
1573
|
+
*
|
|
1574
|
+
* @exampleResponse With `select()`
|
|
1575
|
+
* ```json
|
|
1576
|
+
* {
|
|
1577
|
+
* "data": [
|
|
1578
|
+
* {
|
|
1579
|
+
* "id": 2,
|
|
1580
|
+
* "name": "Leia"
|
|
1581
|
+
* }
|
|
1582
|
+
* ],
|
|
1583
|
+
* "status": 200,
|
|
1584
|
+
* "statusText": "OK"
|
|
1585
|
+
* }
|
|
1586
|
+
* ```
|
|
1025
1587
|
*/
|
|
1026
1588
|
eq<ColumnName extends string>(column: ColumnName, value: ResolveFilterValue<Schema, Row, ColumnName> extends never ? NonNullable<unknown> : ResolveFilterValue<Schema, Row, ColumnName> extends infer ResolvedFilterValue ? NonNullable<ResolvedFilterValue> : never): this;
|
|
1027
1589
|
/**
|
|
@@ -1029,6 +1591,47 @@ declare class PostgrestFilterBuilder<ClientOptions extends ClientServerOptions,
|
|
|
1029
1591
|
*
|
|
1030
1592
|
* @param column - The column to filter on
|
|
1031
1593
|
* @param value - The value to filter with
|
|
1594
|
+
*
|
|
1595
|
+
* @category Database
|
|
1596
|
+
*
|
|
1597
|
+
* @example With `select()`
|
|
1598
|
+
* ```ts
|
|
1599
|
+
* const { data, error } = await supabase
|
|
1600
|
+
* .from('characters')
|
|
1601
|
+
* .select()
|
|
1602
|
+
* .neq('name', 'Leia')
|
|
1603
|
+
* ```
|
|
1604
|
+
*
|
|
1605
|
+
* @exampleSql With `select()`
|
|
1606
|
+
* ```sql
|
|
1607
|
+
* create table
|
|
1608
|
+
* characters (id int8 primary key, name text);
|
|
1609
|
+
*
|
|
1610
|
+
* insert into
|
|
1611
|
+
* characters (id, name)
|
|
1612
|
+
* values
|
|
1613
|
+
* (1, 'Luke'),
|
|
1614
|
+
* (2, 'Leia'),
|
|
1615
|
+
* (3, 'Han');
|
|
1616
|
+
* ```
|
|
1617
|
+
*
|
|
1618
|
+
* @exampleResponse With `select()`
|
|
1619
|
+
* ```json
|
|
1620
|
+
* {
|
|
1621
|
+
* "data": [
|
|
1622
|
+
* {
|
|
1623
|
+
* "id": 1,
|
|
1624
|
+
* "name": "Luke"
|
|
1625
|
+
* },
|
|
1626
|
+
* {
|
|
1627
|
+
* "id": 3,
|
|
1628
|
+
* "name": "Han"
|
|
1629
|
+
* }
|
|
1630
|
+
* ],
|
|
1631
|
+
* "status": 200,
|
|
1632
|
+
* "statusText": "OK"
|
|
1633
|
+
* }
|
|
1634
|
+
* ```
|
|
1032
1635
|
*/
|
|
1033
1636
|
neq<ColumnName extends string>(column: ColumnName, value: ResolveFilterValue<Schema, Row, ColumnName> extends never ? unknown : ResolveFilterValue<Schema, Row, ColumnName> extends infer ResolvedFilterValue ? ResolvedFilterValue : never): this;
|
|
1034
1637
|
gt<ColumnName extends string & keyof Row>(column: ColumnName, value: Row[ColumnName]): this;
|
|
@@ -1073,6 +1676,47 @@ declare class PostgrestFilterBuilder<ClientOptions extends ClientServerOptions,
|
|
|
1073
1676
|
*
|
|
1074
1677
|
* @param column - The column to filter on
|
|
1075
1678
|
* @param values - The values array to filter with
|
|
1679
|
+
*
|
|
1680
|
+
* @category Database
|
|
1681
|
+
*
|
|
1682
|
+
* @example With `select()`
|
|
1683
|
+
* ```ts
|
|
1684
|
+
* const { data, error } = await supabase
|
|
1685
|
+
* .from('characters')
|
|
1686
|
+
* .select()
|
|
1687
|
+
* .in('name', ['Leia', 'Han'])
|
|
1688
|
+
* ```
|
|
1689
|
+
*
|
|
1690
|
+
* @exampleSql With `select()`
|
|
1691
|
+
* ```sql
|
|
1692
|
+
* create table
|
|
1693
|
+
* characters (id int8 primary key, name text);
|
|
1694
|
+
*
|
|
1695
|
+
* insert into
|
|
1696
|
+
* characters (id, name)
|
|
1697
|
+
* values
|
|
1698
|
+
* (1, 'Luke'),
|
|
1699
|
+
* (2, 'Leia'),
|
|
1700
|
+
* (3, 'Han');
|
|
1701
|
+
* ```
|
|
1702
|
+
*
|
|
1703
|
+
* @exampleResponse With `select()`
|
|
1704
|
+
* ```json
|
|
1705
|
+
* {
|
|
1706
|
+
* "data": [
|
|
1707
|
+
* {
|
|
1708
|
+
* "id": 2,
|
|
1709
|
+
* "name": "Leia"
|
|
1710
|
+
* },
|
|
1711
|
+
* {
|
|
1712
|
+
* "id": 3,
|
|
1713
|
+
* "name": "Han"
|
|
1714
|
+
* }
|
|
1715
|
+
* ],
|
|
1716
|
+
* "status": 200,
|
|
1717
|
+
* "statusText": "OK"
|
|
1718
|
+
* }
|
|
1719
|
+
* ```
|
|
1076
1720
|
*/
|
|
1077
1721
|
in<ColumnName extends string>(column: ColumnName, values: ReadonlyArray<ResolveFilterValue<Schema, Row, ColumnName> extends never ? unknown : ResolveFilterValue<Schema, Row, ColumnName> extends infer ResolvedFilterValue ? ResolvedFilterValue : never>): this;
|
|
1078
1722
|
/**
|
|
@@ -1124,6 +1768,141 @@ declare class PostgrestFilterBuilder<ClientOptions extends ClientServerOptions,
|
|
|
1124
1768
|
* @param options.referencedTable - Set this to filter on referenced tables
|
|
1125
1769
|
* instead of the parent table
|
|
1126
1770
|
* @param options.foreignTable - Deprecated, use `referencedTable` instead
|
|
1771
|
+
*
|
|
1772
|
+
* @category Database
|
|
1773
|
+
*
|
|
1774
|
+
* @remarks
|
|
1775
|
+
* or() expects you to use the raw PostgREST syntax for the filter names and values.
|
|
1776
|
+
*
|
|
1777
|
+
* ```ts
|
|
1778
|
+
* .or('id.in.(5,6,7), arraycol.cs.{"a","b"}') // Use `()` for `in` filter, `{}` for array values and `cs` for `contains()`.
|
|
1779
|
+
* .or('id.in.(5,6,7), arraycol.cd.{"a","b"}') // Use `cd` for `containedBy()`
|
|
1780
|
+
* ```
|
|
1781
|
+
*
|
|
1782
|
+
* @example With `select()`
|
|
1783
|
+
* ```ts
|
|
1784
|
+
* const { data, error } = await supabase
|
|
1785
|
+
* .from('characters')
|
|
1786
|
+
* .select('name')
|
|
1787
|
+
* .or('id.eq.2,name.eq.Han')
|
|
1788
|
+
* ```
|
|
1789
|
+
*
|
|
1790
|
+
* @exampleSql With `select()`
|
|
1791
|
+
* ```sql
|
|
1792
|
+
* create table
|
|
1793
|
+
* characters (id int8 primary key, name text);
|
|
1794
|
+
*
|
|
1795
|
+
* insert into
|
|
1796
|
+
* characters (id, name)
|
|
1797
|
+
* values
|
|
1798
|
+
* (1, 'Luke'),
|
|
1799
|
+
* (2, 'Leia'),
|
|
1800
|
+
* (3, 'Han');
|
|
1801
|
+
* ```
|
|
1802
|
+
*
|
|
1803
|
+
* @exampleResponse With `select()`
|
|
1804
|
+
* ```json
|
|
1805
|
+
* {
|
|
1806
|
+
* "data": [
|
|
1807
|
+
* {
|
|
1808
|
+
* "name": "Leia"
|
|
1809
|
+
* },
|
|
1810
|
+
* {
|
|
1811
|
+
* "name": "Han"
|
|
1812
|
+
* }
|
|
1813
|
+
* ],
|
|
1814
|
+
* "status": 200,
|
|
1815
|
+
* "statusText": "OK"
|
|
1816
|
+
* }
|
|
1817
|
+
* ```
|
|
1818
|
+
*
|
|
1819
|
+
* @example Use `or` with `and`
|
|
1820
|
+
* ```ts
|
|
1821
|
+
* const { data, error } = await supabase
|
|
1822
|
+
* .from('characters')
|
|
1823
|
+
* .select('name')
|
|
1824
|
+
* .or('id.gt.3,and(id.eq.1,name.eq.Luke)')
|
|
1825
|
+
* ```
|
|
1826
|
+
*
|
|
1827
|
+
* @exampleSql Use `or` with `and`
|
|
1828
|
+
* ```sql
|
|
1829
|
+
* create table
|
|
1830
|
+
* characters (id int8 primary key, name text);
|
|
1831
|
+
*
|
|
1832
|
+
* insert into
|
|
1833
|
+
* characters (id, name)
|
|
1834
|
+
* values
|
|
1835
|
+
* (1, 'Luke'),
|
|
1836
|
+
* (2, 'Leia'),
|
|
1837
|
+
* (3, 'Han');
|
|
1838
|
+
* ```
|
|
1839
|
+
*
|
|
1840
|
+
* @exampleResponse Use `or` with `and`
|
|
1841
|
+
* ```json
|
|
1842
|
+
* {
|
|
1843
|
+
* "data": [
|
|
1844
|
+
* {
|
|
1845
|
+
* "name": "Luke"
|
|
1846
|
+
* }
|
|
1847
|
+
* ],
|
|
1848
|
+
* "status": 200,
|
|
1849
|
+
* "statusText": "OK"
|
|
1850
|
+
* }
|
|
1851
|
+
* ```
|
|
1852
|
+
*
|
|
1853
|
+
* @example Use `or` on referenced tables
|
|
1854
|
+
* ```ts
|
|
1855
|
+
* const { data, error } = await supabase
|
|
1856
|
+
* .from('orchestral_sections')
|
|
1857
|
+
* .select(`
|
|
1858
|
+
* name,
|
|
1859
|
+
* instruments!inner (
|
|
1860
|
+
* name
|
|
1861
|
+
* )
|
|
1862
|
+
* `)
|
|
1863
|
+
* .or('section_id.eq.1,name.eq.guzheng', { referencedTable: 'instruments' })
|
|
1864
|
+
* ```
|
|
1865
|
+
*
|
|
1866
|
+
* @exampleSql Use `or` on referenced tables
|
|
1867
|
+
* ```sql
|
|
1868
|
+
* create table
|
|
1869
|
+
* orchestral_sections (id int8 primary key, name text);
|
|
1870
|
+
* create table
|
|
1871
|
+
* instruments (
|
|
1872
|
+
* id int8 primary key,
|
|
1873
|
+
* section_id int8 not null references orchestral_sections,
|
|
1874
|
+
* name text
|
|
1875
|
+
* );
|
|
1876
|
+
*
|
|
1877
|
+
* insert into
|
|
1878
|
+
* orchestral_sections (id, name)
|
|
1879
|
+
* values
|
|
1880
|
+
* (1, 'strings'),
|
|
1881
|
+
* (2, 'woodwinds');
|
|
1882
|
+
* insert into
|
|
1883
|
+
* instruments (id, section_id, name)
|
|
1884
|
+
* values
|
|
1885
|
+
* (1, 2, 'flute'),
|
|
1886
|
+
* (2, 1, 'violin');
|
|
1887
|
+
* ```
|
|
1888
|
+
*
|
|
1889
|
+
* @exampleResponse Use `or` on referenced tables
|
|
1890
|
+
* ```json
|
|
1891
|
+
* {
|
|
1892
|
+
* "data": [
|
|
1893
|
+
* {
|
|
1894
|
+
* "name": "strings",
|
|
1895
|
+
* "instruments": [
|
|
1896
|
+
* {
|
|
1897
|
+
* "name": "violin"
|
|
1898
|
+
* }
|
|
1899
|
+
* ]
|
|
1900
|
+
* }
|
|
1901
|
+
* ],
|
|
1902
|
+
* "status": 200,
|
|
1903
|
+
* "statusText": "OK"
|
|
1904
|
+
* }
|
|
1905
|
+
* ```
|
|
1127
1906
|
*/
|
|
1128
1907
|
or(filters: string, {
|
|
1129
1908
|
foreignTable,
|
|
@@ -1151,7 +1930,19 @@ declare class PostgrestQueryBuilder<ClientOptions extends ClientServerOptions, S
|
|
|
1151
1930
|
*
|
|
1152
1931
|
* @example
|
|
1153
1932
|
* ```ts
|
|
1154
|
-
* import PostgrestQueryBuilder from '@supabase/postgrest-js'
|
|
1933
|
+
* import { PostgrestQueryBuilder } from '@supabase/postgrest-js'
|
|
1934
|
+
*
|
|
1935
|
+
* const query = new PostgrestQueryBuilder(
|
|
1936
|
+
* new URL('https://xyzcompany.supabase.co/rest/v1/users'),
|
|
1937
|
+
* { headers: { apikey: 'public-anon-key' } }
|
|
1938
|
+
* )
|
|
1939
|
+
* ```
|
|
1940
|
+
*
|
|
1941
|
+
* @category Database
|
|
1942
|
+
*
|
|
1943
|
+
* @example Example 1
|
|
1944
|
+
* ```ts
|
|
1945
|
+
* import { PostgrestQueryBuilder } from '@supabase/postgrest-js'
|
|
1155
1946
|
*
|
|
1156
1947
|
* const query = new PostgrestQueryBuilder(
|
|
1157
1948
|
* new URL('https://xyzcompany.supabase.co/rest/v1/users'),
|
|
@@ -2147,6 +2938,105 @@ declare class PostgrestQueryBuilder<ClientOptions extends ClientServerOptions, S
|
|
|
2147
2938
|
*
|
|
2148
2939
|
* `"estimated"`: Uses exact count for low numbers and planned count for high
|
|
2149
2940
|
* numbers.
|
|
2941
|
+
*
|
|
2942
|
+
* @category Database
|
|
2943
|
+
*
|
|
2944
|
+
* @remarks
|
|
2945
|
+
* - `delete()` should always be combined with [filters](/docs/reference/javascript/using-filters) to target the item(s) you wish to delete.
|
|
2946
|
+
* - If you use `delete()` with filters and you have
|
|
2947
|
+
* [RLS](/docs/learn/auth-deep-dive/auth-row-level-security) enabled, only
|
|
2948
|
+
* rows visible through `SELECT` policies are deleted. Note that by default
|
|
2949
|
+
* no rows are visible, so you need at least one `SELECT`/`ALL` policy that
|
|
2950
|
+
* makes the rows visible.
|
|
2951
|
+
* - When using `delete().in()`, specify an array of values to target multiple rows with a single query. This is particularly useful for batch deleting entries that share common criteria, such as deleting users by their IDs. Ensure that the array you provide accurately represents all records you intend to delete to avoid unintended data removal.
|
|
2952
|
+
*
|
|
2953
|
+
* @example Delete a single record
|
|
2954
|
+
* ```ts
|
|
2955
|
+
* const response = await supabase
|
|
2956
|
+
* .from('countries')
|
|
2957
|
+
* .delete()
|
|
2958
|
+
* .eq('id', 1)
|
|
2959
|
+
* ```
|
|
2960
|
+
*
|
|
2961
|
+
* @exampleSql Delete a single record
|
|
2962
|
+
* ```sql
|
|
2963
|
+
* create table
|
|
2964
|
+
* countries (id int8 primary key, name text);
|
|
2965
|
+
*
|
|
2966
|
+
* insert into
|
|
2967
|
+
* countries (id, name)
|
|
2968
|
+
* values
|
|
2969
|
+
* (1, 'Mordor');
|
|
2970
|
+
* ```
|
|
2971
|
+
*
|
|
2972
|
+
* @exampleResponse Delete a single record
|
|
2973
|
+
* ```json
|
|
2974
|
+
* {
|
|
2975
|
+
* "status": 204,
|
|
2976
|
+
* "statusText": "No Content"
|
|
2977
|
+
* }
|
|
2978
|
+
* ```
|
|
2979
|
+
*
|
|
2980
|
+
* @example Delete a record and return it
|
|
2981
|
+
* ```ts
|
|
2982
|
+
* const { data, error } = await supabase
|
|
2983
|
+
* .from('countries')
|
|
2984
|
+
* .delete()
|
|
2985
|
+
* .eq('id', 1)
|
|
2986
|
+
* .select()
|
|
2987
|
+
* ```
|
|
2988
|
+
*
|
|
2989
|
+
* @exampleSql Delete a record and return it
|
|
2990
|
+
* ```sql
|
|
2991
|
+
* create table
|
|
2992
|
+
* countries (id int8 primary key, name text);
|
|
2993
|
+
*
|
|
2994
|
+
* insert into
|
|
2995
|
+
* countries (id, name)
|
|
2996
|
+
* values
|
|
2997
|
+
* (1, 'Mordor');
|
|
2998
|
+
* ```
|
|
2999
|
+
*
|
|
3000
|
+
* @exampleResponse Delete a record and return it
|
|
3001
|
+
* ```json
|
|
3002
|
+
* {
|
|
3003
|
+
* "data": [
|
|
3004
|
+
* {
|
|
3005
|
+
* "id": 1,
|
|
3006
|
+
* "name": "Mordor"
|
|
3007
|
+
* }
|
|
3008
|
+
* ],
|
|
3009
|
+
* "status": 200,
|
|
3010
|
+
* "statusText": "OK"
|
|
3011
|
+
* }
|
|
3012
|
+
* ```
|
|
3013
|
+
*
|
|
3014
|
+
* @example Delete multiple records
|
|
3015
|
+
* ```ts
|
|
3016
|
+
* const response = await supabase
|
|
3017
|
+
* .from('countries')
|
|
3018
|
+
* .delete()
|
|
3019
|
+
* .in('id', [1, 2, 3])
|
|
3020
|
+
* ```
|
|
3021
|
+
*
|
|
3022
|
+
* @exampleSql Delete multiple records
|
|
3023
|
+
* ```sql
|
|
3024
|
+
* create table
|
|
3025
|
+
* countries (id int8 primary key, name text);
|
|
3026
|
+
*
|
|
3027
|
+
* insert into
|
|
3028
|
+
* countries (id, name)
|
|
3029
|
+
* values
|
|
3030
|
+
* (1, 'Rohan'), (2, 'The Shire'), (3, 'Mordor');
|
|
3031
|
+
* ```
|
|
3032
|
+
*
|
|
3033
|
+
* @exampleResponse Delete multiple records
|
|
3034
|
+
* ```json
|
|
3035
|
+
* {
|
|
3036
|
+
* "status": 204,
|
|
3037
|
+
* "statusText": "No Content"
|
|
3038
|
+
* }
|
|
3039
|
+
* ```
|
|
2150
3040
|
*/
|
|
2151
3041
|
delete({
|
|
2152
3042
|
count
|
|
@@ -2225,7 +3115,34 @@ declare class PostgrestClient<Database = any, ClientOptions extends ClientServer
|
|
|
2225
3115
|
* @param options.urlLengthLimit - Maximum URL length in characters before warnings/errors are triggered. Defaults to 8000.
|
|
2226
3116
|
* @example
|
|
2227
3117
|
* ```ts
|
|
2228
|
-
* import PostgrestClient from '@supabase/postgrest-js'
|
|
3118
|
+
* import { PostgrestClient } from '@supabase/postgrest-js'
|
|
3119
|
+
*
|
|
3120
|
+
* const postgrest = new PostgrestClient('https://xyzcompany.supabase.co/rest/v1', {
|
|
3121
|
+
* headers: { apikey: 'public-anon-key' },
|
|
3122
|
+
* schema: 'public',
|
|
3123
|
+
* timeout: 30000, // 30 second timeout
|
|
3124
|
+
* })
|
|
3125
|
+
* ```
|
|
3126
|
+
*
|
|
3127
|
+
* @category Database
|
|
3128
|
+
*
|
|
3129
|
+
* @remarks
|
|
3130
|
+
* - A `timeout` option (in milliseconds) can be set to automatically abort requests that take too long.
|
|
3131
|
+
* - A `urlLengthLimit` option (default: 8000) can be set to control when URL length warnings are included in error messages for aborted requests.
|
|
3132
|
+
*
|
|
3133
|
+
* @example Example 1
|
|
3134
|
+
* ```ts
|
|
3135
|
+
* import { PostgrestClient } from '@supabase/postgrest-js'
|
|
3136
|
+
*
|
|
3137
|
+
* const postgrest = new PostgrestClient('https://xyzcompany.supabase.co/rest/v1', {
|
|
3138
|
+
* headers: { apikey: 'public-anon-key' },
|
|
3139
|
+
* schema: 'public',
|
|
3140
|
+
* })
|
|
3141
|
+
* ```
|
|
3142
|
+
*
|
|
3143
|
+
* @example With timeout
|
|
3144
|
+
* ```ts
|
|
3145
|
+
* import { PostgrestClient } from '@supabase/postgrest-js'
|
|
2229
3146
|
*
|
|
2230
3147
|
* const postgrest = new PostgrestClient('https://xyzcompany.supabase.co/rest/v1', {
|
|
2231
3148
|
* headers: { apikey: 'public-anon-key' },
|
|
@@ -2255,6 +3172,8 @@ declare class PostgrestClient<Database = any, ClientOptions extends ClientServer
|
|
|
2255
3172
|
* The schema needs to be on the list of exposed schemas inside Supabase.
|
|
2256
3173
|
*
|
|
2257
3174
|
* @param schema - The schema to query
|
|
3175
|
+
*
|
|
3176
|
+
* @category Database
|
|
2258
3177
|
*/
|
|
2259
3178
|
schema<DynamicSchema extends string & keyof Omit<Database, '__InternalSupabase'>>(schema: DynamicSchema): PostgrestClient<Database, ClientOptions, DynamicSchema, Database[DynamicSchema] extends GenericSchema ? Database[DynamicSchema] : any>;
|
|
2260
3179
|
/**
|
|
@@ -2288,6 +3207,139 @@ declare class PostgrestClient<Database = any, ClientOptions extends ClientServer
|
|
|
2288
3207
|
* .rpc('function_a', {})
|
|
2289
3208
|
* .overrideTypes<{ id: string; user_id: string }[]>()
|
|
2290
3209
|
* ```
|
|
3210
|
+
*
|
|
3211
|
+
* @category Database
|
|
3212
|
+
*
|
|
3213
|
+
* @example Call a Postgres function without arguments
|
|
3214
|
+
* ```ts
|
|
3215
|
+
* const { data, error } = await supabase.rpc('hello_world')
|
|
3216
|
+
* ```
|
|
3217
|
+
*
|
|
3218
|
+
* @exampleSql Call a Postgres function without arguments
|
|
3219
|
+
* ```sql
|
|
3220
|
+
* create function hello_world() returns text as $$
|
|
3221
|
+
* select 'Hello world';
|
|
3222
|
+
* $$ language sql;
|
|
3223
|
+
* ```
|
|
3224
|
+
*
|
|
3225
|
+
* @exampleResponse Call a Postgres function without arguments
|
|
3226
|
+
* ```json
|
|
3227
|
+
* {
|
|
3228
|
+
* "data": "Hello world",
|
|
3229
|
+
* "status": 200,
|
|
3230
|
+
* "statusText": "OK"
|
|
3231
|
+
* }
|
|
3232
|
+
* ```
|
|
3233
|
+
*
|
|
3234
|
+
* @example Call a Postgres function with arguments
|
|
3235
|
+
* ```ts
|
|
3236
|
+
* const { data, error } = await supabase.rpc('echo', { say: '👋' })
|
|
3237
|
+
* ```
|
|
3238
|
+
*
|
|
3239
|
+
* @exampleSql Call a Postgres function with arguments
|
|
3240
|
+
* ```sql
|
|
3241
|
+
* create function echo(say text) returns text as $$
|
|
3242
|
+
* select say;
|
|
3243
|
+
* $$ language sql;
|
|
3244
|
+
* ```
|
|
3245
|
+
*
|
|
3246
|
+
* @exampleResponse Call a Postgres function with arguments
|
|
3247
|
+
* ```json
|
|
3248
|
+
* {
|
|
3249
|
+
* "data": "👋",
|
|
3250
|
+
* "status": 200,
|
|
3251
|
+
* "statusText": "OK"
|
|
3252
|
+
* }
|
|
3253
|
+
*
|
|
3254
|
+
* ```
|
|
3255
|
+
*
|
|
3256
|
+
* @exampleDescription Bulk processing
|
|
3257
|
+
* You can process large payloads by passing in an array as an argument.
|
|
3258
|
+
*
|
|
3259
|
+
* @example Bulk processing
|
|
3260
|
+
* ```ts
|
|
3261
|
+
* const { data, error } = await supabase.rpc('add_one_each', { arr: [1, 2, 3] })
|
|
3262
|
+
* ```
|
|
3263
|
+
*
|
|
3264
|
+
* @exampleSql Bulk processing
|
|
3265
|
+
* ```sql
|
|
3266
|
+
* create function add_one_each(arr int[]) returns int[] as $$
|
|
3267
|
+
* select array_agg(n + 1) from unnest(arr) as n;
|
|
3268
|
+
* $$ language sql;
|
|
3269
|
+
* ```
|
|
3270
|
+
*
|
|
3271
|
+
* @exampleResponse Bulk processing
|
|
3272
|
+
* ```json
|
|
3273
|
+
* {
|
|
3274
|
+
* "data": [
|
|
3275
|
+
* 2,
|
|
3276
|
+
* 3,
|
|
3277
|
+
* 4
|
|
3278
|
+
* ],
|
|
3279
|
+
* "status": 200,
|
|
3280
|
+
* "statusText": "OK"
|
|
3281
|
+
* }
|
|
3282
|
+
* ```
|
|
3283
|
+
*
|
|
3284
|
+
* @exampleDescription Call a Postgres function with filters
|
|
3285
|
+
* Postgres functions that return tables can also be combined with [Filters](/docs/reference/javascript/using-filters) and [Modifiers](/docs/reference/javascript/using-modifiers).
|
|
3286
|
+
*
|
|
3287
|
+
* @example Call a Postgres function with filters
|
|
3288
|
+
* ```ts
|
|
3289
|
+
* const { data, error } = await supabase
|
|
3290
|
+
* .rpc('list_stored_countries')
|
|
3291
|
+
* .eq('id', 1)
|
|
3292
|
+
* .single()
|
|
3293
|
+
* ```
|
|
3294
|
+
*
|
|
3295
|
+
* @exampleSql Call a Postgres function with filters
|
|
3296
|
+
* ```sql
|
|
3297
|
+
* create table
|
|
3298
|
+
* countries (id int8 primary key, name text);
|
|
3299
|
+
*
|
|
3300
|
+
* insert into
|
|
3301
|
+
* countries (id, name)
|
|
3302
|
+
* values
|
|
3303
|
+
* (1, 'Rohan'),
|
|
3304
|
+
* (2, 'The Shire');
|
|
3305
|
+
*
|
|
3306
|
+
* create function list_stored_countries() returns setof countries as $$
|
|
3307
|
+
* select * from countries;
|
|
3308
|
+
* $$ language sql;
|
|
3309
|
+
* ```
|
|
3310
|
+
*
|
|
3311
|
+
* @exampleResponse Call a Postgres function with filters
|
|
3312
|
+
* ```json
|
|
3313
|
+
* {
|
|
3314
|
+
* "data": {
|
|
3315
|
+
* "id": 1,
|
|
3316
|
+
* "name": "Rohan"
|
|
3317
|
+
* },
|
|
3318
|
+
* "status": 200,
|
|
3319
|
+
* "statusText": "OK"
|
|
3320
|
+
* }
|
|
3321
|
+
* ```
|
|
3322
|
+
*
|
|
3323
|
+
* @example Call a read-only Postgres function
|
|
3324
|
+
* ```ts
|
|
3325
|
+
* const { data, error } = await supabase.rpc('hello_world', undefined, { get: true })
|
|
3326
|
+
* ```
|
|
3327
|
+
*
|
|
3328
|
+
* @exampleSql Call a read-only Postgres function
|
|
3329
|
+
* ```sql
|
|
3330
|
+
* create function hello_world() returns text as $$
|
|
3331
|
+
* select 'Hello world';
|
|
3332
|
+
* $$ language sql;
|
|
3333
|
+
* ```
|
|
3334
|
+
*
|
|
3335
|
+
* @exampleResponse Call a read-only Postgres function
|
|
3336
|
+
* ```json
|
|
3337
|
+
* {
|
|
3338
|
+
* "data": "Hello world",
|
|
3339
|
+
* "status": 200,
|
|
3340
|
+
* "statusText": "OK"
|
|
3341
|
+
* }
|
|
3342
|
+
* ```
|
|
2291
3343
|
*/
|
|
2292
3344
|
rpc<FnName extends string & keyof Schema['Functions'], Args extends Schema['Functions'][FnName]['Args'] = never, FilterBuilder extends GetRpcFunctionFilterBuilderByArgs<Schema, FnName, Args> = GetRpcFunctionFilterBuilderByArgs<Schema, FnName, Args>>(fn: FnName, args?: Args, {
|
|
2293
3345
|
head,
|