@expo/entity-database-adapter-knex 0.61.0 → 0.63.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/build/src/AuthorizationResultBasedKnexEntityLoader.d.ts +0 -8
- package/build/src/AuthorizationResultBasedKnexEntityLoader.js +0 -11
- package/build/src/BasePostgresEntityDatabaseAdapter.d.ts +0 -11
- package/build/src/BasePostgresEntityDatabaseAdapter.js +0 -13
- package/build/src/EnforcingKnexEntityLoader.d.ts +0 -32
- package/build/src/EnforcingKnexEntityLoader.js +0 -35
- package/build/src/PostgresEntityDatabaseAdapter.d.ts +3 -2
- package/build/src/PostgresEntityDatabaseAdapter.js +2 -6
- package/build/src/SQLOperator.d.ts +379 -31
- package/build/src/internal/EntityKnexDataManager.d.ts +0 -10
- package/build/src/internal/EntityKnexDataManager.js +3 -16
- package/package.json +5 -5
- package/src/AuthorizationResultBasedKnexEntityLoader.ts +0 -21
- package/src/BasePostgresEntityDatabaseAdapter.ts +0 -36
- package/src/EnforcingKnexEntityLoader.ts +0 -44
- package/src/PostgresEntityDatabaseAdapter.ts +4 -15
- package/src/SQLOperator.ts +449 -101
- package/src/__integration-tests__/PostgresEntityIntegration-test.ts +69 -116
- package/src/__tests__/AuthorizationResultBasedKnexEntityLoader-test.ts +0 -75
- package/src/__tests__/BasePostgresEntityDatabaseAdapter-test.ts +4 -28
- package/src/__tests__/EnforcingKnexEntityLoader-test.ts +0 -52
- package/src/__tests__/fixtures/StubPostgresDatabaseAdapter.ts +3 -13
- package/src/internal/EntityKnexDataManager.ts +6 -37
- package/src/internal/__tests__/EntityKnexDataManager-test.ts +1 -57
package/src/SQLOperator.ts
CHANGED
|
@@ -630,27 +630,41 @@ function resolveInnerExpr<TFields extends Record<string, any>>(
|
|
|
630
630
|
// SupportedSQLValue for plain SQLFragment inputs.
|
|
631
631
|
|
|
632
632
|
// Extract TFields from a SQLFragment type
|
|
633
|
-
type
|
|
633
|
+
type ExtractFragmentFields<T> = T extends SQLFragment<infer F> ? F : never;
|
|
634
634
|
|
|
635
635
|
// Conditional value types for expression overloads.
|
|
636
636
|
// Uses SQLChainableFragment<any, ...> so that TExpr alone drives inference (single type param).
|
|
637
|
-
type
|
|
638
|
-
|
|
637
|
+
type FragmentValueNullable<TFragment> =
|
|
638
|
+
TFragment extends SQLChainableFragment<any, infer TValue>
|
|
639
639
|
? TValue | null | undefined
|
|
640
640
|
: SupportedSQLValue;
|
|
641
641
|
|
|
642
|
-
type
|
|
643
|
-
|
|
642
|
+
type FragmentValue<TFragment> =
|
|
643
|
+
TFragment extends SQLChainableFragment<any, infer TValue> ? TValue : SupportedSQLValue;
|
|
644
644
|
|
|
645
|
-
type
|
|
646
|
-
|
|
645
|
+
type FragmentValueArray<TFragment> =
|
|
646
|
+
TFragment extends SQLChainableFragment<any, infer TValue>
|
|
647
647
|
? readonly TValue[]
|
|
648
648
|
: readonly SupportedSQLValue[];
|
|
649
649
|
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
650
|
+
/**
|
|
651
|
+
* Generates an `IN (...)` condition from a fragment and array of values.
|
|
652
|
+
* Each array element becomes a separate bound parameter. Returns `FALSE` for empty arrays.
|
|
653
|
+
*
|
|
654
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to check
|
|
655
|
+
* @param values - The values to check membership against
|
|
656
|
+
*/
|
|
657
|
+
function inArrayHelper<TFragment extends SQLFragment<any>>(
|
|
658
|
+
fragment: TFragment,
|
|
659
|
+
values: FragmentValueArray<TFragment>,
|
|
660
|
+
): SQLFragment<ExtractFragmentFields<TFragment>>;
|
|
661
|
+
/**
|
|
662
|
+
* Generates an `IN (...)` condition from a field name and array of values.
|
|
663
|
+
* Each array element becomes a separate bound parameter. Returns `FALSE` for empty arrays.
|
|
664
|
+
*
|
|
665
|
+
* @param fieldName - The entity field name to check
|
|
666
|
+
* @param values - The values to check membership against
|
|
667
|
+
*/
|
|
654
668
|
function inArrayHelper<
|
|
655
669
|
TFields extends Record<string, any>,
|
|
656
670
|
N extends PickSupportedSQLValueKeys<TFields>,
|
|
@@ -662,10 +676,24 @@ function inArrayHelper<TFields extends Record<string, any>>(
|
|
|
662
676
|
return resolveInnerExpr(expressionOrFieldName).inArray(values);
|
|
663
677
|
}
|
|
664
678
|
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
679
|
+
/**
|
|
680
|
+
* Generates an `= ANY(?)` condition from a fragment and array of values.
|
|
681
|
+
* The array is bound as a single parameter for consistent query shape. Returns `FALSE` for empty arrays.
|
|
682
|
+
*
|
|
683
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to check
|
|
684
|
+
* @param values - The values to check membership against
|
|
685
|
+
*/
|
|
686
|
+
function anyArrayHelper<TFragment extends SQLFragment<any>>(
|
|
687
|
+
fragment: TFragment,
|
|
688
|
+
values: FragmentValueArray<TFragment>,
|
|
689
|
+
): SQLFragment<ExtractFragmentFields<TFragment>>;
|
|
690
|
+
/**
|
|
691
|
+
* Generates an `= ANY(?)` condition from a field name and array of values.
|
|
692
|
+
* The array is bound as a single parameter for consistent query shape. Returns `FALSE` for empty arrays.
|
|
693
|
+
*
|
|
694
|
+
* @param fieldName - The entity field name to check
|
|
695
|
+
* @param values - The values to check membership against
|
|
696
|
+
*/
|
|
669
697
|
function anyArrayHelper<
|
|
670
698
|
TFields extends Record<string, any>,
|
|
671
699
|
N extends PickSupportedSQLValueKeys<TFields>,
|
|
@@ -677,10 +705,24 @@ function anyArrayHelper<TFields extends Record<string, any>>(
|
|
|
677
705
|
return resolveInnerExpr(expressionOrFieldName).anyArray(values);
|
|
678
706
|
}
|
|
679
707
|
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
708
|
+
/**
|
|
709
|
+
* Generates a `NOT IN (...)` condition from a fragment and array of values.
|
|
710
|
+
* Each array element becomes a separate bound parameter. Returns `TRUE` for empty arrays.
|
|
711
|
+
*
|
|
712
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to check
|
|
713
|
+
* @param values - The values to check non-membership against
|
|
714
|
+
*/
|
|
715
|
+
function notInArrayHelper<TFragment extends SQLFragment<any>>(
|
|
716
|
+
fragment: TFragment,
|
|
717
|
+
values: FragmentValueArray<TFragment>,
|
|
718
|
+
): SQLFragment<ExtractFragmentFields<TFragment>>;
|
|
719
|
+
/**
|
|
720
|
+
* Generates a `NOT IN (...)` condition from a field name and array of values.
|
|
721
|
+
* Each array element becomes a separate bound parameter. Returns `TRUE` for empty arrays.
|
|
722
|
+
*
|
|
723
|
+
* @param fieldName - The entity field name to check
|
|
724
|
+
* @param values - The values to check non-membership against
|
|
725
|
+
*/
|
|
684
726
|
function notInArrayHelper<
|
|
685
727
|
TFields extends Record<string, any>,
|
|
686
728
|
N extends PickSupportedSQLValueKeys<TFields>,
|
|
@@ -692,11 +734,25 @@ function notInArrayHelper<TFields extends Record<string, any>>(
|
|
|
692
734
|
return resolveInnerExpr(expressionOrFieldName).notInArray(values);
|
|
693
735
|
}
|
|
694
736
|
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
737
|
+
/**
|
|
738
|
+
* Generates a `BETWEEN min AND max` condition (inclusive) from a fragment.
|
|
739
|
+
*
|
|
740
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to check
|
|
741
|
+
* @param min - The lower bound
|
|
742
|
+
* @param max - The upper bound
|
|
743
|
+
*/
|
|
744
|
+
function betweenHelper<TFragment extends SQLFragment<any>>(
|
|
745
|
+
fragment: TFragment,
|
|
746
|
+
min: FragmentValue<TFragment>,
|
|
747
|
+
max: FragmentValue<TFragment>,
|
|
748
|
+
): SQLFragment<ExtractFragmentFields<TFragment>>;
|
|
749
|
+
/**
|
|
750
|
+
* Generates a `BETWEEN min AND max` condition (inclusive) from a field name.
|
|
751
|
+
*
|
|
752
|
+
* @param fieldName - The entity field name to check
|
|
753
|
+
* @param min - The lower bound
|
|
754
|
+
* @param max - The upper bound
|
|
755
|
+
*/
|
|
700
756
|
function betweenHelper<
|
|
701
757
|
TFields extends Record<string, any>,
|
|
702
758
|
N extends PickSupportedSQLValueKeys<TFields>,
|
|
@@ -709,11 +765,25 @@ function betweenHelper<TFields extends Record<string, any>>(
|
|
|
709
765
|
return resolveInnerExpr(expressionOrFieldName).between(min, max);
|
|
710
766
|
}
|
|
711
767
|
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
768
|
+
/**
|
|
769
|
+
* Generates a `NOT BETWEEN min AND max` condition from a fragment.
|
|
770
|
+
*
|
|
771
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to check
|
|
772
|
+
* @param min - The lower bound
|
|
773
|
+
* @param max - The upper bound
|
|
774
|
+
*/
|
|
775
|
+
function notBetweenHelper<TFragment extends SQLFragment<any>>(
|
|
776
|
+
fragment: TFragment,
|
|
777
|
+
min: FragmentValue<TFragment>,
|
|
778
|
+
max: FragmentValue<TFragment>,
|
|
779
|
+
): SQLFragment<ExtractFragmentFields<TFragment>>;
|
|
780
|
+
/**
|
|
781
|
+
* Generates a `NOT BETWEEN min AND max` condition from a field name.
|
|
782
|
+
*
|
|
783
|
+
* @param fieldName - The entity field name to check
|
|
784
|
+
* @param min - The lower bound
|
|
785
|
+
* @param max - The upper bound
|
|
786
|
+
*/
|
|
717
787
|
function notBetweenHelper<
|
|
718
788
|
TFields extends Record<string, any>,
|
|
719
789
|
N extends PickSupportedSQLValueKeys<TFields>,
|
|
@@ -726,10 +796,22 @@ function notBetweenHelper<TFields extends Record<string, any>>(
|
|
|
726
796
|
return resolveInnerExpr(expressionOrFieldName).notBetween(min, max);
|
|
727
797
|
}
|
|
728
798
|
|
|
729
|
-
|
|
730
|
-
|
|
799
|
+
/**
|
|
800
|
+
* Generates a case-sensitive `LIKE` condition from a fragment.
|
|
801
|
+
*
|
|
802
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to match
|
|
803
|
+
* @param pattern - The LIKE pattern (use `%` for wildcards, `_` for single character)
|
|
804
|
+
*/
|
|
805
|
+
function likeHelper<TFragment extends SQLFragment<any>>(
|
|
806
|
+
fragment: TFragment,
|
|
731
807
|
pattern: string,
|
|
732
|
-
): SQLFragment<
|
|
808
|
+
): SQLFragment<ExtractFragmentFields<TFragment>>;
|
|
809
|
+
/**
|
|
810
|
+
* Generates a case-sensitive `LIKE` condition from a field name.
|
|
811
|
+
*
|
|
812
|
+
* @param fieldName - The entity field name to match
|
|
813
|
+
* @param pattern - The LIKE pattern (use `%` for wildcards, `_` for single character)
|
|
814
|
+
*/
|
|
733
815
|
function likeHelper<TFields extends Record<string, any>, N extends PickStringValueKeys<TFields>>(
|
|
734
816
|
fieldName: N,
|
|
735
817
|
pattern: string,
|
|
@@ -741,10 +823,22 @@ function likeHelper<TFields extends Record<string, any>>(
|
|
|
741
823
|
return resolveInnerExpr(expressionOrFieldName).like(pattern);
|
|
742
824
|
}
|
|
743
825
|
|
|
744
|
-
|
|
745
|
-
|
|
826
|
+
/**
|
|
827
|
+
* Generates a case-sensitive `NOT LIKE` condition from a fragment.
|
|
828
|
+
*
|
|
829
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to match
|
|
830
|
+
* @param pattern - The LIKE pattern (use `%` for wildcards, `_` for single character)
|
|
831
|
+
*/
|
|
832
|
+
function notLikeHelper<TFragment extends SQLFragment<any>>(
|
|
833
|
+
fragment: TFragment,
|
|
746
834
|
pattern: string,
|
|
747
|
-
): SQLFragment<
|
|
835
|
+
): SQLFragment<ExtractFragmentFields<TFragment>>;
|
|
836
|
+
/**
|
|
837
|
+
* Generates a case-sensitive `NOT LIKE` condition from a field name.
|
|
838
|
+
*
|
|
839
|
+
* @param fieldName - The entity field name to match
|
|
840
|
+
* @param pattern - The LIKE pattern (use `%` for wildcards, `_` for single character)
|
|
841
|
+
*/
|
|
748
842
|
function notLikeHelper<TFields extends Record<string, any>, N extends PickStringValueKeys<TFields>>(
|
|
749
843
|
fieldName: N,
|
|
750
844
|
pattern: string,
|
|
@@ -756,10 +850,22 @@ function notLikeHelper<TFields extends Record<string, any>>(
|
|
|
756
850
|
return resolveInnerExpr(expressionOrFieldName).notLike(pattern);
|
|
757
851
|
}
|
|
758
852
|
|
|
759
|
-
|
|
760
|
-
|
|
853
|
+
/**
|
|
854
|
+
* Generates a case-insensitive `ILIKE` condition from a fragment (PostgreSQL-specific).
|
|
855
|
+
*
|
|
856
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to match
|
|
857
|
+
* @param pattern - The LIKE pattern (use `%` for wildcards, `_` for single character)
|
|
858
|
+
*/
|
|
859
|
+
function ilikeHelper<TFragment extends SQLFragment<any>>(
|
|
860
|
+
fragment: TFragment,
|
|
761
861
|
pattern: string,
|
|
762
|
-
): SQLFragment<
|
|
862
|
+
): SQLFragment<ExtractFragmentFields<TFragment>>;
|
|
863
|
+
/**
|
|
864
|
+
* Generates a case-insensitive `ILIKE` condition from a field name (PostgreSQL-specific).
|
|
865
|
+
*
|
|
866
|
+
* @param fieldName - The entity field name to match
|
|
867
|
+
* @param pattern - The LIKE pattern (use `%` for wildcards, `_` for single character)
|
|
868
|
+
*/
|
|
763
869
|
function ilikeHelper<TFields extends Record<string, any>, N extends PickStringValueKeys<TFields>>(
|
|
764
870
|
fieldName: N,
|
|
765
871
|
pattern: string,
|
|
@@ -771,10 +877,22 @@ function ilikeHelper<TFields extends Record<string, any>>(
|
|
|
771
877
|
return resolveInnerExpr(expressionOrFieldName).ilike(pattern);
|
|
772
878
|
}
|
|
773
879
|
|
|
774
|
-
|
|
775
|
-
|
|
880
|
+
/**
|
|
881
|
+
* Generates a case-insensitive `NOT ILIKE` condition from a fragment (PostgreSQL-specific).
|
|
882
|
+
*
|
|
883
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to match
|
|
884
|
+
* @param pattern - The LIKE pattern (use `%` for wildcards, `_` for single character)
|
|
885
|
+
*/
|
|
886
|
+
function notIlikeHelper<TFragment extends SQLFragment<any>>(
|
|
887
|
+
fragment: TFragment,
|
|
776
888
|
pattern: string,
|
|
777
|
-
): SQLFragment<
|
|
889
|
+
): SQLFragment<ExtractFragmentFields<TFragment>>;
|
|
890
|
+
/**
|
|
891
|
+
* Generates a case-insensitive `NOT ILIKE` condition from a field name (PostgreSQL-specific).
|
|
892
|
+
*
|
|
893
|
+
* @param fieldName - The entity field name to match
|
|
894
|
+
* @param pattern - The LIKE pattern (use `%` for wildcards, `_` for single character)
|
|
895
|
+
*/
|
|
778
896
|
function notIlikeHelper<
|
|
779
897
|
TFields extends Record<string, any>,
|
|
780
898
|
N extends PickStringValueKeys<TFields>,
|
|
@@ -786,9 +904,19 @@ function notIlikeHelper<TFields extends Record<string, any>>(
|
|
|
786
904
|
return resolveInnerExpr(expressionOrFieldName).notIlike(pattern);
|
|
787
905
|
}
|
|
788
906
|
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
907
|
+
/**
|
|
908
|
+
* Generates an `IS NULL` condition from a fragment.
|
|
909
|
+
*
|
|
910
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to check
|
|
911
|
+
*/
|
|
912
|
+
function isNullHelper<TFragment extends SQLFragment<any>>(
|
|
913
|
+
fragment: TFragment,
|
|
914
|
+
): SQLFragment<ExtractFragmentFields<TFragment>>;
|
|
915
|
+
/**
|
|
916
|
+
* Generates an `IS NULL` condition from a field name.
|
|
917
|
+
*
|
|
918
|
+
* @param fieldName - The entity field name to check
|
|
919
|
+
*/
|
|
792
920
|
function isNullHelper<TFields extends Record<string, any>, N extends keyof TFields>(
|
|
793
921
|
fieldName: N,
|
|
794
922
|
): SQLFragment<TFields>;
|
|
@@ -798,9 +926,19 @@ function isNullHelper<TFields extends Record<string, any>>(
|
|
|
798
926
|
return resolveInnerExpr(expressionOrFieldName).isNull();
|
|
799
927
|
}
|
|
800
928
|
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
929
|
+
/**
|
|
930
|
+
* Generates an `IS NOT NULL` condition from a fragment.
|
|
931
|
+
*
|
|
932
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to check
|
|
933
|
+
*/
|
|
934
|
+
function isNotNullHelper<TFragment extends SQLFragment<any>>(
|
|
935
|
+
fragment: TFragment,
|
|
936
|
+
): SQLFragment<ExtractFragmentFields<TFragment>>;
|
|
937
|
+
/**
|
|
938
|
+
* Generates an `IS NOT NULL` condition from a field name.
|
|
939
|
+
*
|
|
940
|
+
* @param fieldName - The entity field name to check
|
|
941
|
+
*/
|
|
804
942
|
function isNotNullHelper<TFields extends Record<string, any>, N extends keyof TFields>(
|
|
805
943
|
fieldName: N,
|
|
806
944
|
): SQLFragment<TFields>;
|
|
@@ -810,10 +948,24 @@ function isNotNullHelper<TFields extends Record<string, any>>(
|
|
|
810
948
|
return resolveInnerExpr(expressionOrFieldName).isNotNull();
|
|
811
949
|
}
|
|
812
950
|
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
951
|
+
/**
|
|
952
|
+
* Generates an equality condition (`= value`) from a fragment.
|
|
953
|
+
* Automatically converts `null`/`undefined` to `IS NULL`.
|
|
954
|
+
*
|
|
955
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to compare
|
|
956
|
+
* @param value - The value to compare against
|
|
957
|
+
*/
|
|
958
|
+
function eqHelper<TFragment extends SQLFragment<any>>(
|
|
959
|
+
fragment: TFragment,
|
|
960
|
+
value: FragmentValueNullable<TFragment>,
|
|
961
|
+
): SQLFragment<ExtractFragmentFields<TFragment>>;
|
|
962
|
+
/**
|
|
963
|
+
* Generates an equality condition (`= value`) from a field name.
|
|
964
|
+
* Automatically converts `null`/`undefined` to `IS NULL`.
|
|
965
|
+
*
|
|
966
|
+
* @param fieldName - The entity field name to compare
|
|
967
|
+
* @param value - The value to compare against
|
|
968
|
+
*/
|
|
817
969
|
function eqHelper<
|
|
818
970
|
TFields extends Record<string, any>,
|
|
819
971
|
N extends PickSupportedSQLValueKeys<TFields>,
|
|
@@ -825,10 +977,24 @@ function eqHelper<TFields extends Record<string, any>>(
|
|
|
825
977
|
return resolveInnerExpr(expressionOrFieldName).eq(value);
|
|
826
978
|
}
|
|
827
979
|
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
980
|
+
/**
|
|
981
|
+
* Generates an inequality condition (`!= value`) from a fragment.
|
|
982
|
+
* Automatically converts `null`/`undefined` to `IS NOT NULL`.
|
|
983
|
+
*
|
|
984
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to compare
|
|
985
|
+
* @param value - The value to compare against
|
|
986
|
+
*/
|
|
987
|
+
function neqHelper<TFragment extends SQLFragment<any>>(
|
|
988
|
+
fragment: TFragment,
|
|
989
|
+
value: FragmentValueNullable<TFragment>,
|
|
990
|
+
): SQLFragment<ExtractFragmentFields<TFragment>>;
|
|
991
|
+
/**
|
|
992
|
+
* Generates an inequality condition (`!= value`) from a field name.
|
|
993
|
+
* Automatically converts `null`/`undefined` to `IS NOT NULL`.
|
|
994
|
+
*
|
|
995
|
+
* @param fieldName - The entity field name to compare
|
|
996
|
+
* @param value - The value to compare against
|
|
997
|
+
*/
|
|
832
998
|
function neqHelper<
|
|
833
999
|
TFields extends Record<string, any>,
|
|
834
1000
|
N extends PickSupportedSQLValueKeys<TFields>,
|
|
@@ -840,10 +1006,22 @@ function neqHelper<TFields extends Record<string, any>>(
|
|
|
840
1006
|
return resolveInnerExpr(expressionOrFieldName).neq(value);
|
|
841
1007
|
}
|
|
842
1008
|
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
1009
|
+
/**
|
|
1010
|
+
* Generates a greater-than condition (`> value`) from a fragment.
|
|
1011
|
+
*
|
|
1012
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to compare
|
|
1013
|
+
* @param value - The value to compare against
|
|
1014
|
+
*/
|
|
1015
|
+
function gtHelper<TFragment extends SQLFragment<any>>(
|
|
1016
|
+
fragment: TFragment,
|
|
1017
|
+
value: FragmentValue<TFragment>,
|
|
1018
|
+
): SQLFragment<ExtractFragmentFields<TFragment>>;
|
|
1019
|
+
/**
|
|
1020
|
+
* Generates a greater-than condition (`> value`) from a field name.
|
|
1021
|
+
*
|
|
1022
|
+
* @param fieldName - The entity field name to compare
|
|
1023
|
+
* @param value - The value to compare against
|
|
1024
|
+
*/
|
|
847
1025
|
function gtHelper<
|
|
848
1026
|
TFields extends Record<string, any>,
|
|
849
1027
|
N extends PickSupportedSQLValueKeys<TFields>,
|
|
@@ -855,10 +1033,22 @@ function gtHelper<TFields extends Record<string, any>>(
|
|
|
855
1033
|
return resolveInnerExpr(expressionOrFieldName).gt(value);
|
|
856
1034
|
}
|
|
857
1035
|
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
1036
|
+
/**
|
|
1037
|
+
* Generates a greater-than-or-equal-to condition (`>= value`) from a fragment.
|
|
1038
|
+
*
|
|
1039
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to compare
|
|
1040
|
+
* @param value - The value to compare against
|
|
1041
|
+
*/
|
|
1042
|
+
function gteHelper<TFragment extends SQLFragment<any>>(
|
|
1043
|
+
fragment: TFragment,
|
|
1044
|
+
value: FragmentValue<TFragment>,
|
|
1045
|
+
): SQLFragment<ExtractFragmentFields<TFragment>>;
|
|
1046
|
+
/**
|
|
1047
|
+
* Generates a greater-than-or-equal-to condition (`>= value`) from a field name.
|
|
1048
|
+
*
|
|
1049
|
+
* @param fieldName - The entity field name to compare
|
|
1050
|
+
* @param value - The value to compare against
|
|
1051
|
+
*/
|
|
862
1052
|
function gteHelper<
|
|
863
1053
|
TFields extends Record<string, any>,
|
|
864
1054
|
N extends PickSupportedSQLValueKeys<TFields>,
|
|
@@ -870,10 +1060,22 @@ function gteHelper<TFields extends Record<string, any>>(
|
|
|
870
1060
|
return resolveInnerExpr(expressionOrFieldName).gte(value);
|
|
871
1061
|
}
|
|
872
1062
|
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
1063
|
+
/**
|
|
1064
|
+
* Generates a less-than condition (`< value`) from a fragment.
|
|
1065
|
+
*
|
|
1066
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to compare
|
|
1067
|
+
* @param value - The value to compare against
|
|
1068
|
+
*/
|
|
1069
|
+
function ltHelper<TFragment extends SQLFragment<any>>(
|
|
1070
|
+
fragment: TFragment,
|
|
1071
|
+
value: FragmentValue<TFragment>,
|
|
1072
|
+
): SQLFragment<ExtractFragmentFields<TFragment>>;
|
|
1073
|
+
/**
|
|
1074
|
+
* Generates a less-than condition (`< value`) from a field name.
|
|
1075
|
+
*
|
|
1076
|
+
* @param fieldName - The entity field name to compare
|
|
1077
|
+
* @param value - The value to compare against
|
|
1078
|
+
*/
|
|
877
1079
|
function ltHelper<
|
|
878
1080
|
TFields extends Record<string, any>,
|
|
879
1081
|
N extends PickSupportedSQLValueKeys<TFields>,
|
|
@@ -885,10 +1087,22 @@ function ltHelper<TFields extends Record<string, any>>(
|
|
|
885
1087
|
return resolveInnerExpr(expressionOrFieldName).lt(value);
|
|
886
1088
|
}
|
|
887
1089
|
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
1090
|
+
/**
|
|
1091
|
+
* Generates a less-than-or-equal-to condition (`<= value`) from a fragment.
|
|
1092
|
+
*
|
|
1093
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to compare
|
|
1094
|
+
* @param value - The value to compare against
|
|
1095
|
+
*/
|
|
1096
|
+
function lteHelper<TFragment extends SQLFragment<any>>(
|
|
1097
|
+
fragment: TFragment,
|
|
1098
|
+
value: FragmentValue<TFragment>,
|
|
1099
|
+
): SQLFragment<ExtractFragmentFields<TFragment>>;
|
|
1100
|
+
/**
|
|
1101
|
+
* Generates a less-than-or-equal-to condition (`<= value`) from a field name.
|
|
1102
|
+
*
|
|
1103
|
+
* @param fieldName - The entity field name to compare
|
|
1104
|
+
* @param value - The value to compare against
|
|
1105
|
+
*/
|
|
892
1106
|
function lteHelper<
|
|
893
1107
|
TFields extends Record<string, any>,
|
|
894
1108
|
N extends PickSupportedSQLValueKeys<TFields>,
|
|
@@ -900,10 +1114,24 @@ function lteHelper<TFields extends Record<string, any>>(
|
|
|
900
1114
|
return resolveInnerExpr(expressionOrFieldName).lte(value);
|
|
901
1115
|
}
|
|
902
1116
|
|
|
903
|
-
|
|
904
|
-
|
|
1117
|
+
/**
|
|
1118
|
+
* Generates a JSON contains condition (`@>`) from a fragment.
|
|
1119
|
+
* Tests whether the JSON value contains the given value.
|
|
1120
|
+
*
|
|
1121
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to check
|
|
1122
|
+
* @param value - The JSON value to check containment of
|
|
1123
|
+
*/
|
|
1124
|
+
function jsonContainsHelper<TFragment extends SQLFragment<any>>(
|
|
1125
|
+
fragment: TFragment,
|
|
905
1126
|
value: JsonSerializable,
|
|
906
|
-
): SQLFragment<
|
|
1127
|
+
): SQLFragment<ExtractFragmentFields<TFragment>>;
|
|
1128
|
+
/**
|
|
1129
|
+
* Generates a JSON contains condition (`@>`) from a field name.
|
|
1130
|
+
* Tests whether the JSON value contains the given value.
|
|
1131
|
+
*
|
|
1132
|
+
* @param fieldName - The entity field name to check
|
|
1133
|
+
* @param value - The JSON value to check containment of
|
|
1134
|
+
*/
|
|
907
1135
|
function jsonContainsHelper<TFields extends Record<string, any>, N extends keyof TFields>(
|
|
908
1136
|
fieldName: N,
|
|
909
1137
|
value: JsonSerializable,
|
|
@@ -921,10 +1149,24 @@ function jsonContainsHelper<TFields extends Record<string, any>>(
|
|
|
921
1149
|
return sql`${inner} @> ${serialized}::jsonb`;
|
|
922
1150
|
}
|
|
923
1151
|
|
|
924
|
-
|
|
925
|
-
|
|
1152
|
+
/**
|
|
1153
|
+
* Generates a JSON contained-by condition (`<@`) from a fragment.
|
|
1154
|
+
* Tests whether the JSON value is contained by the given value.
|
|
1155
|
+
*
|
|
1156
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to check
|
|
1157
|
+
* @param value - The JSON value to check containment against
|
|
1158
|
+
*/
|
|
1159
|
+
function jsonContainedByHelper<TFragment extends SQLFragment<any>>(
|
|
1160
|
+
fragment: TFragment,
|
|
926
1161
|
value: JsonSerializable,
|
|
927
|
-
): SQLFragment<
|
|
1162
|
+
): SQLFragment<ExtractFragmentFields<TFragment>>;
|
|
1163
|
+
/**
|
|
1164
|
+
* Generates a JSON contained-by condition (`<@`) from a field name.
|
|
1165
|
+
* Tests whether the JSON value is contained by the given value.
|
|
1166
|
+
*
|
|
1167
|
+
* @param fieldName - The entity field name to check
|
|
1168
|
+
* @param value - The JSON value to check containment against
|
|
1169
|
+
*/
|
|
928
1170
|
function jsonContainedByHelper<TFields extends Record<string, any>, N extends keyof TFields>(
|
|
929
1171
|
fieldName: N,
|
|
930
1172
|
value: JsonSerializable,
|
|
@@ -942,10 +1184,24 @@ function jsonContainedByHelper<TFields extends Record<string, any>>(
|
|
|
942
1184
|
return sql`${inner} <@ ${serialized}::jsonb`;
|
|
943
1185
|
}
|
|
944
1186
|
|
|
945
|
-
|
|
946
|
-
|
|
1187
|
+
/**
|
|
1188
|
+
* JSON path extraction (`->`) from a fragment. Returns JSON.
|
|
1189
|
+
* Returns an SQLChainableFragment for fluent chaining.
|
|
1190
|
+
*
|
|
1191
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to extract from
|
|
1192
|
+
* @param path - The JSON key to extract
|
|
1193
|
+
*/
|
|
1194
|
+
function jsonPathHelper<TFragment extends SQLFragment<any>>(
|
|
1195
|
+
fragment: TFragment,
|
|
947
1196
|
path: string,
|
|
948
|
-
): SQLChainableFragment<
|
|
1197
|
+
): SQLChainableFragment<ExtractFragmentFields<TFragment>, SupportedSQLValue>;
|
|
1198
|
+
/**
|
|
1199
|
+
* JSON path extraction (`->`) from a field name. Returns JSON.
|
|
1200
|
+
* Returns an SQLChainableFragment for fluent chaining.
|
|
1201
|
+
*
|
|
1202
|
+
* @param fieldName - The entity field name to extract from
|
|
1203
|
+
* @param path - The JSON key to extract
|
|
1204
|
+
*/
|
|
949
1205
|
function jsonPathHelper<TFields extends Record<string, any>, N extends keyof TFields>(
|
|
950
1206
|
fieldName: N,
|
|
951
1207
|
path: string,
|
|
@@ -959,10 +1215,24 @@ function jsonPathHelper<TFields extends Record<string, any>>(
|
|
|
959
1215
|
return new SQLChainableFragment(wrapped.sql, wrapped.bindings);
|
|
960
1216
|
}
|
|
961
1217
|
|
|
962
|
-
|
|
963
|
-
|
|
1218
|
+
/**
|
|
1219
|
+
* JSON path text extraction (`->>`) from a fragment. Returns text.
|
|
1220
|
+
* Returns an SQLChainableFragment for fluent chaining.
|
|
1221
|
+
*
|
|
1222
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to extract from
|
|
1223
|
+
* @param path - The JSON key to extract as text
|
|
1224
|
+
*/
|
|
1225
|
+
function jsonPathTextHelper<TFragment extends SQLFragment<any>>(
|
|
1226
|
+
fragment: TFragment,
|
|
964
1227
|
path: string,
|
|
965
|
-
): SQLChainableFragment<
|
|
1228
|
+
): SQLChainableFragment<ExtractFragmentFields<TFragment>, SupportedSQLValue>;
|
|
1229
|
+
/**
|
|
1230
|
+
* JSON path text extraction (`->>`) from a field name. Returns text.
|
|
1231
|
+
* Returns an SQLChainableFragment for fluent chaining.
|
|
1232
|
+
*
|
|
1233
|
+
* @param fieldName - The entity field name to extract from
|
|
1234
|
+
* @param path - The JSON key to extract as text
|
|
1235
|
+
*/
|
|
966
1236
|
function jsonPathTextHelper<TFields extends Record<string, any>, N extends keyof TFields>(
|
|
967
1237
|
fieldName: N,
|
|
968
1238
|
path: string,
|
|
@@ -976,10 +1246,24 @@ function jsonPathTextHelper<TFields extends Record<string, any>>(
|
|
|
976
1246
|
return new SQLChainableFragment(wrapped.sql, wrapped.bindings);
|
|
977
1247
|
}
|
|
978
1248
|
|
|
979
|
-
|
|
980
|
-
|
|
1249
|
+
/**
|
|
1250
|
+
* JSON deep path extraction (`#>`) from a fragment. Returns JSON at the specified key path.
|
|
1251
|
+
* Returns an SQLChainableFragment for fluent chaining.
|
|
1252
|
+
*
|
|
1253
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to extract from
|
|
1254
|
+
* @param path - Array of keys forming the path (e.g., ['user', 'address', 'city'])
|
|
1255
|
+
*/
|
|
1256
|
+
function jsonDeepPathHelper<TFragment extends SQLFragment<any>>(
|
|
1257
|
+
fragment: TFragment,
|
|
981
1258
|
path: readonly string[],
|
|
982
|
-
): SQLChainableFragment<
|
|
1259
|
+
): SQLChainableFragment<ExtractFragmentFields<TFragment>, SupportedSQLValue>;
|
|
1260
|
+
/**
|
|
1261
|
+
* JSON deep path extraction (`#>`) from a field name. Returns JSON at the specified key path.
|
|
1262
|
+
* Returns an SQLChainableFragment for fluent chaining.
|
|
1263
|
+
*
|
|
1264
|
+
* @param fieldName - The entity field name to extract from
|
|
1265
|
+
* @param path - Array of keys forming the path (e.g., ['user', 'address', 'city'])
|
|
1266
|
+
*/
|
|
983
1267
|
function jsonDeepPathHelper<TFields extends Record<string, any>, N extends keyof TFields>(
|
|
984
1268
|
fieldName: N,
|
|
985
1269
|
path: readonly string[],
|
|
@@ -994,10 +1278,24 @@ function jsonDeepPathHelper<TFields extends Record<string, any>>(
|
|
|
994
1278
|
return new SQLChainableFragment(wrapped.sql, wrapped.bindings);
|
|
995
1279
|
}
|
|
996
1280
|
|
|
997
|
-
|
|
998
|
-
|
|
1281
|
+
/**
|
|
1282
|
+
* JSON deep path text extraction (`#>>`) from a fragment. Returns text at the specified key path.
|
|
1283
|
+
* Returns an SQLChainableFragment for fluent chaining.
|
|
1284
|
+
*
|
|
1285
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to extract from
|
|
1286
|
+
* @param path - Array of keys forming the path (e.g., ['user', 'address', 'city'])
|
|
1287
|
+
*/
|
|
1288
|
+
function jsonDeepPathTextHelper<TFragment extends SQLFragment<any>>(
|
|
1289
|
+
fragment: TFragment,
|
|
999
1290
|
path: readonly string[],
|
|
1000
|
-
): SQLChainableFragment<
|
|
1291
|
+
): SQLChainableFragment<ExtractFragmentFields<TFragment>, SupportedSQLValue>;
|
|
1292
|
+
/**
|
|
1293
|
+
* JSON deep path text extraction (`#>>`) from a field name. Returns text at the specified key path.
|
|
1294
|
+
* Returns an SQLChainableFragment for fluent chaining.
|
|
1295
|
+
*
|
|
1296
|
+
* @param fieldName - The entity field name to extract from
|
|
1297
|
+
* @param path - Array of keys forming the path (e.g., ['user', 'address', 'city'])
|
|
1298
|
+
*/
|
|
1001
1299
|
function jsonDeepPathTextHelper<TFields extends Record<string, any>, N extends keyof TFields>(
|
|
1002
1300
|
fieldName: N,
|
|
1003
1301
|
path: readonly string[],
|
|
@@ -1012,10 +1310,24 @@ function jsonDeepPathTextHelper<TFields extends Record<string, any>>(
|
|
|
1012
1310
|
return new SQLChainableFragment(wrapped.sql, wrapped.bindings);
|
|
1013
1311
|
}
|
|
1014
1312
|
|
|
1015
|
-
|
|
1016
|
-
|
|
1313
|
+
/**
|
|
1314
|
+
* SQL type cast (`::type`) from a fragment.
|
|
1315
|
+
* Returns an SQLChainableFragment for fluent chaining.
|
|
1316
|
+
*
|
|
1317
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to cast
|
|
1318
|
+
* @param typeName - The PostgreSQL type name (e.g., 'int', 'text', 'timestamptz')
|
|
1319
|
+
*/
|
|
1320
|
+
function castHelper<TFragment extends SQLFragment<any>>(
|
|
1321
|
+
fragment: TFragment,
|
|
1017
1322
|
typeName: PostgresCastType,
|
|
1018
|
-
): SQLChainableFragment<
|
|
1323
|
+
): SQLChainableFragment<ExtractFragmentFields<TFragment>, SupportedSQLValue>;
|
|
1324
|
+
/**
|
|
1325
|
+
* SQL type cast (`::type`) from a field name.
|
|
1326
|
+
* Returns an SQLChainableFragment for fluent chaining.
|
|
1327
|
+
*
|
|
1328
|
+
* @param fieldName - The entity field name to cast
|
|
1329
|
+
* @param typeName - The PostgreSQL type name (e.g., 'int', 'text', 'timestamptz')
|
|
1330
|
+
*/
|
|
1019
1331
|
function castHelper<TFields extends Record<string, any>, N extends keyof TFields>(
|
|
1020
1332
|
fieldName: N,
|
|
1021
1333
|
typeName: PostgresCastType,
|
|
@@ -1033,9 +1345,21 @@ function castHelper<TFields extends Record<string, any>>(
|
|
|
1033
1345
|
return new SQLChainableFragment(wrapped.sql, wrapped.bindings);
|
|
1034
1346
|
}
|
|
1035
1347
|
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1348
|
+
/**
|
|
1349
|
+
* Wraps a fragment in `LOWER()` to convert to lowercase.
|
|
1350
|
+
* Returns an SQLChainableFragment for fluent chaining.
|
|
1351
|
+
*
|
|
1352
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to convert
|
|
1353
|
+
*/
|
|
1354
|
+
function lowerHelper<TFragment extends SQLFragment<any>>(
|
|
1355
|
+
fragment: TFragment,
|
|
1356
|
+
): SQLChainableFragment<ExtractFragmentFields<TFragment>, SupportedSQLValue>;
|
|
1357
|
+
/**
|
|
1358
|
+
* Wraps a field in `LOWER()` to convert to lowercase.
|
|
1359
|
+
* Returns an SQLChainableFragment for fluent chaining.
|
|
1360
|
+
*
|
|
1361
|
+
* @param fieldName - The entity field name to convert
|
|
1362
|
+
*/
|
|
1039
1363
|
function lowerHelper<TFields extends Record<string, any>, N extends PickStringValueKeys<TFields>>(
|
|
1040
1364
|
fieldName: N,
|
|
1041
1365
|
): SQLChainableFragment<TFields, TFields[N]>;
|
|
@@ -1047,9 +1371,21 @@ function lowerHelper<TFields extends Record<string, any>>(
|
|
|
1047
1371
|
return new SQLChainableFragment(wrapped.sql, wrapped.bindings);
|
|
1048
1372
|
}
|
|
1049
1373
|
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1374
|
+
/**
|
|
1375
|
+
* Wraps a fragment in `UPPER()` to convert to uppercase.
|
|
1376
|
+
* Returns an SQLChainableFragment for fluent chaining.
|
|
1377
|
+
*
|
|
1378
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to convert
|
|
1379
|
+
*/
|
|
1380
|
+
function upperHelper<TFragment extends SQLFragment<any>>(
|
|
1381
|
+
fragment: TFragment,
|
|
1382
|
+
): SQLChainableFragment<ExtractFragmentFields<TFragment>, SupportedSQLValue>;
|
|
1383
|
+
/**
|
|
1384
|
+
* Wraps a field in `UPPER()` to convert to uppercase.
|
|
1385
|
+
* Returns an SQLChainableFragment for fluent chaining.
|
|
1386
|
+
*
|
|
1387
|
+
* @param fieldName - The entity field name to convert
|
|
1388
|
+
*/
|
|
1053
1389
|
function upperHelper<TFields extends Record<string, any>, N extends PickStringValueKeys<TFields>>(
|
|
1054
1390
|
fieldName: N,
|
|
1055
1391
|
): SQLChainableFragment<TFields, TFields[N]>;
|
|
@@ -1061,9 +1397,21 @@ function upperHelper<TFields extends Record<string, any>>(
|
|
|
1061
1397
|
return new SQLChainableFragment(wrapped.sql, wrapped.bindings);
|
|
1062
1398
|
}
|
|
1063
1399
|
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1400
|
+
/**
|
|
1401
|
+
* Wraps a fragment in `TRIM()` to remove leading and trailing whitespace.
|
|
1402
|
+
* Returns an SQLChainableFragment for fluent chaining.
|
|
1403
|
+
*
|
|
1404
|
+
* @param fragment - A SQLFragment or SQLChainableFragment to trim
|
|
1405
|
+
*/
|
|
1406
|
+
function trimHelper<TFragment extends SQLFragment<any>>(
|
|
1407
|
+
fragment: TFragment,
|
|
1408
|
+
): SQLChainableFragment<ExtractFragmentFields<TFragment>, SupportedSQLValue>;
|
|
1409
|
+
/**
|
|
1410
|
+
* Wraps a field in `TRIM()` to remove leading and trailing whitespace.
|
|
1411
|
+
* Returns an SQLChainableFragment for fluent chaining.
|
|
1412
|
+
*
|
|
1413
|
+
* @param fieldName - The entity field name to trim
|
|
1414
|
+
*/
|
|
1067
1415
|
function trimHelper<TFields extends Record<string, any>, N extends PickStringValueKeys<TFields>>(
|
|
1068
1416
|
fieldName: N,
|
|
1069
1417
|
): SQLChainableFragment<TFields, TFields[N]>;
|