supabase-typed-query 0.13.0 → 1.0.0
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.js +185 -312
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +186 -310
- package/dist/index.mjs.map +1 -1
- package/dist/src/entity/core.d.ts.map +1 -1
- package/dist/src/entity/types.d.ts +5 -5
- package/dist/src/entity/types.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/query/Query.d.ts +13 -13
- package/dist/src/query/Query.d.ts.map +1 -1
- package/dist/src/query/QueryBuilder.d.ts +3 -0
- package/dist/src/query/QueryBuilder.d.ts.map +1 -1
- package/dist/src/query/index.d.ts +19 -19
- package/dist/src/query/index.d.ts.map +1 -1
- package/dist/src/query/rpc.d.ts +7 -5
- package/dist/src/query/rpc.d.ts.map +1 -1
- package/package.json +31 -33
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Option, IO, List } from "functype";
|
|
2
|
+
import { IO as IO2, List as List2, Option as Option2 } from "functype";
|
|
3
3
|
class SupabaseError extends Error {
|
|
4
4
|
code;
|
|
5
5
|
details;
|
|
@@ -46,9 +46,6 @@ const log = {
|
|
|
46
46
|
info: (msg) => process.env.NODE_ENV !== "test" && console.info(`[supabase-typed-query] ${msg}`)
|
|
47
47
|
};
|
|
48
48
|
const TABLES_WITHOUT_DELETED = /* @__PURE__ */ new Set([]);
|
|
49
|
-
const wrapAsync$2 = (fn) => {
|
|
50
|
-
return fn();
|
|
51
|
-
};
|
|
52
49
|
const QueryBuilder = (client, config) => {
|
|
53
50
|
const buildSupabaseQuery = () => {
|
|
54
51
|
const { table, conditions, order, limit, offset, schema } = config;
|
|
@@ -443,81 +440,52 @@ const QueryBuilder = (client, config) => {
|
|
|
443
440
|
* Execute query expecting exactly one result
|
|
444
441
|
*/
|
|
445
442
|
one: () => {
|
|
446
|
-
return
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
const result = data;
|
|
455
|
-
const filteredResult = config.filterFn ? config.filterFn(result) : true;
|
|
456
|
-
if (!filteredResult) {
|
|
457
|
-
return Ok(Option.none());
|
|
458
|
-
}
|
|
459
|
-
return Ok(Option(result));
|
|
460
|
-
} catch (error) {
|
|
461
|
-
log.error(`Error executing single query on ${config.table}: ${toError(error).toString()}`);
|
|
462
|
-
return Err(toError(error));
|
|
463
|
-
}
|
|
464
|
-
});
|
|
443
|
+
return IO.tryAsync(async () => {
|
|
444
|
+
const query2 = buildSupabaseQuery();
|
|
445
|
+
const { data, error } = await query2.single();
|
|
446
|
+
if (error) throw toError(error);
|
|
447
|
+
const result = data;
|
|
448
|
+
const passes = config.filterFn ? config.filterFn(result) : true;
|
|
449
|
+
return passes ? Option(result) : Option.none();
|
|
450
|
+
}, toError).tapError((err) => log.error(`Error getting ${config.table} item: ${err}`));
|
|
465
451
|
},
|
|
466
452
|
/**
|
|
467
453
|
* Execute query expecting zero or more results
|
|
468
454
|
*/
|
|
469
455
|
many: () => {
|
|
470
|
-
return
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
const rawResults = data;
|
|
479
|
-
const results = config.filterFn ? rawResults.filter(config.filterFn) : rawResults;
|
|
480
|
-
return Ok(List(results));
|
|
481
|
-
} catch (error) {
|
|
482
|
-
log.error(`Error executing multi query on ${config.table}: ${toError(error).toString()}`);
|
|
483
|
-
return Err(toError(error));
|
|
484
|
-
}
|
|
485
|
-
});
|
|
456
|
+
return IO.tryAsync(async () => {
|
|
457
|
+
const query2 = buildSupabaseQuery();
|
|
458
|
+
const { data, error } = await query2;
|
|
459
|
+
if (error) throw toError(error);
|
|
460
|
+
const rawResults = data;
|
|
461
|
+
const results = config.filterFn ? rawResults.filter(config.filterFn) : rawResults;
|
|
462
|
+
return List(results);
|
|
463
|
+
}, toError).tapError((err) => log.error(`Error getting ${config.table} items: ${err}`));
|
|
486
464
|
},
|
|
487
465
|
/**
|
|
488
466
|
* Execute query expecting first result from potentially multiple
|
|
489
467
|
*/
|
|
490
468
|
first: () => {
|
|
491
|
-
return
|
|
492
|
-
const manyResult = await QueryBuilder(client, config).many();
|
|
493
|
-
const list = manyResult.orThrow();
|
|
494
|
-
if (list.isEmpty) {
|
|
495
|
-
return Ok(Option.none());
|
|
496
|
-
}
|
|
497
|
-
return Ok(Option(list.head));
|
|
498
|
-
});
|
|
469
|
+
return QueryBuilder(client, config).many().map((list) => list.isEmpty ? Option.none() : Option(list.head));
|
|
499
470
|
},
|
|
500
471
|
/**
|
|
501
472
|
* Execute query expecting exactly one result, throw if error or not found
|
|
502
473
|
*/
|
|
503
474
|
oneOrThrow: async () => {
|
|
504
|
-
const
|
|
505
|
-
const option = result.orThrow();
|
|
475
|
+
const option = await QueryBuilder(client, config).one().runOrThrow();
|
|
506
476
|
return option.orThrow(new Error(`No record found in ${config.table}`));
|
|
507
477
|
},
|
|
508
478
|
/**
|
|
509
479
|
* Execute query expecting zero or more results, throw if error
|
|
510
480
|
*/
|
|
511
481
|
manyOrThrow: async () => {
|
|
512
|
-
|
|
513
|
-
return result.orThrow();
|
|
482
|
+
return QueryBuilder(client, config).many().runOrThrow();
|
|
514
483
|
},
|
|
515
484
|
/**
|
|
516
485
|
* Execute query expecting first result, throw if error or empty
|
|
517
486
|
*/
|
|
518
487
|
firstOrThrow: async () => {
|
|
519
|
-
const
|
|
520
|
-
const option = result.orThrow();
|
|
488
|
+
const option = await QueryBuilder(client, config).first().runOrThrow();
|
|
521
489
|
return option.orThrow(new Error(`No records found in ${config.table}`));
|
|
522
490
|
}
|
|
523
491
|
};
|
|
@@ -532,53 +500,42 @@ const createMappedQuery = (sourceQuery, mapFn) => {
|
|
|
532
500
|
return createMappedQuery(filteredQuery, mapFn);
|
|
533
501
|
},
|
|
534
502
|
one: () => {
|
|
535
|
-
return
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
);
|
|
542
|
-
});
|
|
503
|
+
return sourceQuery.one().map(
|
|
504
|
+
(maybeItem) => maybeItem.fold(
|
|
505
|
+
() => Option.none(),
|
|
506
|
+
(item) => Option(mapFn(item))
|
|
507
|
+
)
|
|
508
|
+
);
|
|
543
509
|
},
|
|
544
510
|
many: () => {
|
|
545
|
-
return
|
|
546
|
-
const itemsResult = await sourceQuery.many();
|
|
547
|
-
const items = itemsResult.orThrow();
|
|
548
|
-
return Ok(items.map(mapFn));
|
|
549
|
-
});
|
|
511
|
+
return sourceQuery.many().map((items) => items.map(mapFn));
|
|
550
512
|
},
|
|
551
513
|
first: () => {
|
|
552
|
-
return
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
);
|
|
559
|
-
});
|
|
514
|
+
return sourceQuery.first().map(
|
|
515
|
+
(maybeItem) => maybeItem.fold(
|
|
516
|
+
() => Option.none(),
|
|
517
|
+
(item) => Option(mapFn(item))
|
|
518
|
+
)
|
|
519
|
+
);
|
|
560
520
|
},
|
|
561
521
|
/**
|
|
562
522
|
* Execute mapped query expecting exactly one result, throw if error or not found
|
|
563
523
|
*/
|
|
564
524
|
oneOrThrow: async () => {
|
|
565
|
-
const
|
|
566
|
-
const option = result.orThrow();
|
|
525
|
+
const option = await createMappedQuery(sourceQuery, mapFn).one().runOrThrow();
|
|
567
526
|
return option.orThrow(new Error(`No record found`));
|
|
568
527
|
},
|
|
569
528
|
/**
|
|
570
529
|
* Execute mapped query expecting zero or more results, throw if error
|
|
571
530
|
*/
|
|
572
531
|
manyOrThrow: async () => {
|
|
573
|
-
|
|
574
|
-
return result.orThrow();
|
|
532
|
+
return createMappedQuery(sourceQuery, mapFn).many().runOrThrow();
|
|
575
533
|
},
|
|
576
534
|
/**
|
|
577
535
|
* Execute mapped query expecting first result, throw if error or empty
|
|
578
536
|
*/
|
|
579
537
|
firstOrThrow: async () => {
|
|
580
|
-
const
|
|
581
|
-
const option = result.orThrow();
|
|
538
|
+
const option = await createMappedQuery(sourceQuery, mapFn).first().runOrThrow();
|
|
582
539
|
return option.orThrow(new Error(`No records found`));
|
|
583
540
|
}
|
|
584
541
|
};
|
|
@@ -600,38 +557,28 @@ const isQuery = (obj) => {
|
|
|
600
557
|
const isMappedQuery = (obj) => {
|
|
601
558
|
return typeof obj === "object" && obj !== null && "one" in obj && "many" in obj && "first" in obj && "map" in obj && "filter" in obj;
|
|
602
559
|
};
|
|
603
|
-
const wrapAsync$1 = (fn) => {
|
|
604
|
-
return fn();
|
|
605
|
-
};
|
|
606
560
|
const rpc = (client, functionName, args, options) => {
|
|
607
561
|
const executeRpc = () => {
|
|
608
562
|
return client.rpc(functionName, args ?? {}, {
|
|
609
563
|
count: options?.count
|
|
610
564
|
});
|
|
611
565
|
};
|
|
612
|
-
const one = () =>
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
if (Array.isArray(data)) {
|
|
622
|
-
if (data.length === 0) {
|
|
623
|
-
return Ok(Option.none());
|
|
624
|
-
}
|
|
625
|
-
return Ok(Option(data[0]));
|
|
566
|
+
const one = () => IO.tryAsync(async () => {
|
|
567
|
+
const { data, error } = await executeRpc();
|
|
568
|
+
if (error) throw toError(error);
|
|
569
|
+
if (data === null || data === void 0) {
|
|
570
|
+
return Option.none();
|
|
571
|
+
}
|
|
572
|
+
if (Array.isArray(data)) {
|
|
573
|
+
if (data.length === 0) {
|
|
574
|
+
return Option.none();
|
|
626
575
|
}
|
|
627
|
-
return
|
|
628
|
-
} catch (error) {
|
|
629
|
-
return Err(toError(error));
|
|
576
|
+
return Option(data[0]);
|
|
630
577
|
}
|
|
631
|
-
|
|
578
|
+
return Option(data);
|
|
579
|
+
}, toError);
|
|
632
580
|
const oneOrThrow = async () => {
|
|
633
|
-
const
|
|
634
|
-
const option = result.orThrow();
|
|
581
|
+
const option = await one().runOrThrow();
|
|
635
582
|
return option.fold(
|
|
636
583
|
() => {
|
|
637
584
|
throw new Error("RPC call returned no result");
|
|
@@ -639,26 +586,19 @@ const rpc = (client, functionName, args, options) => {
|
|
|
639
586
|
(value) => value
|
|
640
587
|
);
|
|
641
588
|
};
|
|
642
|
-
const many = () =>
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
}
|
|
648
|
-
if (data === null || data === void 0) {
|
|
649
|
-
return Ok(List([]));
|
|
650
|
-
}
|
|
651
|
-
if (Array.isArray(data)) {
|
|
652
|
-
return Ok(List(data));
|
|
653
|
-
}
|
|
654
|
-
return Ok(List([data]));
|
|
655
|
-
} catch (error) {
|
|
656
|
-
return Err(toError(error));
|
|
589
|
+
const many = () => IO.tryAsync(async () => {
|
|
590
|
+
const { data, error } = await executeRpc();
|
|
591
|
+
if (error) throw toError(error);
|
|
592
|
+
if (data === null || data === void 0) {
|
|
593
|
+
return List([]);
|
|
657
594
|
}
|
|
658
|
-
|
|
595
|
+
if (Array.isArray(data)) {
|
|
596
|
+
return List(data);
|
|
597
|
+
}
|
|
598
|
+
return List([data]);
|
|
599
|
+
}, toError);
|
|
659
600
|
const manyOrThrow = async () => {
|
|
660
|
-
|
|
661
|
-
return result.orThrow();
|
|
601
|
+
return many().runOrThrow();
|
|
662
602
|
};
|
|
663
603
|
return {
|
|
664
604
|
one,
|
|
@@ -667,208 +607,145 @@ const rpc = (client, functionName, args, options) => {
|
|
|
667
607
|
manyOrThrow
|
|
668
608
|
};
|
|
669
609
|
};
|
|
670
|
-
const
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
const
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
const { data, error } = await queryWithIs.single();
|
|
681
|
-
if (error) {
|
|
682
|
-
return Err(toError(error));
|
|
683
|
-
}
|
|
684
|
-
return Ok(data);
|
|
685
|
-
} catch (error) {
|
|
686
|
-
return Err(toError(error));
|
|
687
|
-
}
|
|
688
|
-
});
|
|
610
|
+
const getEntity = (client, table, where, is, schema) => IO.tryAsync(async () => {
|
|
611
|
+
const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
|
|
612
|
+
const baseQuery = tableQuery.select("*").match(where);
|
|
613
|
+
const queryWithIs = is ? List(Object.entries(is)).foldLeft(baseQuery)(
|
|
614
|
+
(query2, [column, value]) => query2.is(column, value)
|
|
615
|
+
) : baseQuery;
|
|
616
|
+
const { data, error } = await queryWithIs.single();
|
|
617
|
+
if (error) throw toError(error);
|
|
618
|
+
return data;
|
|
619
|
+
}, toError);
|
|
689
620
|
const getEntities = (client, table, where = {}, is, wherein, order = [
|
|
690
621
|
"id",
|
|
691
622
|
{ ascending: true }
|
|
692
|
-
], schema) =>
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
});
|
|
712
|
-
const
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
)
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
)
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
)
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
)
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
) : queryWithIn;
|
|
792
|
-
const { data, error } = await queryWithIs.select();
|
|
793
|
-
if (error) {
|
|
794
|
-
return Err(toError(error));
|
|
795
|
-
}
|
|
796
|
-
return Ok(List(data));
|
|
797
|
-
} catch (error) {
|
|
798
|
-
return Err(toError(error));
|
|
799
|
-
}
|
|
800
|
-
});
|
|
801
|
-
const softDeleteEntity = (client, table, where, is, wherein, schema) => wrapAsync(async () => {
|
|
802
|
-
try {
|
|
803
|
-
const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
|
|
804
|
-
const baseQuery = tableQuery.update({ deleted: (/* @__PURE__ */ new Date()).toISOString() }).match(where);
|
|
805
|
-
const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
|
|
806
|
-
(query2, [column, values]) => query2.in(column, values)
|
|
807
|
-
) : baseQuery;
|
|
808
|
-
const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
|
|
809
|
-
(query2, [column, value]) => query2.is(column, value)
|
|
810
|
-
) : queryWithIn;
|
|
811
|
-
const { data, error } = await queryWithIs.select().single();
|
|
812
|
-
if (error) {
|
|
813
|
-
return Err(toError(error));
|
|
814
|
-
}
|
|
815
|
-
return Ok(data);
|
|
816
|
-
} catch (error) {
|
|
817
|
-
return Err(toError(error));
|
|
818
|
-
}
|
|
819
|
-
});
|
|
820
|
-
const softDeleteEntities = (client, table, where, is, wherein, schema) => wrapAsync(async () => {
|
|
821
|
-
try {
|
|
822
|
-
const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
|
|
823
|
-
const baseQuery = tableQuery.update({ deleted: (/* @__PURE__ */ new Date()).toISOString() }).match(where);
|
|
824
|
-
const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
|
|
825
|
-
(query2, [column, values]) => query2.in(column, values)
|
|
826
|
-
) : baseQuery;
|
|
827
|
-
const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
|
|
828
|
-
(query2, [column, value]) => query2.is(column, value)
|
|
829
|
-
) : queryWithIn;
|
|
830
|
-
const { data, error } = await queryWithIs.select();
|
|
831
|
-
if (error) {
|
|
832
|
-
return Err(toError(error));
|
|
833
|
-
}
|
|
834
|
-
return Ok(List(data));
|
|
835
|
-
} catch (error) {
|
|
836
|
-
return Err(toError(error));
|
|
837
|
-
}
|
|
838
|
-
});
|
|
623
|
+
], schema) => IO.tryAsync(async () => {
|
|
624
|
+
const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
|
|
625
|
+
const baseQuery = tableQuery.select("*").match(where);
|
|
626
|
+
const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
|
|
627
|
+
(query2, [column, values]) => query2.in(column, values)
|
|
628
|
+
) : baseQuery;
|
|
629
|
+
const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
|
|
630
|
+
(query2, [column, value]) => query2.is(column, value)
|
|
631
|
+
) : queryWithIn;
|
|
632
|
+
const queryOrderBy = queryWithIs.order(order[0], order[1]);
|
|
633
|
+
const { data, error } = await queryOrderBy;
|
|
634
|
+
if (error) throw toError(error);
|
|
635
|
+
return List(data);
|
|
636
|
+
}, toError);
|
|
637
|
+
const addEntities = (client, table, entities, schema) => IO.tryAsync(async () => {
|
|
638
|
+
const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
|
|
639
|
+
const { data, error } = await tableQuery.insert(entities).select();
|
|
640
|
+
if (error) throw toError(error);
|
|
641
|
+
return List(data);
|
|
642
|
+
}, toError);
|
|
643
|
+
const updateEntity = (client, table, entities, where, is, wherein, schema) => IO.tryAsync(async () => {
|
|
644
|
+
const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
|
|
645
|
+
const baseQuery = tableQuery.update(entities).match(where);
|
|
646
|
+
const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
|
|
647
|
+
(query2, [column, values]) => query2.in(column, values)
|
|
648
|
+
) : baseQuery;
|
|
649
|
+
const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
|
|
650
|
+
(query2, [column, value]) => query2.is(column, value)
|
|
651
|
+
) : queryWithIn;
|
|
652
|
+
const { data, error } = await queryWithIs.select().single();
|
|
653
|
+
if (error) throw toError(error);
|
|
654
|
+
return data;
|
|
655
|
+
}, toError);
|
|
656
|
+
const upsertEntities = (client, table, entities, identity = "id", where, is, wherein, schema) => IO.tryAsync(async () => {
|
|
657
|
+
const onConflict = Array.isArray(identity) ? identity.join(",") : identity;
|
|
658
|
+
const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
|
|
659
|
+
const baseQuery = tableQuery.upsert(entities, { onConflict }).match(where ?? {});
|
|
660
|
+
const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
|
|
661
|
+
(query2, [column, values]) => query2.in(column, values)
|
|
662
|
+
) : baseQuery;
|
|
663
|
+
const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
|
|
664
|
+
(query2, [column, value]) => query2.is(column, value)
|
|
665
|
+
) : queryWithIn;
|
|
666
|
+
const { data, error } = await queryWithIs.select();
|
|
667
|
+
if (error) throw toError(error);
|
|
668
|
+
return List(data);
|
|
669
|
+
}, toError);
|
|
670
|
+
const deleteEntity = (client, table, where, is, wherein, schema) => IO.tryAsync(async () => {
|
|
671
|
+
const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
|
|
672
|
+
const baseQuery = tableQuery.delete().match(where);
|
|
673
|
+
const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
|
|
674
|
+
(query2, [column, values]) => query2.in(column, values)
|
|
675
|
+
) : baseQuery;
|
|
676
|
+
const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
|
|
677
|
+
(query2, [column, value]) => query2.is(column, value)
|
|
678
|
+
) : queryWithIn;
|
|
679
|
+
const { data, error } = await queryWithIs.select().single();
|
|
680
|
+
if (error) throw toError(error);
|
|
681
|
+
return data;
|
|
682
|
+
}, toError);
|
|
683
|
+
const deleteEntities = (client, table, where, is, wherein, schema) => IO.tryAsync(async () => {
|
|
684
|
+
const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
|
|
685
|
+
const baseQuery = tableQuery.delete().match(where);
|
|
686
|
+
const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
|
|
687
|
+
(query2, [column, values]) => query2.in(column, values)
|
|
688
|
+
) : baseQuery;
|
|
689
|
+
const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
|
|
690
|
+
(query2, [column, value]) => query2.is(column, value)
|
|
691
|
+
) : queryWithIn;
|
|
692
|
+
const { data, error } = await queryWithIs.select();
|
|
693
|
+
if (error) throw toError(error);
|
|
694
|
+
return List(data);
|
|
695
|
+
}, toError);
|
|
696
|
+
const softDeleteEntity = (client, table, where, is, wherein, schema) => IO.tryAsync(async () => {
|
|
697
|
+
const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
|
|
698
|
+
const baseQuery = tableQuery.update({ deleted: (/* @__PURE__ */ new Date()).toISOString() }).match(where);
|
|
699
|
+
const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
|
|
700
|
+
(query2, [column, values]) => query2.in(column, values)
|
|
701
|
+
) : baseQuery;
|
|
702
|
+
const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
|
|
703
|
+
(query2, [column, value]) => query2.is(column, value)
|
|
704
|
+
) : queryWithIn;
|
|
705
|
+
const { data, error } = await queryWithIs.select().single();
|
|
706
|
+
if (error) throw toError(error);
|
|
707
|
+
return data;
|
|
708
|
+
}, toError);
|
|
709
|
+
const softDeleteEntities = (client, table, where, is, wherein, schema) => IO.tryAsync(async () => {
|
|
710
|
+
const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
|
|
711
|
+
const baseQuery = tableQuery.update({ deleted: (/* @__PURE__ */ new Date()).toISOString() }).match(where);
|
|
712
|
+
const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
|
|
713
|
+
(query2, [column, values]) => query2.in(column, values)
|
|
714
|
+
) : baseQuery;
|
|
715
|
+
const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
|
|
716
|
+
(query2, [column, value]) => query2.is(column, value)
|
|
717
|
+
) : queryWithIn;
|
|
718
|
+
const { data, error } = await queryWithIs.select();
|
|
719
|
+
if (error) throw toError(error);
|
|
720
|
+
return List(data);
|
|
721
|
+
}, toError);
|
|
839
722
|
const query = (client, table, where = {}, is, wherein, order, schema) => {
|
|
840
723
|
return createQuery(client, table, where, is, wherein, order, void 0, schema);
|
|
841
724
|
};
|
|
842
|
-
function MultiMutationQuery(
|
|
843
|
-
|
|
844
|
-
many: () =>
|
|
725
|
+
function MultiMutationQuery(task) {
|
|
726
|
+
return {
|
|
727
|
+
many: () => task,
|
|
845
728
|
manyOrThrow: async () => {
|
|
846
|
-
|
|
847
|
-
return taskResult.orThrow();
|
|
729
|
+
return task.runOrThrow();
|
|
848
730
|
},
|
|
849
|
-
execute: () =>
|
|
731
|
+
execute: () => task,
|
|
850
732
|
executeOrThrow: async () => {
|
|
851
|
-
|
|
852
|
-
return taskResult.orThrow();
|
|
733
|
+
return task.runOrThrow();
|
|
853
734
|
}
|
|
854
|
-
}
|
|
855
|
-
return result;
|
|
735
|
+
};
|
|
856
736
|
}
|
|
857
|
-
function SingleMutationQuery(
|
|
858
|
-
|
|
859
|
-
one: () =>
|
|
737
|
+
function SingleMutationQuery(task) {
|
|
738
|
+
return {
|
|
739
|
+
one: () => task.map((value) => Option(value)),
|
|
860
740
|
oneOrThrow: async () => {
|
|
861
|
-
|
|
862
|
-
return taskResult.orThrow();
|
|
741
|
+
return task.runOrThrow();
|
|
863
742
|
},
|
|
864
|
-
execute: () =>
|
|
743
|
+
execute: () => task.map((value) => Option(value)),
|
|
865
744
|
executeOrThrow: async () => {
|
|
866
|
-
const
|
|
867
|
-
const value = taskResult.orThrow();
|
|
745
|
+
const value = await task.runOrThrow();
|
|
868
746
|
return Option(value);
|
|
869
747
|
}
|
|
870
|
-
}
|
|
871
|
-
return result;
|
|
748
|
+
};
|
|
872
749
|
}
|
|
873
750
|
function getSoftDeleteMode(softDelete) {
|
|
874
751
|
return softDelete ? "exclude" : "include";
|
|
@@ -1309,10 +1186,9 @@ const PartitionedEntity = (client, name, config) => {
|
|
|
1309
1186
|
};
|
|
1310
1187
|
export {
|
|
1311
1188
|
Entity,
|
|
1312
|
-
|
|
1189
|
+
IO2 as IO,
|
|
1313
1190
|
List2 as List,
|
|
1314
1191
|
MultiMutationQuery,
|
|
1315
|
-
Ok2 as Ok,
|
|
1316
1192
|
Option2 as Option,
|
|
1317
1193
|
PartitionedEntity,
|
|
1318
1194
|
SingleMutationQuery,
|