@supabase/postgrest-js 2.100.0-rc.0 → 2.100.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 +2478 -151
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1052 -10
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1052 -10
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2478 -151
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/PostgrestBuilder.ts +95 -10
- package/src/PostgrestClient.ts +165 -1
- package/src/PostgrestFilterBuilder.ts +1402 -14
- package/src/PostgrestQueryBuilder.ts +103 -2
- package/src/PostgrestTransformBuilder.ts +605 -7
- package/src/select-query-parser/utils.ts +9 -7
- package/src/version.ts +1 -1
package/dist/index.cjs
CHANGED
|
@@ -37,7 +37,19 @@ var PostgrestBuilder = class {
|
|
|
37
37
|
*
|
|
38
38
|
* @example
|
|
39
39
|
* ```ts
|
|
40
|
-
* import PostgrestQueryBuilder from '@supabase/postgrest-js'
|
|
40
|
+
* import { PostgrestQueryBuilder } from '@supabase/postgrest-js'
|
|
41
|
+
*
|
|
42
|
+
* const builder = new PostgrestQueryBuilder(
|
|
43
|
+
* new URL('https://xyzcompany.supabase.co/rest/v1/users'),
|
|
44
|
+
* { headers: new Headers({ apikey: 'public-anon-key' }) }
|
|
45
|
+
* )
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @category Database
|
|
49
|
+
*
|
|
50
|
+
* @example Creating a Postgrest query builder
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { PostgrestQueryBuilder } from '@supabase/postgrest-js'
|
|
41
53
|
*
|
|
42
54
|
* const builder = new PostgrestQueryBuilder(
|
|
43
55
|
* new URL('https://xyzcompany.supabase.co/rest/v1/users'),
|
|
@@ -65,6 +77,8 @@ var PostgrestBuilder = class {
|
|
|
65
77
|
* throwing the error instead of returning it as part of a successful response.
|
|
66
78
|
*
|
|
67
79
|
* {@link https://github.com/supabase/supabase-js/issues/92}
|
|
80
|
+
*
|
|
81
|
+
* @category Database
|
|
68
82
|
*/
|
|
69
83
|
throwOnError() {
|
|
70
84
|
this.shouldThrowOnError = true;
|
|
@@ -72,12 +86,17 @@ var PostgrestBuilder = class {
|
|
|
72
86
|
}
|
|
73
87
|
/**
|
|
74
88
|
* Set an HTTP header for the request.
|
|
89
|
+
*
|
|
90
|
+
* @category Database
|
|
75
91
|
*/
|
|
76
92
|
setHeader(name, value) {
|
|
77
93
|
this.headers = new Headers(this.headers);
|
|
78
94
|
this.headers.set(name, value);
|
|
79
95
|
return this;
|
|
80
96
|
}
|
|
97
|
+
/** *
|
|
98
|
+
* @category Database
|
|
99
|
+
*/
|
|
81
100
|
then(onfulfilled, onrejected) {
|
|
82
101
|
var _this = this;
|
|
83
102
|
if (this.schema === void 0) {} else if (["GET", "HEAD"].includes(this.method)) this.headers.set("Accept-Profile", this.schema);
|
|
@@ -107,7 +126,7 @@ var PostgrestBuilder = class {
|
|
|
107
126
|
const countHeader = (_this$headers$get2 = _this.headers.get("Prefer")) === null || _this$headers$get2 === void 0 ? void 0 : _this$headers$get2.match(/count=(exact|planned|estimated)/);
|
|
108
127
|
const contentRange = (_res$headers$get = res$1.headers.get("content-range")) === null || _res$headers$get === void 0 ? void 0 : _res$headers$get.split("/");
|
|
109
128
|
if (countHeader && contentRange && contentRange.length > 1) count = parseInt(contentRange[1]);
|
|
110
|
-
if (_this.isMaybeSingle &&
|
|
129
|
+
if (_this.isMaybeSingle && Array.isArray(data)) if (data.length > 1) {
|
|
111
130
|
error = {
|
|
112
131
|
code: "PGRST116",
|
|
113
132
|
details: `Results contain ${data.length} rows, application/vnd.pgrst.object+json requires 1 row`,
|
|
@@ -121,7 +140,6 @@ var PostgrestBuilder = class {
|
|
|
121
140
|
} else if (data.length === 1) data = data[0];
|
|
122
141
|
else data = null;
|
|
123
142
|
} else {
|
|
124
|
-
var _error$details;
|
|
125
143
|
const body = await res$1.text();
|
|
126
144
|
try {
|
|
127
145
|
error = JSON.parse(body);
|
|
@@ -137,11 +155,6 @@ var PostgrestBuilder = class {
|
|
|
137
155
|
statusText = "No Content";
|
|
138
156
|
} else error = { message: body };
|
|
139
157
|
}
|
|
140
|
-
if (error && _this.isMaybeSingle && (error === null || error === void 0 || (_error$details = error.details) === null || _error$details === void 0 ? void 0 : _error$details.includes("0 rows"))) {
|
|
141
|
-
error = null;
|
|
142
|
-
status = 200;
|
|
143
|
-
statusText = "OK";
|
|
144
|
-
}
|
|
145
158
|
if (error && _this.shouldThrowOnError) throw new PostgrestError(error);
|
|
146
159
|
}
|
|
147
160
|
return {
|
|
@@ -200,6 +213,8 @@ var PostgrestBuilder = class {
|
|
|
200
213
|
*
|
|
201
214
|
* @typeParam NewResult - The new result type to override with
|
|
202
215
|
* @deprecated Use overrideTypes<yourType, { merge: false }>() method at the end of your call chain instead
|
|
216
|
+
*
|
|
217
|
+
* @category Database
|
|
203
218
|
*/
|
|
204
219
|
returns() {
|
|
205
220
|
/* istanbul ignore next */
|
|
@@ -226,6 +241,77 @@ var PostgrestBuilder = class {
|
|
|
226
241
|
* .overrideTypes<{ id: number; name: string }, { merge: false }>()
|
|
227
242
|
* ```
|
|
228
243
|
* @returns A PostgrestBuilder instance with the new type
|
|
244
|
+
*
|
|
245
|
+
* @category Database
|
|
246
|
+
*
|
|
247
|
+
* @example Complete Override type of successful response
|
|
248
|
+
* ```ts
|
|
249
|
+
* const { data } = await supabase
|
|
250
|
+
* .from('countries')
|
|
251
|
+
* .select()
|
|
252
|
+
* .overrideTypes<Array<MyType>, { merge: false }>()
|
|
253
|
+
* ```
|
|
254
|
+
*
|
|
255
|
+
* @exampleResponse Complete Override type of successful response
|
|
256
|
+
* ```ts
|
|
257
|
+
* let x: typeof data // MyType[]
|
|
258
|
+
* ```
|
|
259
|
+
*
|
|
260
|
+
* @example Complete Override type of object response
|
|
261
|
+
* ```ts
|
|
262
|
+
* const { data } = await supabase
|
|
263
|
+
* .from('countries')
|
|
264
|
+
* .select()
|
|
265
|
+
* .maybeSingle()
|
|
266
|
+
* .overrideTypes<MyType, { merge: false }>()
|
|
267
|
+
* ```
|
|
268
|
+
*
|
|
269
|
+
* @exampleResponse Complete Override type of object response
|
|
270
|
+
* ```ts
|
|
271
|
+
* let x: typeof data // MyType | null
|
|
272
|
+
* ```
|
|
273
|
+
*
|
|
274
|
+
* @example Partial Override type of successful response
|
|
275
|
+
* ```ts
|
|
276
|
+
* const { data } = await supabase
|
|
277
|
+
* .from('countries')
|
|
278
|
+
* .select()
|
|
279
|
+
* .overrideTypes<Array<{ status: "A" | "B" }>>()
|
|
280
|
+
* ```
|
|
281
|
+
*
|
|
282
|
+
* @exampleResponse Partial Override type of successful response
|
|
283
|
+
* ```ts
|
|
284
|
+
* let x: typeof data // Array<CountryRowProperties & { status: "A" | "B" }>
|
|
285
|
+
* ```
|
|
286
|
+
*
|
|
287
|
+
* @example Partial Override type of object response
|
|
288
|
+
* ```ts
|
|
289
|
+
* const { data } = await supabase
|
|
290
|
+
* .from('countries')
|
|
291
|
+
* .select()
|
|
292
|
+
* .maybeSingle()
|
|
293
|
+
* .overrideTypes<{ status: "A" | "B" }>()
|
|
294
|
+
* ```
|
|
295
|
+
*
|
|
296
|
+
* @exampleResponse Partial Override type of object response
|
|
297
|
+
* ```ts
|
|
298
|
+
* let x: typeof data // CountryRowProperties & { status: "A" | "B" } | null
|
|
299
|
+
* ```
|
|
300
|
+
*
|
|
301
|
+
* @example Example 5
|
|
302
|
+
* ```typescript
|
|
303
|
+
* // Merge with existing types (default behavior)
|
|
304
|
+
* const query = supabase
|
|
305
|
+
* .from('users')
|
|
306
|
+
* .select()
|
|
307
|
+
* .overrideTypes<{ custom_field: string }>()
|
|
308
|
+
*
|
|
309
|
+
* // Replace existing types completely
|
|
310
|
+
* const replaceQuery = supabase
|
|
311
|
+
* .from('users')
|
|
312
|
+
* .select()
|
|
313
|
+
* .overrideTypes<{ id: number; name: string }, { merge: false }>()
|
|
314
|
+
* ```
|
|
229
315
|
*/
|
|
230
316
|
overrideTypes() {
|
|
231
317
|
return this;
|
|
@@ -243,6 +329,41 @@ var PostgrestTransformBuilder = class extends PostgrestBuilder {
|
|
|
243
329
|
* `data`.
|
|
244
330
|
*
|
|
245
331
|
* @param columns - The columns to retrieve, separated by commas
|
|
332
|
+
*
|
|
333
|
+
* @category Database
|
|
334
|
+
*
|
|
335
|
+
* @example With `upsert()`
|
|
336
|
+
* ```ts
|
|
337
|
+
* const { data, error } = await supabase
|
|
338
|
+
* .from('characters')
|
|
339
|
+
* .upsert({ id: 1, name: 'Han Solo' })
|
|
340
|
+
* .select()
|
|
341
|
+
* ```
|
|
342
|
+
*
|
|
343
|
+
* @exampleSql With `upsert()`
|
|
344
|
+
* ```sql
|
|
345
|
+
* create table
|
|
346
|
+
* characters (id int8 primary key, name text);
|
|
347
|
+
*
|
|
348
|
+
* insert into
|
|
349
|
+
* characters (id, name)
|
|
350
|
+
* values
|
|
351
|
+
* (1, 'Han');
|
|
352
|
+
* ```
|
|
353
|
+
*
|
|
354
|
+
* @exampleResponse With `upsert()`
|
|
355
|
+
* ```json
|
|
356
|
+
* {
|
|
357
|
+
* "data": [
|
|
358
|
+
* {
|
|
359
|
+
* "id": 1,
|
|
360
|
+
* "name": "Han Solo"
|
|
361
|
+
* }
|
|
362
|
+
* ],
|
|
363
|
+
* "status": 201,
|
|
364
|
+
* "statusText": "Created"
|
|
365
|
+
* }
|
|
366
|
+
* ```
|
|
246
367
|
*/
|
|
247
368
|
select(columns) {
|
|
248
369
|
let quoted = false;
|
|
@@ -272,6 +393,176 @@ var PostgrestTransformBuilder = class extends PostgrestBuilder {
|
|
|
272
393
|
* its columns
|
|
273
394
|
* @param options.foreignTable - Deprecated, use `options.referencedTable`
|
|
274
395
|
* instead
|
|
396
|
+
*
|
|
397
|
+
* @category Database
|
|
398
|
+
*
|
|
399
|
+
* @example With `select()`
|
|
400
|
+
* ```ts
|
|
401
|
+
* const { data, error } = await supabase
|
|
402
|
+
* .from('characters')
|
|
403
|
+
* .select('id, name')
|
|
404
|
+
* .order('id', { ascending: false })
|
|
405
|
+
* ```
|
|
406
|
+
*
|
|
407
|
+
* @exampleSql With `select()`
|
|
408
|
+
* ```sql
|
|
409
|
+
* create table
|
|
410
|
+
* characters (id int8 primary key, name text);
|
|
411
|
+
*
|
|
412
|
+
* insert into
|
|
413
|
+
* characters (id, name)
|
|
414
|
+
* values
|
|
415
|
+
* (1, 'Luke'),
|
|
416
|
+
* (2, 'Leia'),
|
|
417
|
+
* (3, 'Han');
|
|
418
|
+
* ```
|
|
419
|
+
*
|
|
420
|
+
* @exampleResponse With `select()`
|
|
421
|
+
* ```json
|
|
422
|
+
* {
|
|
423
|
+
* "data": [
|
|
424
|
+
* {
|
|
425
|
+
* "id": 3,
|
|
426
|
+
* "name": "Han"
|
|
427
|
+
* },
|
|
428
|
+
* {
|
|
429
|
+
* "id": 2,
|
|
430
|
+
* "name": "Leia"
|
|
431
|
+
* },
|
|
432
|
+
* {
|
|
433
|
+
* "id": 1,
|
|
434
|
+
* "name": "Luke"
|
|
435
|
+
* }
|
|
436
|
+
* ],
|
|
437
|
+
* "status": 200,
|
|
438
|
+
* "statusText": "OK"
|
|
439
|
+
* }
|
|
440
|
+
* ```
|
|
441
|
+
*
|
|
442
|
+
* @exampleDescription On a referenced table
|
|
443
|
+
* Ordering with `referencedTable` doesn't affect the ordering of the
|
|
444
|
+
* parent table.
|
|
445
|
+
*
|
|
446
|
+
* @example On a referenced table
|
|
447
|
+
* ```ts
|
|
448
|
+
* const { data, error } = await supabase
|
|
449
|
+
* .from('orchestral_sections')
|
|
450
|
+
* .select(`
|
|
451
|
+
* name,
|
|
452
|
+
* instruments (
|
|
453
|
+
* name
|
|
454
|
+
* )
|
|
455
|
+
* `)
|
|
456
|
+
* .order('name', { referencedTable: 'instruments', ascending: false })
|
|
457
|
+
*
|
|
458
|
+
* ```
|
|
459
|
+
*
|
|
460
|
+
* @exampleSql On a referenced table
|
|
461
|
+
* ```sql
|
|
462
|
+
* create table
|
|
463
|
+
* orchestral_sections (id int8 primary key, name text);
|
|
464
|
+
* create table
|
|
465
|
+
* instruments (
|
|
466
|
+
* id int8 primary key,
|
|
467
|
+
* section_id int8 not null references orchestral_sections,
|
|
468
|
+
* name text
|
|
469
|
+
* );
|
|
470
|
+
*
|
|
471
|
+
* insert into
|
|
472
|
+
* orchestral_sections (id, name)
|
|
473
|
+
* values
|
|
474
|
+
* (1, 'strings'),
|
|
475
|
+
* (2, 'woodwinds');
|
|
476
|
+
* insert into
|
|
477
|
+
* instruments (id, section_id, name)
|
|
478
|
+
* values
|
|
479
|
+
* (1, 1, 'harp'),
|
|
480
|
+
* (2, 1, 'violin');
|
|
481
|
+
* ```
|
|
482
|
+
*
|
|
483
|
+
* @exampleResponse On a referenced table
|
|
484
|
+
* ```json
|
|
485
|
+
* {
|
|
486
|
+
* "data": [
|
|
487
|
+
* {
|
|
488
|
+
* "name": "strings",
|
|
489
|
+
* "instruments": [
|
|
490
|
+
* {
|
|
491
|
+
* "name": "violin"
|
|
492
|
+
* },
|
|
493
|
+
* {
|
|
494
|
+
* "name": "harp"
|
|
495
|
+
* }
|
|
496
|
+
* ]
|
|
497
|
+
* },
|
|
498
|
+
* {
|
|
499
|
+
* "name": "woodwinds",
|
|
500
|
+
* "instruments": []
|
|
501
|
+
* }
|
|
502
|
+
* ],
|
|
503
|
+
* "status": 200,
|
|
504
|
+
* "statusText": "OK"
|
|
505
|
+
* }
|
|
506
|
+
* ```
|
|
507
|
+
*
|
|
508
|
+
* @exampleDescription Order parent table by a referenced table
|
|
509
|
+
* Ordering with `referenced_table(col)` affects the ordering of the
|
|
510
|
+
* parent table.
|
|
511
|
+
*
|
|
512
|
+
* @example Order parent table by a referenced table
|
|
513
|
+
* ```ts
|
|
514
|
+
* const { data, error } = await supabase
|
|
515
|
+
* .from('instruments')
|
|
516
|
+
* .select(`
|
|
517
|
+
* name,
|
|
518
|
+
* section:orchestral_sections (
|
|
519
|
+
* name
|
|
520
|
+
* )
|
|
521
|
+
* `)
|
|
522
|
+
* .order('section(name)', { ascending: true })
|
|
523
|
+
*
|
|
524
|
+
* ```
|
|
525
|
+
*
|
|
526
|
+
* @exampleSql Order parent table by a referenced table
|
|
527
|
+
* ```sql
|
|
528
|
+
* create table
|
|
529
|
+
* orchestral_sections (id int8 primary key, name text);
|
|
530
|
+
* create table
|
|
531
|
+
* instruments (
|
|
532
|
+
* id int8 primary key,
|
|
533
|
+
* section_id int8 not null references orchestral_sections,
|
|
534
|
+
* name text
|
|
535
|
+
* );
|
|
536
|
+
*
|
|
537
|
+
* insert into
|
|
538
|
+
* orchestral_sections (id, name)
|
|
539
|
+
* values
|
|
540
|
+
* (1, 'strings'),
|
|
541
|
+
* (2, 'woodwinds');
|
|
542
|
+
* insert into
|
|
543
|
+
* instruments (id, section_id, name)
|
|
544
|
+
* values
|
|
545
|
+
* (1, 2, 'flute'),
|
|
546
|
+
* (2, 1, 'violin');
|
|
547
|
+
* ```
|
|
548
|
+
*
|
|
549
|
+
* @exampleResponse Order parent table by a referenced table
|
|
550
|
+
* ```json
|
|
551
|
+
* {
|
|
552
|
+
* "data": [
|
|
553
|
+
* {
|
|
554
|
+
* "name": "violin",
|
|
555
|
+
* "orchestral_sections": {"name": "strings"}
|
|
556
|
+
* },
|
|
557
|
+
* {
|
|
558
|
+
* "name": "flute",
|
|
559
|
+
* "orchestral_sections": {"name": "woodwinds"}
|
|
560
|
+
* }
|
|
561
|
+
* ],
|
|
562
|
+
* "status": 200,
|
|
563
|
+
* "statusText": "OK"
|
|
564
|
+
* }
|
|
565
|
+
* ```
|
|
275
566
|
*/
|
|
276
567
|
order(column, { ascending = true, nullsFirst, foreignTable, referencedTable = foreignTable } = {}) {
|
|
277
568
|
const key = referencedTable ? `${referencedTable}.order` : "order";
|
|
@@ -288,28 +579,156 @@ var PostgrestTransformBuilder = class extends PostgrestBuilder {
|
|
|
288
579
|
* tables instead of the parent table
|
|
289
580
|
* @param options.foreignTable - Deprecated, use `options.referencedTable`
|
|
290
581
|
* instead
|
|
291
|
-
*/
|
|
292
|
-
limit(count, { foreignTable, referencedTable = foreignTable } = {}) {
|
|
293
|
-
const key = typeof referencedTable === "undefined" ? "limit" : `${referencedTable}.limit`;
|
|
294
|
-
this.url.searchParams.set(key, `${count}`);
|
|
295
|
-
return this;
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Limit the query result by starting at an offset `from` and ending at the offset `to`.
|
|
299
|
-
* Only records within this range are returned.
|
|
300
|
-
* This respects the query order and if there is no order clause the range could behave unexpectedly.
|
|
301
|
-
* The `from` and `to` values are 0-based and inclusive: `range(1, 3)` will include the second, third
|
|
302
|
-
* and fourth rows of the query.
|
|
303
582
|
*
|
|
304
|
-
* @
|
|
305
|
-
*
|
|
306
|
-
* @
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
|
|
312
|
-
|
|
583
|
+
* @category Database
|
|
584
|
+
*
|
|
585
|
+
* @example With `select()`
|
|
586
|
+
* ```ts
|
|
587
|
+
* const { data, error } = await supabase
|
|
588
|
+
* .from('characters')
|
|
589
|
+
* .select('name')
|
|
590
|
+
* .limit(1)
|
|
591
|
+
* ```
|
|
592
|
+
*
|
|
593
|
+
* @exampleSql With `select()`
|
|
594
|
+
* ```sql
|
|
595
|
+
* create table
|
|
596
|
+
* characters (id int8 primary key, name text);
|
|
597
|
+
*
|
|
598
|
+
* insert into
|
|
599
|
+
* characters (id, name)
|
|
600
|
+
* values
|
|
601
|
+
* (1, 'Luke'),
|
|
602
|
+
* (2, 'Leia'),
|
|
603
|
+
* (3, 'Han');
|
|
604
|
+
* ```
|
|
605
|
+
*
|
|
606
|
+
* @exampleResponse With `select()`
|
|
607
|
+
* ```json
|
|
608
|
+
* {
|
|
609
|
+
* "data": [
|
|
610
|
+
* {
|
|
611
|
+
* "name": "Luke"
|
|
612
|
+
* }
|
|
613
|
+
* ],
|
|
614
|
+
* "status": 200,
|
|
615
|
+
* "statusText": "OK"
|
|
616
|
+
* }
|
|
617
|
+
* ```
|
|
618
|
+
*
|
|
619
|
+
* @example On a referenced table
|
|
620
|
+
* ```ts
|
|
621
|
+
* const { data, error } = await supabase
|
|
622
|
+
* .from('orchestral_sections')
|
|
623
|
+
* .select(`
|
|
624
|
+
* name,
|
|
625
|
+
* instruments (
|
|
626
|
+
* name
|
|
627
|
+
* )
|
|
628
|
+
* `)
|
|
629
|
+
* .limit(1, { referencedTable: 'instruments' })
|
|
630
|
+
* ```
|
|
631
|
+
*
|
|
632
|
+
* @exampleSql On a referenced table
|
|
633
|
+
* ```sql
|
|
634
|
+
* create table
|
|
635
|
+
* orchestral_sections (id int8 primary key, name text);
|
|
636
|
+
* create table
|
|
637
|
+
* instruments (
|
|
638
|
+
* id int8 primary key,
|
|
639
|
+
* section_id int8 not null references orchestral_sections,
|
|
640
|
+
* name text
|
|
641
|
+
* );
|
|
642
|
+
*
|
|
643
|
+
* insert into
|
|
644
|
+
* orchestral_sections (id, name)
|
|
645
|
+
* values
|
|
646
|
+
* (1, 'strings');
|
|
647
|
+
* insert into
|
|
648
|
+
* instruments (id, section_id, name)
|
|
649
|
+
* values
|
|
650
|
+
* (1, 1, 'harp'),
|
|
651
|
+
* (2, 1, 'violin');
|
|
652
|
+
* ```
|
|
653
|
+
*
|
|
654
|
+
* @exampleResponse On a referenced table
|
|
655
|
+
* ```json
|
|
656
|
+
* {
|
|
657
|
+
* "data": [
|
|
658
|
+
* {
|
|
659
|
+
* "name": "strings",
|
|
660
|
+
* "instruments": [
|
|
661
|
+
* {
|
|
662
|
+
* "name": "violin"
|
|
663
|
+
* }
|
|
664
|
+
* ]
|
|
665
|
+
* }
|
|
666
|
+
* ],
|
|
667
|
+
* "status": 200,
|
|
668
|
+
* "statusText": "OK"
|
|
669
|
+
* }
|
|
670
|
+
* ```
|
|
671
|
+
*/
|
|
672
|
+
limit(count, { foreignTable, referencedTable = foreignTable } = {}) {
|
|
673
|
+
const key = typeof referencedTable === "undefined" ? "limit" : `${referencedTable}.limit`;
|
|
674
|
+
this.url.searchParams.set(key, `${count}`);
|
|
675
|
+
return this;
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Limit the query result by starting at an offset `from` and ending at the offset `to`.
|
|
679
|
+
* Only records within this range are returned.
|
|
680
|
+
* This respects the query order and if there is no order clause the range could behave unexpectedly.
|
|
681
|
+
* The `from` and `to` values are 0-based and inclusive: `range(1, 3)` will include the second, third
|
|
682
|
+
* and fourth rows of the query.
|
|
683
|
+
*
|
|
684
|
+
* @param from - The starting index from which to limit the result
|
|
685
|
+
* @param to - The last index to which to limit the result
|
|
686
|
+
* @param options - Named parameters
|
|
687
|
+
* @param options.referencedTable - Set this to limit rows of referenced
|
|
688
|
+
* tables instead of the parent table
|
|
689
|
+
* @param options.foreignTable - Deprecated, use `options.referencedTable`
|
|
690
|
+
* instead
|
|
691
|
+
*
|
|
692
|
+
* @category Database
|
|
693
|
+
*
|
|
694
|
+
* @example With `select()`
|
|
695
|
+
* ```ts
|
|
696
|
+
* const { data, error } = await supabase
|
|
697
|
+
* .from('characters')
|
|
698
|
+
* .select('name')
|
|
699
|
+
* .range(0, 1)
|
|
700
|
+
* ```
|
|
701
|
+
*
|
|
702
|
+
* @exampleSql With `select()`
|
|
703
|
+
* ```sql
|
|
704
|
+
* create table
|
|
705
|
+
* characters (id int8 primary key, name text);
|
|
706
|
+
*
|
|
707
|
+
* insert into
|
|
708
|
+
* characters (id, name)
|
|
709
|
+
* values
|
|
710
|
+
* (1, 'Luke'),
|
|
711
|
+
* (2, 'Leia'),
|
|
712
|
+
* (3, 'Han');
|
|
713
|
+
* ```
|
|
714
|
+
*
|
|
715
|
+
* @exampleResponse With `select()`
|
|
716
|
+
* ```json
|
|
717
|
+
* {
|
|
718
|
+
* "data": [
|
|
719
|
+
* {
|
|
720
|
+
* "name": "Luke"
|
|
721
|
+
* },
|
|
722
|
+
* {
|
|
723
|
+
* "name": "Leia"
|
|
724
|
+
* }
|
|
725
|
+
* ],
|
|
726
|
+
* "status": 200,
|
|
727
|
+
* "statusText": "OK"
|
|
728
|
+
* }
|
|
729
|
+
* ```
|
|
730
|
+
*/
|
|
731
|
+
range(from, to, { foreignTable, referencedTable = foreignTable } = {}) {
|
|
313
732
|
const keyOffset = typeof referencedTable === "undefined" ? "offset" : `${referencedTable}.offset`;
|
|
314
733
|
const keyLimit = typeof referencedTable === "undefined" ? "limit" : `${referencedTable}.limit`;
|
|
315
734
|
this.url.searchParams.set(keyOffset, `${from}`);
|
|
@@ -320,6 +739,66 @@ var PostgrestTransformBuilder = class extends PostgrestBuilder {
|
|
|
320
739
|
* Set the AbortSignal for the fetch request.
|
|
321
740
|
*
|
|
322
741
|
* @param signal - The AbortSignal to use for the fetch request
|
|
742
|
+
*
|
|
743
|
+
* @category Database
|
|
744
|
+
*
|
|
745
|
+
* @remarks
|
|
746
|
+
* You can use this to set a timeout for the request.
|
|
747
|
+
*
|
|
748
|
+
* @exampleDescription Aborting requests in-flight
|
|
749
|
+
* You can use an [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) to abort requests.
|
|
750
|
+
* Note that `status` and `statusText` don't mean anything for aborted requests as the request wasn't fulfilled.
|
|
751
|
+
*
|
|
752
|
+
* @example Aborting requests in-flight
|
|
753
|
+
* ```ts
|
|
754
|
+
* const ac = new AbortController()
|
|
755
|
+
*
|
|
756
|
+
* const { data, error } = await supabase
|
|
757
|
+
* .from('very_big_table')
|
|
758
|
+
* .select()
|
|
759
|
+
* .abortSignal(ac.signal)
|
|
760
|
+
*
|
|
761
|
+
* // Abort the request after 100 ms
|
|
762
|
+
* setTimeout(() => ac.abort(), 100)
|
|
763
|
+
* ```
|
|
764
|
+
*
|
|
765
|
+
* @exampleResponse Aborting requests in-flight
|
|
766
|
+
* ```json
|
|
767
|
+
* {
|
|
768
|
+
* "error": {
|
|
769
|
+
* "message": "AbortError: The user aborted a request.",
|
|
770
|
+
* "details": "",
|
|
771
|
+
* "hint": "The request was aborted locally via the provided AbortSignal.",
|
|
772
|
+
* "code": ""
|
|
773
|
+
* },
|
|
774
|
+
* "status": 0,
|
|
775
|
+
* "statusText": ""
|
|
776
|
+
* }
|
|
777
|
+
*
|
|
778
|
+
* ```
|
|
779
|
+
*
|
|
780
|
+
* @example Set a timeout
|
|
781
|
+
* ```ts
|
|
782
|
+
* const { data, error } = await supabase
|
|
783
|
+
* .from('very_big_table')
|
|
784
|
+
* .select()
|
|
785
|
+
* .abortSignal(AbortSignal.timeout(1000 /* ms *\/))
|
|
786
|
+
* ```
|
|
787
|
+
*
|
|
788
|
+
* @exampleResponse Set a timeout
|
|
789
|
+
* ```json
|
|
790
|
+
* {
|
|
791
|
+
* "error": {
|
|
792
|
+
* "message": "FetchError: The user aborted a request.",
|
|
793
|
+
* "details": "",
|
|
794
|
+
* "hint": "",
|
|
795
|
+
* "code": ""
|
|
796
|
+
* },
|
|
797
|
+
* "status": 400,
|
|
798
|
+
* "statusText": "Bad Request"
|
|
799
|
+
* }
|
|
800
|
+
*
|
|
801
|
+
* ```
|
|
323
802
|
*/
|
|
324
803
|
abortSignal(signal) {
|
|
325
804
|
this.signal = signal;
|
|
@@ -330,6 +809,41 @@ var PostgrestTransformBuilder = class extends PostgrestBuilder {
|
|
|
330
809
|
*
|
|
331
810
|
* Query result must be one row (e.g. using `.limit(1)`), otherwise this
|
|
332
811
|
* returns an error.
|
|
812
|
+
*
|
|
813
|
+
* @category Database
|
|
814
|
+
*
|
|
815
|
+
* @example With `select()`
|
|
816
|
+
* ```ts
|
|
817
|
+
* const { data, error } = await supabase
|
|
818
|
+
* .from('characters')
|
|
819
|
+
* .select('name')
|
|
820
|
+
* .limit(1)
|
|
821
|
+
* .single()
|
|
822
|
+
* ```
|
|
823
|
+
*
|
|
824
|
+
* @exampleSql With `select()`
|
|
825
|
+
* ```sql
|
|
826
|
+
* create table
|
|
827
|
+
* characters (id int8 primary key, name text);
|
|
828
|
+
*
|
|
829
|
+
* insert into
|
|
830
|
+
* characters (id, name)
|
|
831
|
+
* values
|
|
832
|
+
* (1, 'Luke'),
|
|
833
|
+
* (2, 'Leia'),
|
|
834
|
+
* (3, 'Han');
|
|
835
|
+
* ```
|
|
836
|
+
*
|
|
837
|
+
* @exampleResponse With `select()`
|
|
838
|
+
* ```json
|
|
839
|
+
* {
|
|
840
|
+
* "data": {
|
|
841
|
+
* "name": "Luke"
|
|
842
|
+
* },
|
|
843
|
+
* "status": 200,
|
|
844
|
+
* "statusText": "OK"
|
|
845
|
+
* }
|
|
846
|
+
* ```
|
|
333
847
|
*/
|
|
334
848
|
single() {
|
|
335
849
|
this.headers.set("Accept", "application/vnd.pgrst.object+json");
|
|
@@ -340,15 +854,80 @@ var PostgrestTransformBuilder = class extends PostgrestBuilder {
|
|
|
340
854
|
*
|
|
341
855
|
* Query result must be zero or one row (e.g. using `.limit(1)`), otherwise
|
|
342
856
|
* this returns an error.
|
|
857
|
+
*
|
|
858
|
+
* @category Database
|
|
859
|
+
*
|
|
860
|
+
* @example With `select()`
|
|
861
|
+
* ```ts
|
|
862
|
+
* const { data, error } = await supabase
|
|
863
|
+
* .from('characters')
|
|
864
|
+
* .select()
|
|
865
|
+
* .eq('name', 'Katniss')
|
|
866
|
+
* .maybeSingle()
|
|
867
|
+
* ```
|
|
868
|
+
*
|
|
869
|
+
* @exampleSql With `select()`
|
|
870
|
+
* ```sql
|
|
871
|
+
* create table
|
|
872
|
+
* characters (id int8 primary key, name text);
|
|
873
|
+
*
|
|
874
|
+
* insert into
|
|
875
|
+
* characters (id, name)
|
|
876
|
+
* values
|
|
877
|
+
* (1, 'Luke'),
|
|
878
|
+
* (2, 'Leia'),
|
|
879
|
+
* (3, 'Han');
|
|
880
|
+
* ```
|
|
881
|
+
*
|
|
882
|
+
* @exampleResponse With `select()`
|
|
883
|
+
* ```json
|
|
884
|
+
* {
|
|
885
|
+
* "status": 200,
|
|
886
|
+
* "statusText": "OK"
|
|
887
|
+
* }
|
|
888
|
+
* ```
|
|
343
889
|
*/
|
|
344
890
|
maybeSingle() {
|
|
345
|
-
if (this.method === "GET") this.headers.set("Accept", "application/json");
|
|
346
|
-
else this.headers.set("Accept", "application/vnd.pgrst.object+json");
|
|
347
891
|
this.isMaybeSingle = true;
|
|
348
892
|
return this;
|
|
349
893
|
}
|
|
350
894
|
/**
|
|
351
895
|
* Return `data` as a string in CSV format.
|
|
896
|
+
*
|
|
897
|
+
* @category Database
|
|
898
|
+
*
|
|
899
|
+
* @exampleDescription Return data as CSV
|
|
900
|
+
* By default, the data is returned in JSON format, but can also be returned as Comma Separated Values.
|
|
901
|
+
*
|
|
902
|
+
* @example Return data as CSV
|
|
903
|
+
* ```ts
|
|
904
|
+
* const { data, error } = await supabase
|
|
905
|
+
* .from('characters')
|
|
906
|
+
* .select()
|
|
907
|
+
* .csv()
|
|
908
|
+
* ```
|
|
909
|
+
*
|
|
910
|
+
* @exampleSql Return data as CSV
|
|
911
|
+
* ```sql
|
|
912
|
+
* create table
|
|
913
|
+
* characters (id int8 primary key, name text);
|
|
914
|
+
*
|
|
915
|
+
* insert into
|
|
916
|
+
* characters (id, name)
|
|
917
|
+
* values
|
|
918
|
+
* (1, 'Luke'),
|
|
919
|
+
* (2, 'Leia'),
|
|
920
|
+
* (3, 'Han');
|
|
921
|
+
* ```
|
|
922
|
+
*
|
|
923
|
+
* @exampleResponse Return data as CSV
|
|
924
|
+
* ```json
|
|
925
|
+
* {
|
|
926
|
+
* "data": "id,name\n1,Luke\n2,Leia\n3,Han",
|
|
927
|
+
* "status": 200,
|
|
928
|
+
* "statusText": "OK"
|
|
929
|
+
* }
|
|
930
|
+
* ```
|
|
352
931
|
*/
|
|
353
932
|
csv() {
|
|
354
933
|
this.headers.set("Accept", "text/csv");
|
|
@@ -356,6 +935,8 @@ var PostgrestTransformBuilder = class extends PostgrestBuilder {
|
|
|
356
935
|
}
|
|
357
936
|
/**
|
|
358
937
|
* Return `data` as an object in [GeoJSON](https://geojson.org) format.
|
|
938
|
+
*
|
|
939
|
+
* @category Database
|
|
359
940
|
*/
|
|
360
941
|
geojson() {
|
|
361
942
|
this.headers.set("Accept", "application/geo+json");
|
|
@@ -385,12 +966,82 @@ var PostgrestTransformBuilder = class extends PostgrestBuilder {
|
|
|
385
966
|
*
|
|
386
967
|
* @param options.format - The format of the output, can be `"text"` (default)
|
|
387
968
|
* or `"json"`
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
969
|
+
*
|
|
970
|
+
* @category Database
|
|
971
|
+
*
|
|
972
|
+
* @exampleDescription Get the execution plan
|
|
973
|
+
* By default, the data is returned in TEXT format, but can also be returned as JSON by using the `format` parameter.
|
|
974
|
+
*
|
|
975
|
+
* @example Get the execution plan
|
|
976
|
+
* ```ts
|
|
977
|
+
* const { data, error } = await supabase
|
|
978
|
+
* .from('characters')
|
|
979
|
+
* .select()
|
|
980
|
+
* .explain()
|
|
981
|
+
* ```
|
|
982
|
+
*
|
|
983
|
+
* @exampleSql Get the execution plan
|
|
984
|
+
* ```sql
|
|
985
|
+
* create table
|
|
986
|
+
* characters (id int8 primary key, name text);
|
|
987
|
+
*
|
|
988
|
+
* insert into
|
|
989
|
+
* characters (id, name)
|
|
990
|
+
* values
|
|
991
|
+
* (1, 'Luke'),
|
|
992
|
+
* (2, 'Leia'),
|
|
993
|
+
* (3, 'Han');
|
|
994
|
+
* ```
|
|
995
|
+
*
|
|
996
|
+
* @exampleResponse Get the execution plan
|
|
997
|
+
* ```js
|
|
998
|
+
* Aggregate (cost=33.34..33.36 rows=1 width=112)
|
|
999
|
+
* -> Limit (cost=0.00..18.33 rows=1000 width=40)
|
|
1000
|
+
* -> Seq Scan on characters (cost=0.00..22.00 rows=1200 width=40)
|
|
1001
|
+
* ```
|
|
1002
|
+
*
|
|
1003
|
+
* @exampleDescription Get the execution plan with analyze and verbose
|
|
1004
|
+
* By default, the data is returned in TEXT format, but can also be returned as JSON by using the `format` parameter.
|
|
1005
|
+
*
|
|
1006
|
+
* @example Get the execution plan with analyze and verbose
|
|
1007
|
+
* ```ts
|
|
1008
|
+
* const { data, error } = await supabase
|
|
1009
|
+
* .from('characters')
|
|
1010
|
+
* .select()
|
|
1011
|
+
* .explain({analyze:true,verbose:true})
|
|
1012
|
+
* ```
|
|
1013
|
+
*
|
|
1014
|
+
* @exampleSql Get the execution plan with analyze and verbose
|
|
1015
|
+
* ```sql
|
|
1016
|
+
* create table
|
|
1017
|
+
* characters (id int8 primary key, name text);
|
|
1018
|
+
*
|
|
1019
|
+
* insert into
|
|
1020
|
+
* characters (id, name)
|
|
1021
|
+
* values
|
|
1022
|
+
* (1, 'Luke'),
|
|
1023
|
+
* (2, 'Leia'),
|
|
1024
|
+
* (3, 'Han');
|
|
1025
|
+
* ```
|
|
1026
|
+
*
|
|
1027
|
+
* @exampleResponse Get the execution plan with analyze and verbose
|
|
1028
|
+
* ```js
|
|
1029
|
+
* Aggregate (cost=33.34..33.36 rows=1 width=112) (actual time=0.041..0.041 rows=1 loops=1)
|
|
1030
|
+
* 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)
|
|
1031
|
+
* -> Limit (cost=0.00..18.33 rows=1000 width=40) (actual time=0.005..0.006 rows=3 loops=1)
|
|
1032
|
+
* Output: characters.id, characters.name
|
|
1033
|
+
* -> Seq Scan on public.characters (cost=0.00..22.00 rows=1200 width=40) (actual time=0.004..0.005 rows=3 loops=1)
|
|
1034
|
+
* Output: characters.id, characters.name
|
|
1035
|
+
* Query Identifier: -4730654291623321173
|
|
1036
|
+
* Planning Time: 0.407 ms
|
|
1037
|
+
* Execution Time: 0.119 ms
|
|
1038
|
+
* ```
|
|
1039
|
+
*/
|
|
1040
|
+
explain({ analyze = false, verbose = false, settings = false, buffers = false, wal = false, format = "text" } = {}) {
|
|
1041
|
+
var _this$headers$get;
|
|
1042
|
+
const options = [
|
|
1043
|
+
analyze ? "analyze" : null,
|
|
1044
|
+
verbose ? "verbose" : null,
|
|
394
1045
|
settings ? "settings" : null,
|
|
395
1046
|
buffers ? "buffers" : null,
|
|
396
1047
|
wal ? "wal" : null
|
|
@@ -404,6 +1055,8 @@ var PostgrestTransformBuilder = class extends PostgrestBuilder {
|
|
|
404
1055
|
* Rollback the query.
|
|
405
1056
|
*
|
|
406
1057
|
* `data` will still be returned, but the query is not committed.
|
|
1058
|
+
*
|
|
1059
|
+
* @category Database
|
|
407
1060
|
*/
|
|
408
1061
|
rollback() {
|
|
409
1062
|
this.headers.append("Prefer", "tx=rollback");
|
|
@@ -414,6 +1067,38 @@ var PostgrestTransformBuilder = class extends PostgrestBuilder {
|
|
|
414
1067
|
*
|
|
415
1068
|
* @typeParam NewResult - The new result type to override with
|
|
416
1069
|
* @deprecated Use overrideTypes<yourType, { merge: false }>() method at the end of your call chain instead
|
|
1070
|
+
*
|
|
1071
|
+
* @category Database
|
|
1072
|
+
*
|
|
1073
|
+
* @remarks
|
|
1074
|
+
* - Deprecated: use overrideTypes method instead
|
|
1075
|
+
*
|
|
1076
|
+
* @example Override type of successful response
|
|
1077
|
+
* ```ts
|
|
1078
|
+
* const { data } = await supabase
|
|
1079
|
+
* .from('countries')
|
|
1080
|
+
* .select()
|
|
1081
|
+
* .returns<Array<MyType>>()
|
|
1082
|
+
* ```
|
|
1083
|
+
*
|
|
1084
|
+
* @exampleResponse Override type of successful response
|
|
1085
|
+
* ```js
|
|
1086
|
+
* let x: typeof data // MyType[]
|
|
1087
|
+
* ```
|
|
1088
|
+
*
|
|
1089
|
+
* @example Override type of object response
|
|
1090
|
+
* ```ts
|
|
1091
|
+
* const { data } = await supabase
|
|
1092
|
+
* .from('countries')
|
|
1093
|
+
* .select()
|
|
1094
|
+
* .maybeSingle()
|
|
1095
|
+
* .returns<MyType>()
|
|
1096
|
+
* ```
|
|
1097
|
+
*
|
|
1098
|
+
* @exampleResponse Override type of object response
|
|
1099
|
+
* ```js
|
|
1100
|
+
* let x: typeof data // MyType | null
|
|
1101
|
+
* ```
|
|
417
1102
|
*/
|
|
418
1103
|
returns() {
|
|
419
1104
|
return this;
|
|
@@ -423,6 +1108,8 @@ var PostgrestTransformBuilder = class extends PostgrestBuilder {
|
|
|
423
1108
|
* Only available in PostgREST v13+ and only works with PATCH and DELETE methods.
|
|
424
1109
|
*
|
|
425
1110
|
* @param value - The maximum number of rows that can be affected
|
|
1111
|
+
*
|
|
1112
|
+
* @category Database
|
|
426
1113
|
*/
|
|
427
1114
|
maxAffected(value) {
|
|
428
1115
|
this.headers.append("Prefer", "handling=strict");
|
|
@@ -442,6 +1129,43 @@ var PostgrestFilterBuilder = class extends PostgrestTransformBuilder {
|
|
|
442
1129
|
*
|
|
443
1130
|
* @param column - The column to filter on
|
|
444
1131
|
* @param value - The value to filter with
|
|
1132
|
+
*
|
|
1133
|
+
* @category Database
|
|
1134
|
+
*
|
|
1135
|
+
* @example With `select()`
|
|
1136
|
+
* ```ts
|
|
1137
|
+
* const { data, error } = await supabase
|
|
1138
|
+
* .from('characters')
|
|
1139
|
+
* .select()
|
|
1140
|
+
* .eq('name', 'Leia')
|
|
1141
|
+
* ```
|
|
1142
|
+
*
|
|
1143
|
+
* @exampleSql With `select()`
|
|
1144
|
+
* ```sql
|
|
1145
|
+
* create table
|
|
1146
|
+
* characters (id int8 primary key, name text);
|
|
1147
|
+
*
|
|
1148
|
+
* insert into
|
|
1149
|
+
* characters (id, name)
|
|
1150
|
+
* values
|
|
1151
|
+
* (1, 'Luke'),
|
|
1152
|
+
* (2, 'Leia'),
|
|
1153
|
+
* (3, 'Han');
|
|
1154
|
+
* ```
|
|
1155
|
+
*
|
|
1156
|
+
* @exampleResponse With `select()`
|
|
1157
|
+
* ```json
|
|
1158
|
+
* {
|
|
1159
|
+
* "data": [
|
|
1160
|
+
* {
|
|
1161
|
+
* "id": 2,
|
|
1162
|
+
* "name": "Leia"
|
|
1163
|
+
* }
|
|
1164
|
+
* ],
|
|
1165
|
+
* "status": 200,
|
|
1166
|
+
* "statusText": "OK"
|
|
1167
|
+
* }
|
|
1168
|
+
* ```
|
|
445
1169
|
*/
|
|
446
1170
|
eq(column, value) {
|
|
447
1171
|
this.url.searchParams.append(column, `eq.${value}`);
|
|
@@ -452,6 +1176,47 @@ var PostgrestFilterBuilder = class extends PostgrestTransformBuilder {
|
|
|
452
1176
|
*
|
|
453
1177
|
* @param column - The column to filter on
|
|
454
1178
|
* @param value - The value to filter with
|
|
1179
|
+
*
|
|
1180
|
+
* @category Database
|
|
1181
|
+
*
|
|
1182
|
+
* @example With `select()`
|
|
1183
|
+
* ```ts
|
|
1184
|
+
* const { data, error } = await supabase
|
|
1185
|
+
* .from('characters')
|
|
1186
|
+
* .select()
|
|
1187
|
+
* .neq('name', 'Leia')
|
|
1188
|
+
* ```
|
|
1189
|
+
*
|
|
1190
|
+
* @exampleSql With `select()`
|
|
1191
|
+
* ```sql
|
|
1192
|
+
* create table
|
|
1193
|
+
* characters (id int8 primary key, name text);
|
|
1194
|
+
*
|
|
1195
|
+
* insert into
|
|
1196
|
+
* characters (id, name)
|
|
1197
|
+
* values
|
|
1198
|
+
* (1, 'Luke'),
|
|
1199
|
+
* (2, 'Leia'),
|
|
1200
|
+
* (3, 'Han');
|
|
1201
|
+
* ```
|
|
1202
|
+
*
|
|
1203
|
+
* @exampleResponse With `select()`
|
|
1204
|
+
* ```json
|
|
1205
|
+
* {
|
|
1206
|
+
* "data": [
|
|
1207
|
+
* {
|
|
1208
|
+
* "id": 1,
|
|
1209
|
+
* "name": "Luke"
|
|
1210
|
+
* },
|
|
1211
|
+
* {
|
|
1212
|
+
* "id": 3,
|
|
1213
|
+
* "name": "Han"
|
|
1214
|
+
* }
|
|
1215
|
+
* ],
|
|
1216
|
+
* "status": 200,
|
|
1217
|
+
* "statusText": "OK"
|
|
1218
|
+
* }
|
|
1219
|
+
* ```
|
|
455
1220
|
*/
|
|
456
1221
|
neq(column, value) {
|
|
457
1222
|
this.url.searchParams.append(column, `neq.${value}`);
|
|
@@ -462,6 +1227,47 @@ var PostgrestFilterBuilder = class extends PostgrestTransformBuilder {
|
|
|
462
1227
|
*
|
|
463
1228
|
* @param column - The column to filter on
|
|
464
1229
|
* @param value - The value to filter with
|
|
1230
|
+
*
|
|
1231
|
+
* @category Database
|
|
1232
|
+
*
|
|
1233
|
+
* @exampleDescription With `select()`
|
|
1234
|
+
* When using [reserved words](https://www.postgresql.org/docs/current/sql-keywords-appendix.html) for column names you need
|
|
1235
|
+
* to add double quotes e.g. `.gt('"order"', 2)`
|
|
1236
|
+
*
|
|
1237
|
+
* @example With `select()`
|
|
1238
|
+
* ```ts
|
|
1239
|
+
* const { data, error } = await supabase
|
|
1240
|
+
* .from('characters')
|
|
1241
|
+
* .select()
|
|
1242
|
+
* .gt('id', 2)
|
|
1243
|
+
* ```
|
|
1244
|
+
*
|
|
1245
|
+
* @exampleSql With `select()`
|
|
1246
|
+
* ```sql
|
|
1247
|
+
* create table
|
|
1248
|
+
* characters (id int8 primary key, name text);
|
|
1249
|
+
*
|
|
1250
|
+
* insert into
|
|
1251
|
+
* characters (id, name)
|
|
1252
|
+
* values
|
|
1253
|
+
* (1, 'Luke'),
|
|
1254
|
+
* (2, 'Leia'),
|
|
1255
|
+
* (3, 'Han');
|
|
1256
|
+
* ```
|
|
1257
|
+
*
|
|
1258
|
+
* @exampleResponse With `select()`
|
|
1259
|
+
* ```json
|
|
1260
|
+
* {
|
|
1261
|
+
* "data": [
|
|
1262
|
+
* {
|
|
1263
|
+
* "id": 3,
|
|
1264
|
+
* "name": "Han"
|
|
1265
|
+
* }
|
|
1266
|
+
* ],
|
|
1267
|
+
* "status": 200,
|
|
1268
|
+
* "statusText": "OK"
|
|
1269
|
+
* }
|
|
1270
|
+
* ```
|
|
465
1271
|
*/
|
|
466
1272
|
gt(column, value) {
|
|
467
1273
|
this.url.searchParams.append(column, `gt.${value}`);
|
|
@@ -472,6 +1278,47 @@ var PostgrestFilterBuilder = class extends PostgrestTransformBuilder {
|
|
|
472
1278
|
*
|
|
473
1279
|
* @param column - The column to filter on
|
|
474
1280
|
* @param value - The value to filter with
|
|
1281
|
+
*
|
|
1282
|
+
* @category Database
|
|
1283
|
+
*
|
|
1284
|
+
* @example With `select()`
|
|
1285
|
+
* ```ts
|
|
1286
|
+
* const { data, error } = await supabase
|
|
1287
|
+
* .from('characters')
|
|
1288
|
+
* .select()
|
|
1289
|
+
* .gte('id', 2)
|
|
1290
|
+
* ```
|
|
1291
|
+
*
|
|
1292
|
+
* @exampleSql With `select()`
|
|
1293
|
+
* ```sql
|
|
1294
|
+
* create table
|
|
1295
|
+
* characters (id int8 primary key, name text);
|
|
1296
|
+
*
|
|
1297
|
+
* insert into
|
|
1298
|
+
* characters (id, name)
|
|
1299
|
+
* values
|
|
1300
|
+
* (1, 'Luke'),
|
|
1301
|
+
* (2, 'Leia'),
|
|
1302
|
+
* (3, 'Han');
|
|
1303
|
+
* ```
|
|
1304
|
+
*
|
|
1305
|
+
* @exampleResponse With `select()`
|
|
1306
|
+
* ```json
|
|
1307
|
+
* {
|
|
1308
|
+
* "data": [
|
|
1309
|
+
* {
|
|
1310
|
+
* "id": 2,
|
|
1311
|
+
* "name": "Leia"
|
|
1312
|
+
* },
|
|
1313
|
+
* {
|
|
1314
|
+
* "id": 3,
|
|
1315
|
+
* "name": "Han"
|
|
1316
|
+
* }
|
|
1317
|
+
* ],
|
|
1318
|
+
* "status": 200,
|
|
1319
|
+
* "statusText": "OK"
|
|
1320
|
+
* }
|
|
1321
|
+
* ```
|
|
475
1322
|
*/
|
|
476
1323
|
gte(column, value) {
|
|
477
1324
|
this.url.searchParams.append(column, `gte.${value}`);
|
|
@@ -482,6 +1329,43 @@ var PostgrestFilterBuilder = class extends PostgrestTransformBuilder {
|
|
|
482
1329
|
*
|
|
483
1330
|
* @param column - The column to filter on
|
|
484
1331
|
* @param value - The value to filter with
|
|
1332
|
+
*
|
|
1333
|
+
* @category Database
|
|
1334
|
+
*
|
|
1335
|
+
* @example With `select()`
|
|
1336
|
+
* ```ts
|
|
1337
|
+
* const { data, error } = await supabase
|
|
1338
|
+
* .from('characters')
|
|
1339
|
+
* .select()
|
|
1340
|
+
* .lt('id', 2)
|
|
1341
|
+
* ```
|
|
1342
|
+
*
|
|
1343
|
+
* @exampleSql With `select()`
|
|
1344
|
+
* ```sql
|
|
1345
|
+
* create table
|
|
1346
|
+
* characters (id int8 primary key, name text);
|
|
1347
|
+
*
|
|
1348
|
+
* insert into
|
|
1349
|
+
* characters (id, name)
|
|
1350
|
+
* values
|
|
1351
|
+
* (1, 'Luke'),
|
|
1352
|
+
* (2, 'Leia'),
|
|
1353
|
+
* (3, 'Han');
|
|
1354
|
+
* ```
|
|
1355
|
+
*
|
|
1356
|
+
* @exampleResponse With `select()`
|
|
1357
|
+
* ```json
|
|
1358
|
+
* {
|
|
1359
|
+
* "data": [
|
|
1360
|
+
* {
|
|
1361
|
+
* "id": 1,
|
|
1362
|
+
* "name": "Luke"
|
|
1363
|
+
* }
|
|
1364
|
+
* ],
|
|
1365
|
+
* "status": 200,
|
|
1366
|
+
* "statusText": "OK"
|
|
1367
|
+
* }
|
|
1368
|
+
* ```
|
|
485
1369
|
*/
|
|
486
1370
|
lt(column, value) {
|
|
487
1371
|
this.url.searchParams.append(column, `lt.${value}`);
|
|
@@ -492,18 +1376,96 @@ var PostgrestFilterBuilder = class extends PostgrestTransformBuilder {
|
|
|
492
1376
|
*
|
|
493
1377
|
* @param column - The column to filter on
|
|
494
1378
|
* @param value - The value to filter with
|
|
495
|
-
*/
|
|
496
|
-
lte(column, value) {
|
|
497
|
-
this.url.searchParams.append(column, `lte.${value}`);
|
|
498
|
-
return this;
|
|
499
|
-
}
|
|
500
|
-
/**
|
|
501
|
-
* Match only rows where `column` matches `pattern` case-sensitively.
|
|
502
1379
|
*
|
|
503
|
-
* @
|
|
504
|
-
*
|
|
505
|
-
|
|
506
|
-
|
|
1380
|
+
* @category Database
|
|
1381
|
+
*
|
|
1382
|
+
* @example With `select()`
|
|
1383
|
+
* ```ts
|
|
1384
|
+
* const { data, error } = await supabase
|
|
1385
|
+
* .from('characters')
|
|
1386
|
+
* .select()
|
|
1387
|
+
* .lte('id', 2)
|
|
1388
|
+
* ```
|
|
1389
|
+
*
|
|
1390
|
+
* @exampleSql With `select()`
|
|
1391
|
+
* ```sql
|
|
1392
|
+
* create table
|
|
1393
|
+
* characters (id int8 primary key, name text);
|
|
1394
|
+
*
|
|
1395
|
+
* insert into
|
|
1396
|
+
* characters (id, name)
|
|
1397
|
+
* values
|
|
1398
|
+
* (1, 'Luke'),
|
|
1399
|
+
* (2, 'Leia'),
|
|
1400
|
+
* (3, 'Han');
|
|
1401
|
+
* ```
|
|
1402
|
+
*
|
|
1403
|
+
* @exampleResponse With `select()`
|
|
1404
|
+
* ```json
|
|
1405
|
+
* {
|
|
1406
|
+
* "data": [
|
|
1407
|
+
* {
|
|
1408
|
+
* "id": 1,
|
|
1409
|
+
* "name": "Luke"
|
|
1410
|
+
* },
|
|
1411
|
+
* {
|
|
1412
|
+
* "id": 2,
|
|
1413
|
+
* "name": "Leia"
|
|
1414
|
+
* }
|
|
1415
|
+
* ],
|
|
1416
|
+
* "status": 200,
|
|
1417
|
+
* "statusText": "OK"
|
|
1418
|
+
* }
|
|
1419
|
+
* ```
|
|
1420
|
+
*/
|
|
1421
|
+
lte(column, value) {
|
|
1422
|
+
this.url.searchParams.append(column, `lte.${value}`);
|
|
1423
|
+
return this;
|
|
1424
|
+
}
|
|
1425
|
+
/**
|
|
1426
|
+
* Match only rows where `column` matches `pattern` case-sensitively.
|
|
1427
|
+
*
|
|
1428
|
+
* @param column - The column to filter on
|
|
1429
|
+
* @param pattern - The pattern to match with
|
|
1430
|
+
*
|
|
1431
|
+
* @category Database
|
|
1432
|
+
*
|
|
1433
|
+
* @example With `select()`
|
|
1434
|
+
* ```ts
|
|
1435
|
+
* const { data, error } = await supabase
|
|
1436
|
+
* .from('characters')
|
|
1437
|
+
* .select()
|
|
1438
|
+
* .like('name', '%Lu%')
|
|
1439
|
+
* ```
|
|
1440
|
+
*
|
|
1441
|
+
* @exampleSql With `select()`
|
|
1442
|
+
* ```sql
|
|
1443
|
+
* create table
|
|
1444
|
+
* characters (id int8 primary key, name text);
|
|
1445
|
+
*
|
|
1446
|
+
* insert into
|
|
1447
|
+
* characters (id, name)
|
|
1448
|
+
* values
|
|
1449
|
+
* (1, 'Luke'),
|
|
1450
|
+
* (2, 'Leia'),
|
|
1451
|
+
* (3, 'Han');
|
|
1452
|
+
* ```
|
|
1453
|
+
*
|
|
1454
|
+
* @exampleResponse With `select()`
|
|
1455
|
+
* ```json
|
|
1456
|
+
* {
|
|
1457
|
+
* "data": [
|
|
1458
|
+
* {
|
|
1459
|
+
* "id": 1,
|
|
1460
|
+
* "name": "Luke"
|
|
1461
|
+
* }
|
|
1462
|
+
* ],
|
|
1463
|
+
* "status": 200,
|
|
1464
|
+
* "statusText": "OK"
|
|
1465
|
+
* }
|
|
1466
|
+
* ```
|
|
1467
|
+
*/
|
|
1468
|
+
like(column, pattern) {
|
|
507
1469
|
this.url.searchParams.append(column, `like.${pattern}`);
|
|
508
1470
|
return this;
|
|
509
1471
|
}
|
|
@@ -512,6 +1474,8 @@ var PostgrestFilterBuilder = class extends PostgrestTransformBuilder {
|
|
|
512
1474
|
*
|
|
513
1475
|
* @param column - The column to filter on
|
|
514
1476
|
* @param patterns - The patterns to match with
|
|
1477
|
+
*
|
|
1478
|
+
* @category Database
|
|
515
1479
|
*/
|
|
516
1480
|
likeAllOf(column, patterns) {
|
|
517
1481
|
this.url.searchParams.append(column, `like(all).{${patterns.join(",")}}`);
|
|
@@ -522,6 +1486,8 @@ var PostgrestFilterBuilder = class extends PostgrestTransformBuilder {
|
|
|
522
1486
|
*
|
|
523
1487
|
* @param column - The column to filter on
|
|
524
1488
|
* @param patterns - The patterns to match with
|
|
1489
|
+
*
|
|
1490
|
+
* @category Database
|
|
525
1491
|
*/
|
|
526
1492
|
likeAnyOf(column, patterns) {
|
|
527
1493
|
this.url.searchParams.append(column, `like(any).{${patterns.join(",")}}`);
|
|
@@ -532,6 +1498,43 @@ var PostgrestFilterBuilder = class extends PostgrestTransformBuilder {
|
|
|
532
1498
|
*
|
|
533
1499
|
* @param column - The column to filter on
|
|
534
1500
|
* @param pattern - The pattern to match with
|
|
1501
|
+
*
|
|
1502
|
+
* @category Database
|
|
1503
|
+
*
|
|
1504
|
+
* @example With `select()`
|
|
1505
|
+
* ```ts
|
|
1506
|
+
* const { data, error } = await supabase
|
|
1507
|
+
* .from('characters')
|
|
1508
|
+
* .select()
|
|
1509
|
+
* .ilike('name', '%lu%')
|
|
1510
|
+
* ```
|
|
1511
|
+
*
|
|
1512
|
+
* @exampleSql With `select()`
|
|
1513
|
+
* ```sql
|
|
1514
|
+
* create table
|
|
1515
|
+
* characters (id int8 primary key, name text);
|
|
1516
|
+
*
|
|
1517
|
+
* insert into
|
|
1518
|
+
* characters (id, name)
|
|
1519
|
+
* values
|
|
1520
|
+
* (1, 'Luke'),
|
|
1521
|
+
* (2, 'Leia'),
|
|
1522
|
+
* (3, 'Han');
|
|
1523
|
+
* ```
|
|
1524
|
+
*
|
|
1525
|
+
* @exampleResponse With `select()`
|
|
1526
|
+
* ```json
|
|
1527
|
+
* {
|
|
1528
|
+
* "data": [
|
|
1529
|
+
* {
|
|
1530
|
+
* "id": 1,
|
|
1531
|
+
* "name": "Luke"
|
|
1532
|
+
* }
|
|
1533
|
+
* ],
|
|
1534
|
+
* "status": 200,
|
|
1535
|
+
* "statusText": "OK"
|
|
1536
|
+
* }
|
|
1537
|
+
* ```
|
|
535
1538
|
*/
|
|
536
1539
|
ilike(column, pattern) {
|
|
537
1540
|
this.url.searchParams.append(column, `ilike.${pattern}`);
|
|
@@ -542,6 +1545,8 @@ var PostgrestFilterBuilder = class extends PostgrestTransformBuilder {
|
|
|
542
1545
|
*
|
|
543
1546
|
* @param column - The column to filter on
|
|
544
1547
|
* @param patterns - The patterns to match with
|
|
1548
|
+
*
|
|
1549
|
+
* @category Database
|
|
545
1550
|
*/
|
|
546
1551
|
ilikeAllOf(column, patterns) {
|
|
547
1552
|
this.url.searchParams.append(column, `ilike(all).{${patterns.join(",")}}`);
|
|
@@ -552,6 +1557,8 @@ var PostgrestFilterBuilder = class extends PostgrestTransformBuilder {
|
|
|
552
1557
|
*
|
|
553
1558
|
* @param column - The column to filter on
|
|
554
1559
|
* @param patterns - The patterns to match with
|
|
1560
|
+
*
|
|
1561
|
+
* @category Database
|
|
555
1562
|
*/
|
|
556
1563
|
ilikeAnyOf(column, patterns) {
|
|
557
1564
|
this.url.searchParams.append(column, `ilike(any).{${patterns.join(",")}}`);
|
|
@@ -590,6 +1597,47 @@ var PostgrestFilterBuilder = class extends PostgrestTransformBuilder {
|
|
|
590
1597
|
*
|
|
591
1598
|
* @param column - The column to filter on
|
|
592
1599
|
* @param value - The value to filter with
|
|
1600
|
+
*
|
|
1601
|
+
* @category Database
|
|
1602
|
+
*
|
|
1603
|
+
* @exampleDescription Checking for nullness, true or false
|
|
1604
|
+
* Using the `eq()` filter doesn't work when filtering for `null`.
|
|
1605
|
+
*
|
|
1606
|
+
* Instead, you need to use `is()`.
|
|
1607
|
+
*
|
|
1608
|
+
* @example Checking for nullness, true or false
|
|
1609
|
+
* ```ts
|
|
1610
|
+
* const { data, error } = await supabase
|
|
1611
|
+
* .from('countries')
|
|
1612
|
+
* .select()
|
|
1613
|
+
* .is('name', null)
|
|
1614
|
+
* ```
|
|
1615
|
+
*
|
|
1616
|
+
* @exampleSql Checking for nullness, true or false
|
|
1617
|
+
* ```sql
|
|
1618
|
+
* create table
|
|
1619
|
+
* countries (id int8 primary key, name text);
|
|
1620
|
+
*
|
|
1621
|
+
* insert into
|
|
1622
|
+
* countries (id, name)
|
|
1623
|
+
* values
|
|
1624
|
+
* (1, 'null'),
|
|
1625
|
+
* (2, null);
|
|
1626
|
+
* ```
|
|
1627
|
+
*
|
|
1628
|
+
* @exampleResponse Checking for nullness, true or false
|
|
1629
|
+
* ```json
|
|
1630
|
+
* {
|
|
1631
|
+
* "data": [
|
|
1632
|
+
* {
|
|
1633
|
+
* "id": 2,
|
|
1634
|
+
* "name": "null"
|
|
1635
|
+
* }
|
|
1636
|
+
* ],
|
|
1637
|
+
* "status": 200,
|
|
1638
|
+
* "statusText": "OK"
|
|
1639
|
+
* }
|
|
1640
|
+
* ```
|
|
593
1641
|
*/
|
|
594
1642
|
is(column, value) {
|
|
595
1643
|
this.url.searchParams.append(column, `is.${value}`);
|
|
@@ -614,6 +1662,47 @@ var PostgrestFilterBuilder = class extends PostgrestTransformBuilder {
|
|
|
614
1662
|
*
|
|
615
1663
|
* @param column - The column to filter on
|
|
616
1664
|
* @param values - The values array to filter with
|
|
1665
|
+
*
|
|
1666
|
+
* @category Database
|
|
1667
|
+
*
|
|
1668
|
+
* @example With `select()`
|
|
1669
|
+
* ```ts
|
|
1670
|
+
* const { data, error } = await supabase
|
|
1671
|
+
* .from('characters')
|
|
1672
|
+
* .select()
|
|
1673
|
+
* .in('name', ['Leia', 'Han'])
|
|
1674
|
+
* ```
|
|
1675
|
+
*
|
|
1676
|
+
* @exampleSql With `select()`
|
|
1677
|
+
* ```sql
|
|
1678
|
+
* create table
|
|
1679
|
+
* characters (id int8 primary key, name text);
|
|
1680
|
+
*
|
|
1681
|
+
* insert into
|
|
1682
|
+
* characters (id, name)
|
|
1683
|
+
* values
|
|
1684
|
+
* (1, 'Luke'),
|
|
1685
|
+
* (2, 'Leia'),
|
|
1686
|
+
* (3, 'Han');
|
|
1687
|
+
* ```
|
|
1688
|
+
*
|
|
1689
|
+
* @exampleResponse With `select()`
|
|
1690
|
+
* ```json
|
|
1691
|
+
* {
|
|
1692
|
+
* "data": [
|
|
1693
|
+
* {
|
|
1694
|
+
* "id": 2,
|
|
1695
|
+
* "name": "Leia"
|
|
1696
|
+
* },
|
|
1697
|
+
* {
|
|
1698
|
+
* "id": 3,
|
|
1699
|
+
* "name": "Han"
|
|
1700
|
+
* }
|
|
1701
|
+
* ],
|
|
1702
|
+
* "status": 200,
|
|
1703
|
+
* "statusText": "OK"
|
|
1704
|
+
* }
|
|
1705
|
+
* ```
|
|
617
1706
|
*/
|
|
618
1707
|
in(column, values) {
|
|
619
1708
|
const cleanedValues = Array.from(new Set(values)).map((s) => {
|
|
@@ -643,72 +1732,506 @@ var PostgrestFilterBuilder = class extends PostgrestTransformBuilder {
|
|
|
643
1732
|
*
|
|
644
1733
|
* @param column - The jsonb, array, or range column to filter on
|
|
645
1734
|
* @param value - The jsonb, array, or range value to filter with
|
|
646
|
-
*/
|
|
647
|
-
contains(column, value) {
|
|
648
|
-
if (typeof value === "string") this.url.searchParams.append(column, `cs.${value}`);
|
|
649
|
-
else if (Array.isArray(value)) this.url.searchParams.append(column, `cs.{${value.join(",")}}`);
|
|
650
|
-
else this.url.searchParams.append(column, `cs.${JSON.stringify(value)}`);
|
|
651
|
-
return this;
|
|
652
|
-
}
|
|
653
|
-
/**
|
|
654
|
-
* Only relevant for jsonb, array, and range columns. Match only rows where
|
|
655
|
-
* every element appearing in `column` is contained by `value`.
|
|
656
1735
|
*
|
|
657
|
-
* @
|
|
658
|
-
* @param value - The jsonb, array, or range value to filter with
|
|
659
|
-
*/
|
|
660
|
-
containedBy(column, value) {
|
|
661
|
-
if (typeof value === "string") this.url.searchParams.append(column, `cd.${value}`);
|
|
662
|
-
else if (Array.isArray(value)) this.url.searchParams.append(column, `cd.{${value.join(",")}}`);
|
|
663
|
-
else this.url.searchParams.append(column, `cd.${JSON.stringify(value)}`);
|
|
664
|
-
return this;
|
|
665
|
-
}
|
|
666
|
-
/**
|
|
667
|
-
* Only relevant for range columns. Match only rows where every element in
|
|
668
|
-
* `column` is greater than any element in `range`.
|
|
1736
|
+
* @category Database
|
|
669
1737
|
*
|
|
670
|
-
* @
|
|
671
|
-
*
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
/**
|
|
678
|
-
* Only relevant for range columns. Match only rows where every element in
|
|
679
|
-
* `column` is either contained in `range` or greater than any element in
|
|
680
|
-
* `range`.
|
|
1738
|
+
* @example On array columns
|
|
1739
|
+
* ```ts
|
|
1740
|
+
* const { data, error } = await supabase
|
|
1741
|
+
* .from('issues')
|
|
1742
|
+
* .select()
|
|
1743
|
+
* .contains('tags', ['is:open', 'priority:low'])
|
|
1744
|
+
* ```
|
|
681
1745
|
*
|
|
682
|
-
* @
|
|
683
|
-
*
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
* Only relevant for range columns. Match only rows where every element in
|
|
691
|
-
* `column` is less than any element in `range`.
|
|
1746
|
+
* @exampleSql On array columns
|
|
1747
|
+
* ```sql
|
|
1748
|
+
* create table
|
|
1749
|
+
* issues (
|
|
1750
|
+
* id int8 primary key,
|
|
1751
|
+
* title text,
|
|
1752
|
+
* tags text[]
|
|
1753
|
+
* );
|
|
692
1754
|
*
|
|
693
|
-
*
|
|
694
|
-
*
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
}
|
|
700
|
-
/**
|
|
701
|
-
* Only relevant for range columns. Match only rows where every element in
|
|
702
|
-
* `column` is either contained in `range` or less than any element in
|
|
703
|
-
* `range`.
|
|
1755
|
+
* insert into
|
|
1756
|
+
* issues (id, title, tags)
|
|
1757
|
+
* values
|
|
1758
|
+
* (1, 'Cache invalidation is not working', array['is:open', 'severity:high', 'priority:low']),
|
|
1759
|
+
* (2, 'Use better names', array['is:open', 'severity:low', 'priority:medium']);
|
|
1760
|
+
* ```
|
|
704
1761
|
*
|
|
705
|
-
* @
|
|
706
|
-
*
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
}
|
|
1762
|
+
* @exampleResponse On array columns
|
|
1763
|
+
* ```json
|
|
1764
|
+
* {
|
|
1765
|
+
* "data": [
|
|
1766
|
+
* {
|
|
1767
|
+
* "title": "Cache invalidation is not working"
|
|
1768
|
+
* }
|
|
1769
|
+
* ],
|
|
1770
|
+
* "status": 200,
|
|
1771
|
+
* "statusText": "OK"
|
|
1772
|
+
* }
|
|
1773
|
+
* ```
|
|
1774
|
+
*
|
|
1775
|
+
* @exampleDescription On range columns
|
|
1776
|
+
* Postgres supports a number of [range
|
|
1777
|
+
* types](https://www.postgresql.org/docs/current/rangetypes.html). You
|
|
1778
|
+
* can filter on range columns using the string representation of range
|
|
1779
|
+
* values.
|
|
1780
|
+
*
|
|
1781
|
+
* @example On range columns
|
|
1782
|
+
* ```ts
|
|
1783
|
+
* const { data, error } = await supabase
|
|
1784
|
+
* .from('reservations')
|
|
1785
|
+
* .select()
|
|
1786
|
+
* .contains('during', '[2000-01-01 13:00, 2000-01-01 13:30)')
|
|
1787
|
+
* ```
|
|
1788
|
+
*
|
|
1789
|
+
* @exampleSql On range columns
|
|
1790
|
+
* ```sql
|
|
1791
|
+
* create table
|
|
1792
|
+
* reservations (
|
|
1793
|
+
* id int8 primary key,
|
|
1794
|
+
* room_name text,
|
|
1795
|
+
* during tsrange
|
|
1796
|
+
* );
|
|
1797
|
+
*
|
|
1798
|
+
* insert into
|
|
1799
|
+
* reservations (id, room_name, during)
|
|
1800
|
+
* values
|
|
1801
|
+
* (1, 'Emerald', '[2000-01-01 13:00, 2000-01-01 15:00)'),
|
|
1802
|
+
* (2, 'Topaz', '[2000-01-02 09:00, 2000-01-02 10:00)');
|
|
1803
|
+
* ```
|
|
1804
|
+
*
|
|
1805
|
+
* @exampleResponse On range columns
|
|
1806
|
+
* ```json
|
|
1807
|
+
* {
|
|
1808
|
+
* "data": [
|
|
1809
|
+
* {
|
|
1810
|
+
* "id": 1,
|
|
1811
|
+
* "room_name": "Emerald",
|
|
1812
|
+
* "during": "[\"2000-01-01 13:00:00\",\"2000-01-01 15:00:00\")"
|
|
1813
|
+
* }
|
|
1814
|
+
* ],
|
|
1815
|
+
* "status": 200,
|
|
1816
|
+
* "statusText": "OK"
|
|
1817
|
+
* }
|
|
1818
|
+
* ```
|
|
1819
|
+
*
|
|
1820
|
+
* @example On `jsonb` columns
|
|
1821
|
+
* ```ts
|
|
1822
|
+
* const { data, error } = await supabase
|
|
1823
|
+
* .from('users')
|
|
1824
|
+
* .select('name')
|
|
1825
|
+
* .contains('address', { postcode: 90210 })
|
|
1826
|
+
* ```
|
|
1827
|
+
*
|
|
1828
|
+
* @exampleSql On `jsonb` columns
|
|
1829
|
+
* ```sql
|
|
1830
|
+
* create table
|
|
1831
|
+
* users (
|
|
1832
|
+
* id int8 primary key,
|
|
1833
|
+
* name text,
|
|
1834
|
+
* address jsonb
|
|
1835
|
+
* );
|
|
1836
|
+
*
|
|
1837
|
+
* insert into
|
|
1838
|
+
* users (id, name, address)
|
|
1839
|
+
* values
|
|
1840
|
+
* (1, 'Michael', '{ "postcode": 90210, "street": "Melrose Place" }'),
|
|
1841
|
+
* (2, 'Jane', '{}');
|
|
1842
|
+
* ```
|
|
1843
|
+
*
|
|
1844
|
+
* @exampleResponse On `jsonb` columns
|
|
1845
|
+
* ```json
|
|
1846
|
+
* {
|
|
1847
|
+
* "data": [
|
|
1848
|
+
* {
|
|
1849
|
+
* "name": "Michael"
|
|
1850
|
+
* }
|
|
1851
|
+
* ],
|
|
1852
|
+
* "status": 200,
|
|
1853
|
+
* "statusText": "OK"
|
|
1854
|
+
* }
|
|
1855
|
+
* ```
|
|
1856
|
+
*/
|
|
1857
|
+
contains(column, value) {
|
|
1858
|
+
if (typeof value === "string") this.url.searchParams.append(column, `cs.${value}`);
|
|
1859
|
+
else if (Array.isArray(value)) this.url.searchParams.append(column, `cs.{${value.join(",")}}`);
|
|
1860
|
+
else this.url.searchParams.append(column, `cs.${JSON.stringify(value)}`);
|
|
1861
|
+
return this;
|
|
1862
|
+
}
|
|
1863
|
+
/**
|
|
1864
|
+
* Only relevant for jsonb, array, and range columns. Match only rows where
|
|
1865
|
+
* every element appearing in `column` is contained by `value`.
|
|
1866
|
+
*
|
|
1867
|
+
* @param column - The jsonb, array, or range column to filter on
|
|
1868
|
+
* @param value - The jsonb, array, or range value to filter with
|
|
1869
|
+
*
|
|
1870
|
+
* @category Database
|
|
1871
|
+
*
|
|
1872
|
+
* @example On array columns
|
|
1873
|
+
* ```ts
|
|
1874
|
+
* const { data, error } = await supabase
|
|
1875
|
+
* .from('classes')
|
|
1876
|
+
* .select('name')
|
|
1877
|
+
* .containedBy('days', ['monday', 'tuesday', 'wednesday', 'friday'])
|
|
1878
|
+
* ```
|
|
1879
|
+
*
|
|
1880
|
+
* @exampleSql On array columns
|
|
1881
|
+
* ```sql
|
|
1882
|
+
* create table
|
|
1883
|
+
* classes (
|
|
1884
|
+
* id int8 primary key,
|
|
1885
|
+
* name text,
|
|
1886
|
+
* days text[]
|
|
1887
|
+
* );
|
|
1888
|
+
*
|
|
1889
|
+
* insert into
|
|
1890
|
+
* classes (id, name, days)
|
|
1891
|
+
* values
|
|
1892
|
+
* (1, 'Chemistry', array['monday', 'friday']),
|
|
1893
|
+
* (2, 'History', array['monday', 'wednesday', 'thursday']);
|
|
1894
|
+
* ```
|
|
1895
|
+
*
|
|
1896
|
+
* @exampleResponse On array columns
|
|
1897
|
+
* ```json
|
|
1898
|
+
* {
|
|
1899
|
+
* "data": [
|
|
1900
|
+
* {
|
|
1901
|
+
* "name": "Chemistry"
|
|
1902
|
+
* }
|
|
1903
|
+
* ],
|
|
1904
|
+
* "status": 200,
|
|
1905
|
+
* "statusText": "OK"
|
|
1906
|
+
* }
|
|
1907
|
+
* ```
|
|
1908
|
+
*
|
|
1909
|
+
* @exampleDescription On range columns
|
|
1910
|
+
* Postgres supports a number of [range
|
|
1911
|
+
* types](https://www.postgresql.org/docs/current/rangetypes.html). You
|
|
1912
|
+
* can filter on range columns using the string representation of range
|
|
1913
|
+
* values.
|
|
1914
|
+
*
|
|
1915
|
+
* @example On range columns
|
|
1916
|
+
* ```ts
|
|
1917
|
+
* const { data, error } = await supabase
|
|
1918
|
+
* .from('reservations')
|
|
1919
|
+
* .select()
|
|
1920
|
+
* .containedBy('during', '[2000-01-01 00:00, 2000-01-01 23:59)')
|
|
1921
|
+
* ```
|
|
1922
|
+
*
|
|
1923
|
+
* @exampleSql On range columns
|
|
1924
|
+
* ```sql
|
|
1925
|
+
* create table
|
|
1926
|
+
* reservations (
|
|
1927
|
+
* id int8 primary key,
|
|
1928
|
+
* room_name text,
|
|
1929
|
+
* during tsrange
|
|
1930
|
+
* );
|
|
1931
|
+
*
|
|
1932
|
+
* insert into
|
|
1933
|
+
* reservations (id, room_name, during)
|
|
1934
|
+
* values
|
|
1935
|
+
* (1, 'Emerald', '[2000-01-01 13:00, 2000-01-01 15:00)'),
|
|
1936
|
+
* (2, 'Topaz', '[2000-01-02 09:00, 2000-01-02 10:00)');
|
|
1937
|
+
* ```
|
|
1938
|
+
*
|
|
1939
|
+
* @exampleResponse On range columns
|
|
1940
|
+
* ```json
|
|
1941
|
+
* {
|
|
1942
|
+
* "data": [
|
|
1943
|
+
* {
|
|
1944
|
+
* "id": 1,
|
|
1945
|
+
* "room_name": "Emerald",
|
|
1946
|
+
* "during": "[\"2000-01-01 13:00:00\",\"2000-01-01 15:00:00\")"
|
|
1947
|
+
* }
|
|
1948
|
+
* ],
|
|
1949
|
+
* "status": 200,
|
|
1950
|
+
* "statusText": "OK"
|
|
1951
|
+
* }
|
|
1952
|
+
* ```
|
|
1953
|
+
*
|
|
1954
|
+
* @example On `jsonb` columns
|
|
1955
|
+
* ```ts
|
|
1956
|
+
* const { data, error } = await supabase
|
|
1957
|
+
* .from('users')
|
|
1958
|
+
* .select('name')
|
|
1959
|
+
* .containedBy('address', {})
|
|
1960
|
+
* ```
|
|
1961
|
+
*
|
|
1962
|
+
* @exampleSql On `jsonb` columns
|
|
1963
|
+
* ```sql
|
|
1964
|
+
* create table
|
|
1965
|
+
* users (
|
|
1966
|
+
* id int8 primary key,
|
|
1967
|
+
* name text,
|
|
1968
|
+
* address jsonb
|
|
1969
|
+
* );
|
|
1970
|
+
*
|
|
1971
|
+
* insert into
|
|
1972
|
+
* users (id, name, address)
|
|
1973
|
+
* values
|
|
1974
|
+
* (1, 'Michael', '{ "postcode": 90210, "street": "Melrose Place" }'),
|
|
1975
|
+
* (2, 'Jane', '{}');
|
|
1976
|
+
* ```
|
|
1977
|
+
*
|
|
1978
|
+
* @exampleResponse On `jsonb` columns
|
|
1979
|
+
* ```json
|
|
1980
|
+
* {
|
|
1981
|
+
* "data": [
|
|
1982
|
+
* {
|
|
1983
|
+
* "name": "Jane"
|
|
1984
|
+
* }
|
|
1985
|
+
* ],
|
|
1986
|
+
* "status": 200,
|
|
1987
|
+
* "statusText": "OK"
|
|
1988
|
+
* }
|
|
1989
|
+
*
|
|
1990
|
+
* ```
|
|
1991
|
+
*/
|
|
1992
|
+
containedBy(column, value) {
|
|
1993
|
+
if (typeof value === "string") this.url.searchParams.append(column, `cd.${value}`);
|
|
1994
|
+
else if (Array.isArray(value)) this.url.searchParams.append(column, `cd.{${value.join(",")}}`);
|
|
1995
|
+
else this.url.searchParams.append(column, `cd.${JSON.stringify(value)}`);
|
|
1996
|
+
return this;
|
|
1997
|
+
}
|
|
1998
|
+
/**
|
|
1999
|
+
* Only relevant for range columns. Match only rows where every element in
|
|
2000
|
+
* `column` is greater than any element in `range`.
|
|
2001
|
+
*
|
|
2002
|
+
* @param column - The range column to filter on
|
|
2003
|
+
* @param range - The range to filter with
|
|
2004
|
+
*
|
|
2005
|
+
* @category Database
|
|
2006
|
+
*
|
|
2007
|
+
* @exampleDescription With `select()`
|
|
2008
|
+
* Postgres supports a number of [range
|
|
2009
|
+
* types](https://www.postgresql.org/docs/current/rangetypes.html). You
|
|
2010
|
+
* can filter on range columns using the string representation of range
|
|
2011
|
+
* values.
|
|
2012
|
+
*
|
|
2013
|
+
* @example With `select()`
|
|
2014
|
+
* ```ts
|
|
2015
|
+
* const { data, error } = await supabase
|
|
2016
|
+
* .from('reservations')
|
|
2017
|
+
* .select()
|
|
2018
|
+
* .rangeGt('during', '[2000-01-02 08:00, 2000-01-02 09:00)')
|
|
2019
|
+
* ```
|
|
2020
|
+
*
|
|
2021
|
+
* @exampleSql With `select()`
|
|
2022
|
+
* ```sql
|
|
2023
|
+
* create table
|
|
2024
|
+
* reservations (
|
|
2025
|
+
* id int8 primary key,
|
|
2026
|
+
* room_name text,
|
|
2027
|
+
* during tsrange
|
|
2028
|
+
* );
|
|
2029
|
+
*
|
|
2030
|
+
* insert into
|
|
2031
|
+
* reservations (id, room_name, during)
|
|
2032
|
+
* values
|
|
2033
|
+
* (1, 'Emerald', '[2000-01-01 13:00, 2000-01-01 15:00)'),
|
|
2034
|
+
* (2, 'Topaz', '[2000-01-02 09:00, 2000-01-02 10:00)');
|
|
2035
|
+
* ```
|
|
2036
|
+
*
|
|
2037
|
+
* @exampleResponse With `select()`
|
|
2038
|
+
* ```json
|
|
2039
|
+
* {
|
|
2040
|
+
* "data": [
|
|
2041
|
+
* {
|
|
2042
|
+
* "id": 2,
|
|
2043
|
+
* "room_name": "Topaz",
|
|
2044
|
+
* "during": "[\"2000-01-02 09:00:00\",\"2000-01-02 10:00:00\")"
|
|
2045
|
+
* }
|
|
2046
|
+
* ],
|
|
2047
|
+
* "status": 200,
|
|
2048
|
+
* "statusText": "OK"
|
|
2049
|
+
* }
|
|
2050
|
+
*
|
|
2051
|
+
* ```
|
|
2052
|
+
*/
|
|
2053
|
+
rangeGt(column, range) {
|
|
2054
|
+
this.url.searchParams.append(column, `sr.${range}`);
|
|
2055
|
+
return this;
|
|
2056
|
+
}
|
|
2057
|
+
/**
|
|
2058
|
+
* Only relevant for range columns. Match only rows where every element in
|
|
2059
|
+
* `column` is either contained in `range` or greater than any element in
|
|
2060
|
+
* `range`.
|
|
2061
|
+
*
|
|
2062
|
+
* @param column - The range column to filter on
|
|
2063
|
+
* @param range - The range to filter with
|
|
2064
|
+
*
|
|
2065
|
+
* @category Database
|
|
2066
|
+
*
|
|
2067
|
+
* @exampleDescription With `select()`
|
|
2068
|
+
* Postgres supports a number of [range
|
|
2069
|
+
* types](https://www.postgresql.org/docs/current/rangetypes.html). You
|
|
2070
|
+
* can filter on range columns using the string representation of range
|
|
2071
|
+
* values.
|
|
2072
|
+
*
|
|
2073
|
+
* @example With `select()`
|
|
2074
|
+
* ```ts
|
|
2075
|
+
* const { data, error } = await supabase
|
|
2076
|
+
* .from('reservations')
|
|
2077
|
+
* .select()
|
|
2078
|
+
* .rangeGte('during', '[2000-01-02 08:30, 2000-01-02 09:30)')
|
|
2079
|
+
* ```
|
|
2080
|
+
*
|
|
2081
|
+
* @exampleSql With `select()`
|
|
2082
|
+
* ```sql
|
|
2083
|
+
* create table
|
|
2084
|
+
* reservations (
|
|
2085
|
+
* id int8 primary key,
|
|
2086
|
+
* room_name text,
|
|
2087
|
+
* during tsrange
|
|
2088
|
+
* );
|
|
2089
|
+
*
|
|
2090
|
+
* insert into
|
|
2091
|
+
* reservations (id, room_name, during)
|
|
2092
|
+
* values
|
|
2093
|
+
* (1, 'Emerald', '[2000-01-01 13:00, 2000-01-01 15:00)'),
|
|
2094
|
+
* (2, 'Topaz', '[2000-01-02 09:00, 2000-01-02 10:00)');
|
|
2095
|
+
* ```
|
|
2096
|
+
*
|
|
2097
|
+
* @exampleResponse With `select()`
|
|
2098
|
+
* ```json
|
|
2099
|
+
* {
|
|
2100
|
+
* "data": [
|
|
2101
|
+
* {
|
|
2102
|
+
* "id": 2,
|
|
2103
|
+
* "room_name": "Topaz",
|
|
2104
|
+
* "during": "[\"2000-01-02 09:00:00\",\"2000-01-02 10:00:00\")"
|
|
2105
|
+
* }
|
|
2106
|
+
* ],
|
|
2107
|
+
* "status": 200,
|
|
2108
|
+
* "statusText": "OK"
|
|
2109
|
+
* }
|
|
2110
|
+
*
|
|
2111
|
+
* ```
|
|
2112
|
+
*/
|
|
2113
|
+
rangeGte(column, range) {
|
|
2114
|
+
this.url.searchParams.append(column, `nxl.${range}`);
|
|
2115
|
+
return this;
|
|
2116
|
+
}
|
|
2117
|
+
/**
|
|
2118
|
+
* Only relevant for range columns. Match only rows where every element in
|
|
2119
|
+
* `column` is less than any element in `range`.
|
|
2120
|
+
*
|
|
2121
|
+
* @param column - The range column to filter on
|
|
2122
|
+
* @param range - The range to filter with
|
|
2123
|
+
*
|
|
2124
|
+
* @category Database
|
|
2125
|
+
*
|
|
2126
|
+
* @exampleDescription With `select()`
|
|
2127
|
+
* Postgres supports a number of [range
|
|
2128
|
+
* types](https://www.postgresql.org/docs/current/rangetypes.html). You
|
|
2129
|
+
* can filter on range columns using the string representation of range
|
|
2130
|
+
* values.
|
|
2131
|
+
*
|
|
2132
|
+
* @example With `select()`
|
|
2133
|
+
* ```ts
|
|
2134
|
+
* const { data, error } = await supabase
|
|
2135
|
+
* .from('reservations')
|
|
2136
|
+
* .select()
|
|
2137
|
+
* .rangeLt('during', '[2000-01-01 15:00, 2000-01-01 16:00)')
|
|
2138
|
+
* ```
|
|
2139
|
+
*
|
|
2140
|
+
* @exampleSql With `select()`
|
|
2141
|
+
* ```sql
|
|
2142
|
+
* create table
|
|
2143
|
+
* reservations (
|
|
2144
|
+
* id int8 primary key,
|
|
2145
|
+
* room_name text,
|
|
2146
|
+
* during tsrange
|
|
2147
|
+
* );
|
|
2148
|
+
*
|
|
2149
|
+
* insert into
|
|
2150
|
+
* reservations (id, room_name, during)
|
|
2151
|
+
* values
|
|
2152
|
+
* (1, 'Emerald', '[2000-01-01 13:00, 2000-01-01 15:00)'),
|
|
2153
|
+
* (2, 'Topaz', '[2000-01-02 09:00, 2000-01-02 10:00)');
|
|
2154
|
+
* ```
|
|
2155
|
+
*
|
|
2156
|
+
* @exampleResponse With `select()`
|
|
2157
|
+
* ```json
|
|
2158
|
+
* {
|
|
2159
|
+
* "data": [
|
|
2160
|
+
* {
|
|
2161
|
+
* "id": 1,
|
|
2162
|
+
* "room_name": "Emerald",
|
|
2163
|
+
* "during": "[\"2000-01-01 13:00:00\",\"2000-01-01 15:00:00\")"
|
|
2164
|
+
* }
|
|
2165
|
+
* ],
|
|
2166
|
+
* "status": 200,
|
|
2167
|
+
* "statusText": "OK"
|
|
2168
|
+
* }
|
|
2169
|
+
* ```
|
|
2170
|
+
*/
|
|
2171
|
+
rangeLt(column, range) {
|
|
2172
|
+
this.url.searchParams.append(column, `sl.${range}`);
|
|
2173
|
+
return this;
|
|
2174
|
+
}
|
|
2175
|
+
/**
|
|
2176
|
+
* Only relevant for range columns. Match only rows where every element in
|
|
2177
|
+
* `column` is either contained in `range` or less than any element in
|
|
2178
|
+
* `range`.
|
|
2179
|
+
*
|
|
2180
|
+
* @param column - The range column to filter on
|
|
2181
|
+
* @param range - The range to filter with
|
|
2182
|
+
*
|
|
2183
|
+
* @category Database
|
|
2184
|
+
*
|
|
2185
|
+
* @exampleDescription With `select()`
|
|
2186
|
+
* Postgres supports a number of [range
|
|
2187
|
+
* types](https://www.postgresql.org/docs/current/rangetypes.html). You
|
|
2188
|
+
* can filter on range columns using the string representation of range
|
|
2189
|
+
* values.
|
|
2190
|
+
*
|
|
2191
|
+
* @example With `select()`
|
|
2192
|
+
* ```ts
|
|
2193
|
+
* const { data, error } = await supabase
|
|
2194
|
+
* .from('reservations')
|
|
2195
|
+
* .select()
|
|
2196
|
+
* .rangeLte('during', '[2000-01-01 14:00, 2000-01-01 16:00)')
|
|
2197
|
+
* ```
|
|
2198
|
+
*
|
|
2199
|
+
* @exampleSql With `select()`
|
|
2200
|
+
* ```sql
|
|
2201
|
+
* create table
|
|
2202
|
+
* reservations (
|
|
2203
|
+
* id int8 primary key,
|
|
2204
|
+
* room_name text,
|
|
2205
|
+
* during tsrange
|
|
2206
|
+
* );
|
|
2207
|
+
*
|
|
2208
|
+
* insert into
|
|
2209
|
+
* reservations (id, room_name, during)
|
|
2210
|
+
* values
|
|
2211
|
+
* (1, 'Emerald', '[2000-01-01 13:00, 2000-01-01 15:00)'),
|
|
2212
|
+
* (2, 'Topaz', '[2000-01-02 09:00, 2000-01-02 10:00)');
|
|
2213
|
+
* ```
|
|
2214
|
+
*
|
|
2215
|
+
* @exampleResponse With `select()`
|
|
2216
|
+
* ```json
|
|
2217
|
+
* {
|
|
2218
|
+
* "data": [
|
|
2219
|
+
* {
|
|
2220
|
+
* "id": 1,
|
|
2221
|
+
* "room_name": "Emerald",
|
|
2222
|
+
* "during": "[\"2000-01-01 13:00:00\",\"2000-01-01 15:00:00\")"
|
|
2223
|
+
* }
|
|
2224
|
+
* ],
|
|
2225
|
+
* "status": 200,
|
|
2226
|
+
* "statusText": "OK"
|
|
2227
|
+
* }
|
|
2228
|
+
*
|
|
2229
|
+
* ```
|
|
2230
|
+
*/
|
|
2231
|
+
rangeLte(column, range) {
|
|
2232
|
+
this.url.searchParams.append(column, `nxr.${range}`);
|
|
2233
|
+
return this;
|
|
2234
|
+
}
|
|
712
2235
|
/**
|
|
713
2236
|
* Only relevant for range columns. Match only rows where `column` is
|
|
714
2237
|
* mutually exclusive to `range` and there can be no element between the two
|
|
@@ -716,6 +2239,53 @@ var PostgrestFilterBuilder = class extends PostgrestTransformBuilder {
|
|
|
716
2239
|
*
|
|
717
2240
|
* @param column - The range column to filter on
|
|
718
2241
|
* @param range - The range to filter with
|
|
2242
|
+
*
|
|
2243
|
+
* @category Database
|
|
2244
|
+
*
|
|
2245
|
+
* @exampleDescription With `select()`
|
|
2246
|
+
* Postgres supports a number of [range
|
|
2247
|
+
* types](https://www.postgresql.org/docs/current/rangetypes.html). You
|
|
2248
|
+
* can filter on range columns using the string representation of range
|
|
2249
|
+
* values.
|
|
2250
|
+
*
|
|
2251
|
+
* @example With `select()`
|
|
2252
|
+
* ```ts
|
|
2253
|
+
* const { data, error } = await supabase
|
|
2254
|
+
* .from('reservations')
|
|
2255
|
+
* .select()
|
|
2256
|
+
* .rangeAdjacent('during', '[2000-01-01 12:00, 2000-01-01 13:00)')
|
|
2257
|
+
* ```
|
|
2258
|
+
*
|
|
2259
|
+
* @exampleSql With `select()`
|
|
2260
|
+
* ```sql
|
|
2261
|
+
* create table
|
|
2262
|
+
* reservations (
|
|
2263
|
+
* id int8 primary key,
|
|
2264
|
+
* room_name text,
|
|
2265
|
+
* during tsrange
|
|
2266
|
+
* );
|
|
2267
|
+
*
|
|
2268
|
+
* insert into
|
|
2269
|
+
* reservations (id, room_name, during)
|
|
2270
|
+
* values
|
|
2271
|
+
* (1, 'Emerald', '[2000-01-01 13:00, 2000-01-01 15:00)'),
|
|
2272
|
+
* (2, 'Topaz', '[2000-01-02 09:00, 2000-01-02 10:00)');
|
|
2273
|
+
* ```
|
|
2274
|
+
*
|
|
2275
|
+
* @exampleResponse With `select()`
|
|
2276
|
+
* ```json
|
|
2277
|
+
* {
|
|
2278
|
+
* "data": [
|
|
2279
|
+
* {
|
|
2280
|
+
* "id": 1,
|
|
2281
|
+
* "room_name": "Emerald",
|
|
2282
|
+
* "during": "[\"2000-01-01 13:00:00\",\"2000-01-01 15:00:00\")"
|
|
2283
|
+
* }
|
|
2284
|
+
* ],
|
|
2285
|
+
* "status": 200,
|
|
2286
|
+
* "statusText": "OK"
|
|
2287
|
+
* }
|
|
2288
|
+
* ```
|
|
719
2289
|
*/
|
|
720
2290
|
rangeAdjacent(column, range) {
|
|
721
2291
|
this.url.searchParams.append(column, `adj.${range}`);
|
|
@@ -725,23 +2295,200 @@ var PostgrestFilterBuilder = class extends PostgrestTransformBuilder {
|
|
|
725
2295
|
* Only relevant for array and range columns. Match only rows where
|
|
726
2296
|
* `column` and `value` have an element in common.
|
|
727
2297
|
*
|
|
728
|
-
* @param column - The array or range column to filter on
|
|
729
|
-
* @param value - The array or range value to filter with
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
*
|
|
738
|
-
*
|
|
2298
|
+
* @param column - The array or range column to filter on
|
|
2299
|
+
* @param value - The array or range value to filter with
|
|
2300
|
+
*
|
|
2301
|
+
* @category Database
|
|
2302
|
+
*
|
|
2303
|
+
* @example On array columns
|
|
2304
|
+
* ```ts
|
|
2305
|
+
* const { data, error } = await supabase
|
|
2306
|
+
* .from('issues')
|
|
2307
|
+
* .select('title')
|
|
2308
|
+
* .overlaps('tags', ['is:closed', 'severity:high'])
|
|
2309
|
+
* ```
|
|
2310
|
+
*
|
|
2311
|
+
* @exampleSql On array columns
|
|
2312
|
+
* ```sql
|
|
2313
|
+
* create table
|
|
2314
|
+
* issues (
|
|
2315
|
+
* id int8 primary key,
|
|
2316
|
+
* title text,
|
|
2317
|
+
* tags text[]
|
|
2318
|
+
* );
|
|
2319
|
+
*
|
|
2320
|
+
* insert into
|
|
2321
|
+
* issues (id, title, tags)
|
|
2322
|
+
* values
|
|
2323
|
+
* (1, 'Cache invalidation is not working', array['is:open', 'severity:high', 'priority:low']),
|
|
2324
|
+
* (2, 'Use better names', array['is:open', 'severity:low', 'priority:medium']);
|
|
2325
|
+
* ```
|
|
2326
|
+
*
|
|
2327
|
+
* @exampleResponse On array columns
|
|
2328
|
+
* ```json
|
|
2329
|
+
* {
|
|
2330
|
+
* "data": [
|
|
2331
|
+
* {
|
|
2332
|
+
* "title": "Cache invalidation is not working"
|
|
2333
|
+
* }
|
|
2334
|
+
* ],
|
|
2335
|
+
* "status": 200,
|
|
2336
|
+
* "statusText": "OK"
|
|
2337
|
+
* }
|
|
2338
|
+
* ```
|
|
2339
|
+
*
|
|
2340
|
+
* @exampleDescription On range columns
|
|
2341
|
+
* Postgres supports a number of [range
|
|
2342
|
+
* types](https://www.postgresql.org/docs/current/rangetypes.html). You
|
|
2343
|
+
* can filter on range columns using the string representation of range
|
|
2344
|
+
* values.
|
|
2345
|
+
*
|
|
2346
|
+
* @example On range columns
|
|
2347
|
+
* ```ts
|
|
2348
|
+
* const { data, error } = await supabase
|
|
2349
|
+
* .from('reservations')
|
|
2350
|
+
* .select()
|
|
2351
|
+
* .overlaps('during', '[2000-01-01 12:45, 2000-01-01 13:15)')
|
|
2352
|
+
* ```
|
|
2353
|
+
*
|
|
2354
|
+
* @exampleSql On range columns
|
|
2355
|
+
* ```sql
|
|
2356
|
+
* create table
|
|
2357
|
+
* reservations (
|
|
2358
|
+
* id int8 primary key,
|
|
2359
|
+
* room_name text,
|
|
2360
|
+
* during tsrange
|
|
2361
|
+
* );
|
|
2362
|
+
*
|
|
2363
|
+
* insert into
|
|
2364
|
+
* reservations (id, room_name, during)
|
|
2365
|
+
* values
|
|
2366
|
+
* (1, 'Emerald', '[2000-01-01 13:00, 2000-01-01 15:00)'),
|
|
2367
|
+
* (2, 'Topaz', '[2000-01-02 09:00, 2000-01-02 10:00)');
|
|
2368
|
+
* ```
|
|
2369
|
+
*
|
|
2370
|
+
* @exampleResponse On range columns
|
|
2371
|
+
* ```json
|
|
2372
|
+
* {
|
|
2373
|
+
* "data": [
|
|
2374
|
+
* {
|
|
2375
|
+
* "id": 1,
|
|
2376
|
+
* "room_name": "Emerald",
|
|
2377
|
+
* "during": "[\"2000-01-01 13:00:00\",\"2000-01-01 15:00:00\")"
|
|
2378
|
+
* }
|
|
2379
|
+
* ],
|
|
2380
|
+
* "status": 200,
|
|
2381
|
+
* "statusText": "OK"
|
|
2382
|
+
* }
|
|
2383
|
+
* ```
|
|
2384
|
+
*/
|
|
2385
|
+
overlaps(column, value) {
|
|
2386
|
+
if (typeof value === "string") this.url.searchParams.append(column, `ov.${value}`);
|
|
2387
|
+
else this.url.searchParams.append(column, `ov.{${value.join(",")}}`);
|
|
2388
|
+
return this;
|
|
2389
|
+
}
|
|
2390
|
+
/**
|
|
2391
|
+
* Only relevant for text and tsvector columns. Match only rows where
|
|
2392
|
+
* `column` matches the query string in `query`.
|
|
2393
|
+
*
|
|
2394
|
+
* @param column - The text or tsvector column to filter on
|
|
2395
|
+
* @param query - The query text to match with
|
|
2396
|
+
* @param options - Named parameters
|
|
2397
|
+
* @param options.config - The text search configuration to use
|
|
2398
|
+
* @param options.type - Change how the `query` text is interpreted
|
|
2399
|
+
*
|
|
2400
|
+
* @category Database
|
|
2401
|
+
*
|
|
2402
|
+
* @remarks
|
|
2403
|
+
* - For more information, see [Postgres full text search](/docs/guides/database/full-text-search).
|
|
2404
|
+
*
|
|
2405
|
+
* @example Text search
|
|
2406
|
+
* ```ts
|
|
2407
|
+
* const result = await supabase
|
|
2408
|
+
* .from("texts")
|
|
2409
|
+
* .select("content")
|
|
2410
|
+
* .textSearch("content", `'eggs' & 'ham'`, {
|
|
2411
|
+
* config: "english",
|
|
2412
|
+
* });
|
|
2413
|
+
* ```
|
|
2414
|
+
*
|
|
2415
|
+
* @exampleSql Text search
|
|
2416
|
+
* ```sql
|
|
2417
|
+
* create table texts (
|
|
2418
|
+
* id bigint
|
|
2419
|
+
* primary key
|
|
2420
|
+
* generated always as identity,
|
|
2421
|
+
* content text
|
|
2422
|
+
* );
|
|
2423
|
+
*
|
|
2424
|
+
* insert into texts (content) values
|
|
2425
|
+
* ('Four score and seven years ago'),
|
|
2426
|
+
* ('The road goes ever on and on'),
|
|
2427
|
+
* ('Green eggs and ham')
|
|
2428
|
+
* ;
|
|
2429
|
+
* ```
|
|
2430
|
+
*
|
|
2431
|
+
* @exampleResponse Text search
|
|
2432
|
+
* ```json
|
|
2433
|
+
* {
|
|
2434
|
+
* "data": [
|
|
2435
|
+
* {
|
|
2436
|
+
* "content": "Green eggs and ham"
|
|
2437
|
+
* }
|
|
2438
|
+
* ],
|
|
2439
|
+
* "status": 200,
|
|
2440
|
+
* "statusText": "OK"
|
|
2441
|
+
* }
|
|
2442
|
+
* ```
|
|
2443
|
+
*
|
|
2444
|
+
* @exampleDescription Basic normalization
|
|
2445
|
+
* Uses PostgreSQL's `plainto_tsquery` function.
|
|
2446
|
+
*
|
|
2447
|
+
* @example Basic normalization
|
|
2448
|
+
* ```ts
|
|
2449
|
+
* const { data, error } = await supabase
|
|
2450
|
+
* .from('quotes')
|
|
2451
|
+
* .select('catchphrase')
|
|
2452
|
+
* .textSearch('catchphrase', `'fat' & 'cat'`, {
|
|
2453
|
+
* type: 'plain',
|
|
2454
|
+
* config: 'english'
|
|
2455
|
+
* })
|
|
2456
|
+
* ```
|
|
2457
|
+
*
|
|
2458
|
+
* @exampleDescription Full normalization
|
|
2459
|
+
* Uses PostgreSQL's `phraseto_tsquery` function.
|
|
2460
|
+
*
|
|
2461
|
+
* @example Full normalization
|
|
2462
|
+
* ```ts
|
|
2463
|
+
* const { data, error } = await supabase
|
|
2464
|
+
* .from('quotes')
|
|
2465
|
+
* .select('catchphrase')
|
|
2466
|
+
* .textSearch('catchphrase', `'fat' & 'cat'`, {
|
|
2467
|
+
* type: 'phrase',
|
|
2468
|
+
* config: 'english'
|
|
2469
|
+
* })
|
|
2470
|
+
* ```
|
|
2471
|
+
*
|
|
2472
|
+
* @exampleDescription Websearch
|
|
2473
|
+
* Uses PostgreSQL's `websearch_to_tsquery` function.
|
|
2474
|
+
* This function will never raise syntax errors, which makes it possible to use raw user-supplied input for search, and can be used
|
|
2475
|
+
* with advanced operators.
|
|
739
2476
|
*
|
|
740
|
-
*
|
|
741
|
-
*
|
|
742
|
-
*
|
|
743
|
-
*
|
|
744
|
-
*
|
|
2477
|
+
* - `unquoted text`: text not inside quote marks will be converted to terms separated by & operators, as if processed by plainto_tsquery.
|
|
2478
|
+
* - `"quoted text"`: text inside quote marks will be converted to terms separated by `<->` operators, as if processed by phraseto_tsquery.
|
|
2479
|
+
* - `OR`: the word “or” will be converted to the | operator.
|
|
2480
|
+
* - `-`: a dash will be converted to the ! operator.
|
|
2481
|
+
*
|
|
2482
|
+
* @example Websearch
|
|
2483
|
+
* ```ts
|
|
2484
|
+
* const { data, error } = await supabase
|
|
2485
|
+
* .from('quotes')
|
|
2486
|
+
* .select('catchphrase')
|
|
2487
|
+
* .textSearch('catchphrase', `'fat or cat'`, {
|
|
2488
|
+
* type: 'websearch',
|
|
2489
|
+
* config: 'english'
|
|
2490
|
+
* })
|
|
2491
|
+
* ```
|
|
745
2492
|
*/
|
|
746
2493
|
textSearch(column, query, { config, type } = {}) {
|
|
747
2494
|
let typePart = "";
|
|
@@ -758,9 +2505,45 @@ var PostgrestFilterBuilder = class extends PostgrestTransformBuilder {
|
|
|
758
2505
|
*
|
|
759
2506
|
* @param query - The object to filter with, with column names as keys mapped
|
|
760
2507
|
* to their filter values
|
|
2508
|
+
*
|
|
2509
|
+
* @category Database
|
|
2510
|
+
*
|
|
2511
|
+
* @example With `select()`
|
|
2512
|
+
* ```ts
|
|
2513
|
+
* const { data, error } = await supabase
|
|
2514
|
+
* .from('characters')
|
|
2515
|
+
* .select('name')
|
|
2516
|
+
* .match({ id: 2, name: 'Leia' })
|
|
2517
|
+
* ```
|
|
2518
|
+
*
|
|
2519
|
+
* @exampleSql With `select()`
|
|
2520
|
+
* ```sql
|
|
2521
|
+
* create table
|
|
2522
|
+
* characters (id int8 primary key, name text);
|
|
2523
|
+
*
|
|
2524
|
+
* insert into
|
|
2525
|
+
* characters (id, name)
|
|
2526
|
+
* values
|
|
2527
|
+
* (1, 'Luke'),
|
|
2528
|
+
* (2, 'Leia'),
|
|
2529
|
+
* (3, 'Han');
|
|
2530
|
+
* ```
|
|
2531
|
+
*
|
|
2532
|
+
* @exampleResponse With `select()`
|
|
2533
|
+
* ```json
|
|
2534
|
+
* {
|
|
2535
|
+
* "data": [
|
|
2536
|
+
* {
|
|
2537
|
+
* "name": "Leia"
|
|
2538
|
+
* }
|
|
2539
|
+
* ],
|
|
2540
|
+
* "status": 200,
|
|
2541
|
+
* "statusText": "OK"
|
|
2542
|
+
* }
|
|
2543
|
+
* ```
|
|
761
2544
|
*/
|
|
762
2545
|
match(query) {
|
|
763
|
-
Object.entries(query).forEach(([column, value]) => {
|
|
2546
|
+
Object.entries(query).filter(([_, value]) => value !== void 0).forEach(([column, value]) => {
|
|
764
2547
|
this.url.searchParams.append(column, `eq.${value}`);
|
|
765
2548
|
});
|
|
766
2549
|
return this;
|
|
@@ -777,6 +2560,51 @@ var PostgrestFilterBuilder = class extends PostgrestTransformBuilder {
|
|
|
777
2560
|
* @param operator - The operator to be negated to filter with, following
|
|
778
2561
|
* PostgREST syntax
|
|
779
2562
|
* @param value - The value to filter with, following PostgREST syntax
|
|
2563
|
+
*
|
|
2564
|
+
* @category Database
|
|
2565
|
+
*
|
|
2566
|
+
* @remarks
|
|
2567
|
+
* not() expects you to use the raw PostgREST syntax for the filter values.
|
|
2568
|
+
*
|
|
2569
|
+
* ```ts
|
|
2570
|
+
* .not('id', 'in', '(5,6,7)') // Use `()` for `in` filter
|
|
2571
|
+
* .not('arraycol', 'cs', '{"a","b"}') // Use `cs` for `contains()`, `{}` for array values
|
|
2572
|
+
* ```
|
|
2573
|
+
*
|
|
2574
|
+
* @example With `select()`
|
|
2575
|
+
* ```ts
|
|
2576
|
+
* const { data, error } = await supabase
|
|
2577
|
+
* .from('countries')
|
|
2578
|
+
* .select()
|
|
2579
|
+
* .not('name', 'is', null)
|
|
2580
|
+
* ```
|
|
2581
|
+
*
|
|
2582
|
+
* @exampleSql With `select()`
|
|
2583
|
+
* ```sql
|
|
2584
|
+
* create table
|
|
2585
|
+
* countries (id int8 primary key, name text);
|
|
2586
|
+
*
|
|
2587
|
+
* insert into
|
|
2588
|
+
* countries (id, name)
|
|
2589
|
+
* values
|
|
2590
|
+
* (1, 'null'),
|
|
2591
|
+
* (2, null);
|
|
2592
|
+
* ```
|
|
2593
|
+
*
|
|
2594
|
+
* @exampleResponse With `select()`
|
|
2595
|
+
* ```json
|
|
2596
|
+
* {
|
|
2597
|
+
* "data": [
|
|
2598
|
+
* {
|
|
2599
|
+
* "id": 1,
|
|
2600
|
+
* "name": "null"
|
|
2601
|
+
* }
|
|
2602
|
+
* ],
|
|
2603
|
+
* "status": 200,
|
|
2604
|
+
* "statusText": "OK"
|
|
2605
|
+
* }
|
|
2606
|
+
*
|
|
2607
|
+
* ```
|
|
780
2608
|
*/
|
|
781
2609
|
not(column, operator, value) {
|
|
782
2610
|
this.url.searchParams.append(column, `not.${operator}.${value}`);
|
|
@@ -789,31 +2617,265 @@ var PostgrestFilterBuilder = class extends PostgrestTransformBuilder {
|
|
|
789
2617
|
* syntax](https://postgrest.org/en/stable/api.html#operators). You also need
|
|
790
2618
|
* to make sure it's properly sanitized.
|
|
791
2619
|
*
|
|
792
|
-
* It's currently not possible to do an `.or()` filter across multiple tables.
|
|
2620
|
+
* It's currently not possible to do an `.or()` filter across multiple tables.
|
|
2621
|
+
*
|
|
2622
|
+
* @param filters - The filters to use, following PostgREST syntax
|
|
2623
|
+
* @param options - Named parameters
|
|
2624
|
+
* @param options.referencedTable - Set this to filter on referenced tables
|
|
2625
|
+
* instead of the parent table
|
|
2626
|
+
* @param options.foreignTable - Deprecated, use `referencedTable` instead
|
|
2627
|
+
*
|
|
2628
|
+
* @category Database
|
|
2629
|
+
*
|
|
2630
|
+
* @remarks
|
|
2631
|
+
* or() expects you to use the raw PostgREST syntax for the filter names and values.
|
|
2632
|
+
*
|
|
2633
|
+
* ```ts
|
|
2634
|
+
* .or('id.in.(5,6,7), arraycol.cs.{"a","b"}') // Use `()` for `in` filter, `{}` for array values and `cs` for `contains()`.
|
|
2635
|
+
* .or('id.in.(5,6,7), arraycol.cd.{"a","b"}') // Use `cd` for `containedBy()`
|
|
2636
|
+
* ```
|
|
2637
|
+
*
|
|
2638
|
+
* @example With `select()`
|
|
2639
|
+
* ```ts
|
|
2640
|
+
* const { data, error } = await supabase
|
|
2641
|
+
* .from('characters')
|
|
2642
|
+
* .select('name')
|
|
2643
|
+
* .or('id.eq.2,name.eq.Han')
|
|
2644
|
+
* ```
|
|
2645
|
+
*
|
|
2646
|
+
* @exampleSql With `select()`
|
|
2647
|
+
* ```sql
|
|
2648
|
+
* create table
|
|
2649
|
+
* characters (id int8 primary key, name text);
|
|
2650
|
+
*
|
|
2651
|
+
* insert into
|
|
2652
|
+
* characters (id, name)
|
|
2653
|
+
* values
|
|
2654
|
+
* (1, 'Luke'),
|
|
2655
|
+
* (2, 'Leia'),
|
|
2656
|
+
* (3, 'Han');
|
|
2657
|
+
* ```
|
|
2658
|
+
*
|
|
2659
|
+
* @exampleResponse With `select()`
|
|
2660
|
+
* ```json
|
|
2661
|
+
* {
|
|
2662
|
+
* "data": [
|
|
2663
|
+
* {
|
|
2664
|
+
* "name": "Leia"
|
|
2665
|
+
* },
|
|
2666
|
+
* {
|
|
2667
|
+
* "name": "Han"
|
|
2668
|
+
* }
|
|
2669
|
+
* ],
|
|
2670
|
+
* "status": 200,
|
|
2671
|
+
* "statusText": "OK"
|
|
2672
|
+
* }
|
|
2673
|
+
* ```
|
|
2674
|
+
*
|
|
2675
|
+
* @example Use `or` with `and`
|
|
2676
|
+
* ```ts
|
|
2677
|
+
* const { data, error } = await supabase
|
|
2678
|
+
* .from('characters')
|
|
2679
|
+
* .select('name')
|
|
2680
|
+
* .or('id.gt.3,and(id.eq.1,name.eq.Luke)')
|
|
2681
|
+
* ```
|
|
2682
|
+
*
|
|
2683
|
+
* @exampleSql Use `or` with `and`
|
|
2684
|
+
* ```sql
|
|
2685
|
+
* create table
|
|
2686
|
+
* characters (id int8 primary key, name text);
|
|
2687
|
+
*
|
|
2688
|
+
* insert into
|
|
2689
|
+
* characters (id, name)
|
|
2690
|
+
* values
|
|
2691
|
+
* (1, 'Luke'),
|
|
2692
|
+
* (2, 'Leia'),
|
|
2693
|
+
* (3, 'Han');
|
|
2694
|
+
* ```
|
|
2695
|
+
*
|
|
2696
|
+
* @exampleResponse Use `or` with `and`
|
|
2697
|
+
* ```json
|
|
2698
|
+
* {
|
|
2699
|
+
* "data": [
|
|
2700
|
+
* {
|
|
2701
|
+
* "name": "Luke"
|
|
2702
|
+
* }
|
|
2703
|
+
* ],
|
|
2704
|
+
* "status": 200,
|
|
2705
|
+
* "statusText": "OK"
|
|
2706
|
+
* }
|
|
2707
|
+
* ```
|
|
2708
|
+
*
|
|
2709
|
+
* @example Use `or` on referenced tables
|
|
2710
|
+
* ```ts
|
|
2711
|
+
* const { data, error } = await supabase
|
|
2712
|
+
* .from('orchestral_sections')
|
|
2713
|
+
* .select(`
|
|
2714
|
+
* name,
|
|
2715
|
+
* instruments!inner (
|
|
2716
|
+
* name
|
|
2717
|
+
* )
|
|
2718
|
+
* `)
|
|
2719
|
+
* .or('section_id.eq.1,name.eq.guzheng', { referencedTable: 'instruments' })
|
|
2720
|
+
* ```
|
|
2721
|
+
*
|
|
2722
|
+
* @exampleSql Use `or` on referenced tables
|
|
2723
|
+
* ```sql
|
|
2724
|
+
* create table
|
|
2725
|
+
* orchestral_sections (id int8 primary key, name text);
|
|
2726
|
+
* create table
|
|
2727
|
+
* instruments (
|
|
2728
|
+
* id int8 primary key,
|
|
2729
|
+
* section_id int8 not null references orchestral_sections,
|
|
2730
|
+
* name text
|
|
2731
|
+
* );
|
|
2732
|
+
*
|
|
2733
|
+
* insert into
|
|
2734
|
+
* orchestral_sections (id, name)
|
|
2735
|
+
* values
|
|
2736
|
+
* (1, 'strings'),
|
|
2737
|
+
* (2, 'woodwinds');
|
|
2738
|
+
* insert into
|
|
2739
|
+
* instruments (id, section_id, name)
|
|
2740
|
+
* values
|
|
2741
|
+
* (1, 2, 'flute'),
|
|
2742
|
+
* (2, 1, 'violin');
|
|
2743
|
+
* ```
|
|
2744
|
+
*
|
|
2745
|
+
* @exampleResponse Use `or` on referenced tables
|
|
2746
|
+
* ```json
|
|
2747
|
+
* {
|
|
2748
|
+
* "data": [
|
|
2749
|
+
* {
|
|
2750
|
+
* "name": "strings",
|
|
2751
|
+
* "instruments": [
|
|
2752
|
+
* {
|
|
2753
|
+
* "name": "violin"
|
|
2754
|
+
* }
|
|
2755
|
+
* ]
|
|
2756
|
+
* }
|
|
2757
|
+
* ],
|
|
2758
|
+
* "status": 200,
|
|
2759
|
+
* "statusText": "OK"
|
|
2760
|
+
* }
|
|
2761
|
+
* ```
|
|
2762
|
+
*/
|
|
2763
|
+
or(filters, { foreignTable, referencedTable = foreignTable } = {}) {
|
|
2764
|
+
const key = referencedTable ? `${referencedTable}.or` : "or";
|
|
2765
|
+
this.url.searchParams.append(key, `(${filters})`);
|
|
2766
|
+
return this;
|
|
2767
|
+
}
|
|
2768
|
+
/**
|
|
2769
|
+
* Match only rows which satisfy the filter. This is an escape hatch - you
|
|
2770
|
+
* should use the specific filter methods wherever possible.
|
|
2771
|
+
*
|
|
2772
|
+
* Unlike most filters, `opearator` and `value` are used as-is and need to
|
|
2773
|
+
* follow [PostgREST
|
|
2774
|
+
* syntax](https://postgrest.org/en/stable/api.html#operators). You also need
|
|
2775
|
+
* to make sure they are properly sanitized.
|
|
2776
|
+
*
|
|
2777
|
+
* @param column - The column to filter on
|
|
2778
|
+
* @param operator - The operator to filter with, following PostgREST syntax
|
|
2779
|
+
* @param value - The value to filter with, following PostgREST syntax
|
|
2780
|
+
*
|
|
2781
|
+
* @category Database
|
|
2782
|
+
*
|
|
2783
|
+
* @remarks
|
|
2784
|
+
* filter() expects you to use the raw PostgREST syntax for the filter values.
|
|
2785
|
+
*
|
|
2786
|
+
* ```ts
|
|
2787
|
+
* .filter('id', 'in', '(5,6,7)') // Use `()` for `in` filter
|
|
2788
|
+
* .filter('arraycol', 'cs', '{"a","b"}') // Use `cs` for `contains()`, `{}` for array values
|
|
2789
|
+
* ```
|
|
2790
|
+
*
|
|
2791
|
+
* @example With `select()`
|
|
2792
|
+
* ```ts
|
|
2793
|
+
* const { data, error } = await supabase
|
|
2794
|
+
* .from('characters')
|
|
2795
|
+
* .select()
|
|
2796
|
+
* .filter('name', 'in', '("Han","Yoda")')
|
|
2797
|
+
* ```
|
|
2798
|
+
*
|
|
2799
|
+
* @exampleSql With `select()`
|
|
2800
|
+
* ```sql
|
|
2801
|
+
* create table
|
|
2802
|
+
* characters (id int8 primary key, name text);
|
|
2803
|
+
*
|
|
2804
|
+
* insert into
|
|
2805
|
+
* characters (id, name)
|
|
2806
|
+
* values
|
|
2807
|
+
* (1, 'Luke'),
|
|
2808
|
+
* (2, 'Leia'),
|
|
2809
|
+
* (3, 'Han');
|
|
2810
|
+
* ```
|
|
2811
|
+
*
|
|
2812
|
+
* @exampleResponse With `select()`
|
|
2813
|
+
* ```json
|
|
2814
|
+
* {
|
|
2815
|
+
* "data": [
|
|
2816
|
+
* {
|
|
2817
|
+
* "id": 3,
|
|
2818
|
+
* "name": "Han"
|
|
2819
|
+
* }
|
|
2820
|
+
* ],
|
|
2821
|
+
* "status": 200,
|
|
2822
|
+
* "statusText": "OK"
|
|
2823
|
+
* }
|
|
2824
|
+
* ```
|
|
2825
|
+
*
|
|
2826
|
+
* @example On a referenced table
|
|
2827
|
+
* ```ts
|
|
2828
|
+
* const { data, error } = await supabase
|
|
2829
|
+
* .from('orchestral_sections')
|
|
2830
|
+
* .select(`
|
|
2831
|
+
* name,
|
|
2832
|
+
* instruments!inner (
|
|
2833
|
+
* name
|
|
2834
|
+
* )
|
|
2835
|
+
* `)
|
|
2836
|
+
* .filter('instruments.name', 'eq', 'flute')
|
|
2837
|
+
* ```
|
|
793
2838
|
*
|
|
794
|
-
* @
|
|
795
|
-
*
|
|
796
|
-
*
|
|
797
|
-
*
|
|
798
|
-
*
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
}
|
|
805
|
-
/**
|
|
806
|
-
* Match only rows which satisfy the filter. This is an escape hatch - you
|
|
807
|
-
* should use the specific filter methods wherever possible.
|
|
2839
|
+
* @exampleSql On a referenced table
|
|
2840
|
+
* ```sql
|
|
2841
|
+
* create table
|
|
2842
|
+
* orchestral_sections (id int8 primary key, name text);
|
|
2843
|
+
* create table
|
|
2844
|
+
* instruments (
|
|
2845
|
+
* id int8 primary key,
|
|
2846
|
+
* section_id int8 not null references orchestral_sections,
|
|
2847
|
+
* name text
|
|
2848
|
+
* );
|
|
808
2849
|
*
|
|
809
|
-
*
|
|
810
|
-
*
|
|
811
|
-
*
|
|
812
|
-
*
|
|
2850
|
+
* insert into
|
|
2851
|
+
* orchestral_sections (id, name)
|
|
2852
|
+
* values
|
|
2853
|
+
* (1, 'strings'),
|
|
2854
|
+
* (2, 'woodwinds');
|
|
2855
|
+
* insert into
|
|
2856
|
+
* instruments (id, section_id, name)
|
|
2857
|
+
* values
|
|
2858
|
+
* (1, 2, 'flute'),
|
|
2859
|
+
* (2, 1, 'violin');
|
|
2860
|
+
* ```
|
|
813
2861
|
*
|
|
814
|
-
* @
|
|
815
|
-
*
|
|
816
|
-
*
|
|
2862
|
+
* @exampleResponse On a referenced table
|
|
2863
|
+
* ```json
|
|
2864
|
+
* {
|
|
2865
|
+
* "data": [
|
|
2866
|
+
* {
|
|
2867
|
+
* "name": "woodwinds",
|
|
2868
|
+
* "instruments": [
|
|
2869
|
+
* {
|
|
2870
|
+
* "name": "flute"
|
|
2871
|
+
* }
|
|
2872
|
+
* ]
|
|
2873
|
+
* }
|
|
2874
|
+
* ],
|
|
2875
|
+
* "status": 200,
|
|
2876
|
+
* "statusText": "OK"
|
|
2877
|
+
* }
|
|
2878
|
+
* ```
|
|
817
2879
|
*/
|
|
818
2880
|
filter(column, operator, value) {
|
|
819
2881
|
this.url.searchParams.append(column, `${operator}.${value}`);
|
|
@@ -827,9 +2889,11 @@ var PostgrestQueryBuilder = class {
|
|
|
827
2889
|
/**
|
|
828
2890
|
* Creates a query builder scoped to a Postgres table or view.
|
|
829
2891
|
*
|
|
830
|
-
* @
|
|
2892
|
+
* @category Database
|
|
2893
|
+
*
|
|
2894
|
+
* @example Creating a Postgrest query builder
|
|
831
2895
|
* ```ts
|
|
832
|
-
* import PostgrestQueryBuilder from '@supabase/postgrest-js'
|
|
2896
|
+
* import { PostgrestQueryBuilder } from '@supabase/postgrest-js'
|
|
833
2897
|
*
|
|
834
2898
|
* const query = new PostgrestQueryBuilder(
|
|
835
2899
|
* new URL('https://xyzcompany.supabase.co/rest/v1/users'),
|
|
@@ -2192,6 +4256,105 @@ var PostgrestQueryBuilder = class {
|
|
|
2192
4256
|
*
|
|
2193
4257
|
* `"estimated"`: Uses exact count for low numbers and planned count for high
|
|
2194
4258
|
* numbers.
|
|
4259
|
+
*
|
|
4260
|
+
* @category Database
|
|
4261
|
+
*
|
|
4262
|
+
* @remarks
|
|
4263
|
+
* - `delete()` should always be combined with [filters](/docs/reference/javascript/using-filters) to target the item(s) you wish to delete.
|
|
4264
|
+
* - If you use `delete()` with filters and you have
|
|
4265
|
+
* [RLS](/docs/learn/auth-deep-dive/auth-row-level-security) enabled, only
|
|
4266
|
+
* rows visible through `SELECT` policies are deleted. Note that by default
|
|
4267
|
+
* no rows are visible, so you need at least one `SELECT`/`ALL` policy that
|
|
4268
|
+
* makes the rows visible.
|
|
4269
|
+
* - 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.
|
|
4270
|
+
*
|
|
4271
|
+
* @example Delete a single record
|
|
4272
|
+
* ```ts
|
|
4273
|
+
* const response = await supabase
|
|
4274
|
+
* .from('countries')
|
|
4275
|
+
* .delete()
|
|
4276
|
+
* .eq('id', 1)
|
|
4277
|
+
* ```
|
|
4278
|
+
*
|
|
4279
|
+
* @exampleSql Delete a single record
|
|
4280
|
+
* ```sql
|
|
4281
|
+
* create table
|
|
4282
|
+
* countries (id int8 primary key, name text);
|
|
4283
|
+
*
|
|
4284
|
+
* insert into
|
|
4285
|
+
* countries (id, name)
|
|
4286
|
+
* values
|
|
4287
|
+
* (1, 'Mordor');
|
|
4288
|
+
* ```
|
|
4289
|
+
*
|
|
4290
|
+
* @exampleResponse Delete a single record
|
|
4291
|
+
* ```json
|
|
4292
|
+
* {
|
|
4293
|
+
* "status": 204,
|
|
4294
|
+
* "statusText": "No Content"
|
|
4295
|
+
* }
|
|
4296
|
+
* ```
|
|
4297
|
+
*
|
|
4298
|
+
* @example Delete a record and return it
|
|
4299
|
+
* ```ts
|
|
4300
|
+
* const { data, error } = await supabase
|
|
4301
|
+
* .from('countries')
|
|
4302
|
+
* .delete()
|
|
4303
|
+
* .eq('id', 1)
|
|
4304
|
+
* .select()
|
|
4305
|
+
* ```
|
|
4306
|
+
*
|
|
4307
|
+
* @exampleSql Delete a record and return it
|
|
4308
|
+
* ```sql
|
|
4309
|
+
* create table
|
|
4310
|
+
* countries (id int8 primary key, name text);
|
|
4311
|
+
*
|
|
4312
|
+
* insert into
|
|
4313
|
+
* countries (id, name)
|
|
4314
|
+
* values
|
|
4315
|
+
* (1, 'Mordor');
|
|
4316
|
+
* ```
|
|
4317
|
+
*
|
|
4318
|
+
* @exampleResponse Delete a record and return it
|
|
4319
|
+
* ```json
|
|
4320
|
+
* {
|
|
4321
|
+
* "data": [
|
|
4322
|
+
* {
|
|
4323
|
+
* "id": 1,
|
|
4324
|
+
* "name": "Mordor"
|
|
4325
|
+
* }
|
|
4326
|
+
* ],
|
|
4327
|
+
* "status": 200,
|
|
4328
|
+
* "statusText": "OK"
|
|
4329
|
+
* }
|
|
4330
|
+
* ```
|
|
4331
|
+
*
|
|
4332
|
+
* @example Delete multiple records
|
|
4333
|
+
* ```ts
|
|
4334
|
+
* const response = await supabase
|
|
4335
|
+
* .from('countries')
|
|
4336
|
+
* .delete()
|
|
4337
|
+
* .in('id', [1, 2, 3])
|
|
4338
|
+
* ```
|
|
4339
|
+
*
|
|
4340
|
+
* @exampleSql Delete multiple records
|
|
4341
|
+
* ```sql
|
|
4342
|
+
* create table
|
|
4343
|
+
* countries (id int8 primary key, name text);
|
|
4344
|
+
*
|
|
4345
|
+
* insert into
|
|
4346
|
+
* countries (id, name)
|
|
4347
|
+
* values
|
|
4348
|
+
* (1, 'Rohan'), (2, 'The Shire'), (3, 'Mordor');
|
|
4349
|
+
* ```
|
|
4350
|
+
*
|
|
4351
|
+
* @exampleResponse Delete multiple records
|
|
4352
|
+
* ```json
|
|
4353
|
+
* {
|
|
4354
|
+
* "status": 204,
|
|
4355
|
+
* "statusText": "No Content"
|
|
4356
|
+
* }
|
|
4357
|
+
* ```
|
|
2195
4358
|
*/
|
|
2196
4359
|
delete({ count } = {}) {
|
|
2197
4360
|
var _this$fetch4;
|
|
@@ -2300,7 +4463,34 @@ var PostgrestClient = class PostgrestClient {
|
|
|
2300
4463
|
* @param options.urlLengthLimit - Maximum URL length in characters before warnings/errors are triggered. Defaults to 8000.
|
|
2301
4464
|
* @example
|
|
2302
4465
|
* ```ts
|
|
2303
|
-
* import PostgrestClient from '@supabase/postgrest-js'
|
|
4466
|
+
* import { PostgrestClient } from '@supabase/postgrest-js'
|
|
4467
|
+
*
|
|
4468
|
+
* const postgrest = new PostgrestClient('https://xyzcompany.supabase.co/rest/v1', {
|
|
4469
|
+
* headers: { apikey: 'public-anon-key' },
|
|
4470
|
+
* schema: 'public',
|
|
4471
|
+
* timeout: 30000, // 30 second timeout
|
|
4472
|
+
* })
|
|
4473
|
+
* ```
|
|
4474
|
+
*
|
|
4475
|
+
* @category Database
|
|
4476
|
+
*
|
|
4477
|
+
* @remarks
|
|
4478
|
+
* - A `timeout` option (in milliseconds) can be set to automatically abort requests that take too long.
|
|
4479
|
+
* - A `urlLengthLimit` option (default: 8000) can be set to control when URL length warnings are included in error messages for aborted requests.
|
|
4480
|
+
*
|
|
4481
|
+
* @example Creating a Postgrest client
|
|
4482
|
+
* ```ts
|
|
4483
|
+
* import { PostgrestClient } from '@supabase/postgrest-js'
|
|
4484
|
+
*
|
|
4485
|
+
* const postgrest = new PostgrestClient('https://xyzcompany.supabase.co/rest/v1', {
|
|
4486
|
+
* headers: { apikey: 'public-anon-key' },
|
|
4487
|
+
* schema: 'public',
|
|
4488
|
+
* })
|
|
4489
|
+
* ```
|
|
4490
|
+
*
|
|
4491
|
+
* @example With timeout
|
|
4492
|
+
* ```ts
|
|
4493
|
+
* import { PostgrestClient } from '@supabase/postgrest-js'
|
|
2304
4494
|
*
|
|
2305
4495
|
* const postgrest = new PostgrestClient('https://xyzcompany.supabase.co/rest/v1', {
|
|
2306
4496
|
* headers: { apikey: 'public-anon-key' },
|
|
@@ -2342,6 +4532,8 @@ var PostgrestClient = class PostgrestClient {
|
|
|
2342
4532
|
* Perform a query on a table or a view.
|
|
2343
4533
|
*
|
|
2344
4534
|
* @param relation - The table or view name to query
|
|
4535
|
+
*
|
|
4536
|
+
* @category Database
|
|
2345
4537
|
*/
|
|
2346
4538
|
from(relation) {
|
|
2347
4539
|
if (!relation || typeof relation !== "string" || relation.trim() === "") throw new Error("Invalid relation name: relation must be a non-empty string.");
|
|
@@ -2358,6 +4550,8 @@ var PostgrestClient = class PostgrestClient {
|
|
|
2358
4550
|
* The schema needs to be on the list of exposed schemas inside Supabase.
|
|
2359
4551
|
*
|
|
2360
4552
|
* @param schema - The schema to query
|
|
4553
|
+
*
|
|
4554
|
+
* @category Database
|
|
2361
4555
|
*/
|
|
2362
4556
|
schema(schema) {
|
|
2363
4557
|
return new PostgrestClient(this.url, {
|
|
@@ -2398,6 +4592,139 @@ var PostgrestClient = class PostgrestClient {
|
|
|
2398
4592
|
* .rpc('function_a', {})
|
|
2399
4593
|
* .overrideTypes<{ id: string; user_id: string }[]>()
|
|
2400
4594
|
* ```
|
|
4595
|
+
*
|
|
4596
|
+
* @category Database
|
|
4597
|
+
*
|
|
4598
|
+
* @example Call a Postgres function without arguments
|
|
4599
|
+
* ```ts
|
|
4600
|
+
* const { data, error } = await supabase.rpc('hello_world')
|
|
4601
|
+
* ```
|
|
4602
|
+
*
|
|
4603
|
+
* @exampleSql Call a Postgres function without arguments
|
|
4604
|
+
* ```sql
|
|
4605
|
+
* create function hello_world() returns text as $$
|
|
4606
|
+
* select 'Hello world';
|
|
4607
|
+
* $$ language sql;
|
|
4608
|
+
* ```
|
|
4609
|
+
*
|
|
4610
|
+
* @exampleResponse Call a Postgres function without arguments
|
|
4611
|
+
* ```json
|
|
4612
|
+
* {
|
|
4613
|
+
* "data": "Hello world",
|
|
4614
|
+
* "status": 200,
|
|
4615
|
+
* "statusText": "OK"
|
|
4616
|
+
* }
|
|
4617
|
+
* ```
|
|
4618
|
+
*
|
|
4619
|
+
* @example Call a Postgres function with arguments
|
|
4620
|
+
* ```ts
|
|
4621
|
+
* const { data, error } = await supabase.rpc('echo', { say: '👋' })
|
|
4622
|
+
* ```
|
|
4623
|
+
*
|
|
4624
|
+
* @exampleSql Call a Postgres function with arguments
|
|
4625
|
+
* ```sql
|
|
4626
|
+
* create function echo(say text) returns text as $$
|
|
4627
|
+
* select say;
|
|
4628
|
+
* $$ language sql;
|
|
4629
|
+
* ```
|
|
4630
|
+
*
|
|
4631
|
+
* @exampleResponse Call a Postgres function with arguments
|
|
4632
|
+
* ```json
|
|
4633
|
+
* {
|
|
4634
|
+
* "data": "👋",
|
|
4635
|
+
* "status": 200,
|
|
4636
|
+
* "statusText": "OK"
|
|
4637
|
+
* }
|
|
4638
|
+
*
|
|
4639
|
+
* ```
|
|
4640
|
+
*
|
|
4641
|
+
* @exampleDescription Bulk processing
|
|
4642
|
+
* You can process large payloads by passing in an array as an argument.
|
|
4643
|
+
*
|
|
4644
|
+
* @example Bulk processing
|
|
4645
|
+
* ```ts
|
|
4646
|
+
* const { data, error } = await supabase.rpc('add_one_each', { arr: [1, 2, 3] })
|
|
4647
|
+
* ```
|
|
4648
|
+
*
|
|
4649
|
+
* @exampleSql Bulk processing
|
|
4650
|
+
* ```sql
|
|
4651
|
+
* create function add_one_each(arr int[]) returns int[] as $$
|
|
4652
|
+
* select array_agg(n + 1) from unnest(arr) as n;
|
|
4653
|
+
* $$ language sql;
|
|
4654
|
+
* ```
|
|
4655
|
+
*
|
|
4656
|
+
* @exampleResponse Bulk processing
|
|
4657
|
+
* ```json
|
|
4658
|
+
* {
|
|
4659
|
+
* "data": [
|
|
4660
|
+
* 2,
|
|
4661
|
+
* 3,
|
|
4662
|
+
* 4
|
|
4663
|
+
* ],
|
|
4664
|
+
* "status": 200,
|
|
4665
|
+
* "statusText": "OK"
|
|
4666
|
+
* }
|
|
4667
|
+
* ```
|
|
4668
|
+
*
|
|
4669
|
+
* @exampleDescription Call a Postgres function with filters
|
|
4670
|
+
* Postgres functions that return tables can also be combined with [Filters](/docs/reference/javascript/using-filters) and [Modifiers](/docs/reference/javascript/using-modifiers).
|
|
4671
|
+
*
|
|
4672
|
+
* @example Call a Postgres function with filters
|
|
4673
|
+
* ```ts
|
|
4674
|
+
* const { data, error } = await supabase
|
|
4675
|
+
* .rpc('list_stored_countries')
|
|
4676
|
+
* .eq('id', 1)
|
|
4677
|
+
* .single()
|
|
4678
|
+
* ```
|
|
4679
|
+
*
|
|
4680
|
+
* @exampleSql Call a Postgres function with filters
|
|
4681
|
+
* ```sql
|
|
4682
|
+
* create table
|
|
4683
|
+
* countries (id int8 primary key, name text);
|
|
4684
|
+
*
|
|
4685
|
+
* insert into
|
|
4686
|
+
* countries (id, name)
|
|
4687
|
+
* values
|
|
4688
|
+
* (1, 'Rohan'),
|
|
4689
|
+
* (2, 'The Shire');
|
|
4690
|
+
*
|
|
4691
|
+
* create function list_stored_countries() returns setof countries as $$
|
|
4692
|
+
* select * from countries;
|
|
4693
|
+
* $$ language sql;
|
|
4694
|
+
* ```
|
|
4695
|
+
*
|
|
4696
|
+
* @exampleResponse Call a Postgres function with filters
|
|
4697
|
+
* ```json
|
|
4698
|
+
* {
|
|
4699
|
+
* "data": {
|
|
4700
|
+
* "id": 1,
|
|
4701
|
+
* "name": "Rohan"
|
|
4702
|
+
* },
|
|
4703
|
+
* "status": 200,
|
|
4704
|
+
* "statusText": "OK"
|
|
4705
|
+
* }
|
|
4706
|
+
* ```
|
|
4707
|
+
*
|
|
4708
|
+
* @example Call a read-only Postgres function
|
|
4709
|
+
* ```ts
|
|
4710
|
+
* const { data, error } = await supabase.rpc('hello_world', undefined, { get: true })
|
|
4711
|
+
* ```
|
|
4712
|
+
*
|
|
4713
|
+
* @exampleSql Call a read-only Postgres function
|
|
4714
|
+
* ```sql
|
|
4715
|
+
* create function hello_world() returns text as $$
|
|
4716
|
+
* select 'Hello world';
|
|
4717
|
+
* $$ language sql;
|
|
4718
|
+
* ```
|
|
4719
|
+
*
|
|
4720
|
+
* @exampleResponse Call a read-only Postgres function
|
|
4721
|
+
* ```json
|
|
4722
|
+
* {
|
|
4723
|
+
* "data": "Hello world",
|
|
4724
|
+
* "status": 200,
|
|
4725
|
+
* "statusText": "OK"
|
|
4726
|
+
* }
|
|
4727
|
+
* ```
|
|
2401
4728
|
*/
|
|
2402
4729
|
rpc(fn, args = {}, { head = false, get = false, count } = {}) {
|
|
2403
4730
|
var _this$fetch;
|