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