hysteria-orm 10.4.5 → 10.4.7

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/lib/index.d.cts CHANGED
@@ -2323,11 +2323,12 @@ declare class JoinNode extends QueryNode {
2323
2323
  folder: string;
2324
2324
  file: string;
2325
2325
  type: "inner" | "left" | "right" | "full" | "cross" | "natural";
2326
+ additionalConditions?: (WhereNode | WhereGroupNode | WhereSubqueryNode)[];
2326
2327
  constructor(table: string, left: string, right: string, type: "inner" | "left" | "right" | "full" | "cross" | "natural" | undefined, on: {
2327
2328
  left?: string;
2328
2329
  right?: string;
2329
2330
  operator: string;
2330
- }, isRawValue?: boolean);
2331
+ }, isRawValue?: boolean, additionalConditions?: (WhereNode | WhereGroupNode | WhereSubqueryNode)[]);
2331
2332
  }
2332
2333
 
2333
2334
  declare class GroupByNode extends QueryNode {
@@ -2651,6 +2652,222 @@ declare abstract class FooterQueryBuilder<T extends Model> {
2651
2652
  offset(offset: number): this;
2652
2653
  }
2653
2654
 
2655
+ declare class JoinOnQueryBuilder {
2656
+ protected sqlDataSource: SqlDataSource;
2657
+ protected whereNodes: (WhereNode | WhereGroupNode | WhereSubqueryNode)[];
2658
+ protected isNestedCondition: boolean;
2659
+ constructor(sqlDataSource: SqlDataSource, isNestedCondition?: boolean);
2660
+ /**
2661
+ * @description Get the where conditions for the join
2662
+ */
2663
+ getConditions(): (WhereNode | WhereGroupNode | WhereSubqueryNode)[];
2664
+ /**
2665
+ * @description Adds a WHERE condition to the query.
2666
+ */
2667
+ where(column: SelectableColumn<string>, operator: BinaryOperatorType, value: BaseValues): this;
2668
+ where(cb: (queryBuilder: JoinOnQueryBuilder) => void): this;
2669
+ where(column: SelectableColumn<string>, value: BaseValues): this;
2670
+ /**
2671
+ * @description Adds an AND WHERE condition to the query.
2672
+ */
2673
+ andWhere(column: SelectableColumn<string>, operator: BinaryOperatorType, value: BaseValues): this;
2674
+ andWhere(column: SelectableColumn<string>, value: BaseValues): this;
2675
+ andWhere(cb: (queryBuilder: JoinOnQueryBuilder) => void): this;
2676
+ /**
2677
+ * @description Adds an OR WHERE condition to the query.
2678
+ */
2679
+ orWhere(column: SelectableColumn<string>, operator: BinaryOperatorType, value: BaseValues): this;
2680
+ orWhere(column: SelectableColumn<string>, value: BaseValues): this;
2681
+ orWhere(cb: (queryBuilder: JoinOnQueryBuilder) => void): this;
2682
+ /**
2683
+ * @description Adds a negated WHERE condition to the query.
2684
+ */
2685
+ whereNot(column: SelectableColumn<string>, operator: BinaryOperatorType, value: BaseValues): this;
2686
+ whereNot(column: SelectableColumn<string>, value: BaseValues): this;
2687
+ /**
2688
+ * @description Adds a negated AND WHERE condition to the query.
2689
+ */
2690
+ andWhereNot(column: SelectableColumn<string>, operator: BinaryOperatorType, value: BaseValues): this;
2691
+ andWhereNot(column: SelectableColumn<string>, value: BaseValues): this;
2692
+ /**
2693
+ * @description Adds a negated OR WHERE condition to the query.
2694
+ */
2695
+ orWhereNot(column: SelectableColumn<string>, operator: BinaryOperatorType, value: BaseValues): this;
2696
+ orWhereNot(column: SelectableColumn<string>, value: BaseValues): this;
2697
+ /**
2698
+ * @description Adds a WHERE BETWEEN condition to the query.
2699
+ */
2700
+ whereBetween(column: SelectableColumn<string>, min: BaseValues, max: BaseValues): this;
2701
+ /**
2702
+ * @description Adds an AND WHERE BETWEEN condition to the query.
2703
+ */
2704
+ andWhereBetween(column: SelectableColumn<string>, min: BaseValues, max: BaseValues): this;
2705
+ /**
2706
+ * @description Adds an OR WHERE BETWEEN condition to the query.
2707
+ */
2708
+ orWhereBetween(column: SelectableColumn<string>, min: BaseValues, max: BaseValues): this;
2709
+ /**
2710
+ * @description Adds a WHERE NOT BETWEEN condition to the query.
2711
+ */
2712
+ whereNotBetween(column: SelectableColumn<string>, min: BaseValues, max: BaseValues): this;
2713
+ /**
2714
+ * @description Adds an AND WHERE NOT BETWEEN condition to the query.
2715
+ */
2716
+ andWhereNotBetween(column: SelectableColumn<string>, min: BaseValues, max: BaseValues): this;
2717
+ /**
2718
+ * @description Adds an OR WHERE NOT BETWEEN condition to the query.
2719
+ */
2720
+ orWhereNotBetween(column: SelectableColumn<string>, min: BaseValues, max: BaseValues): this;
2721
+ /**
2722
+ * @description Adds a WHERE LIKE condition to the query.
2723
+ */
2724
+ whereLike(column: SelectableColumn<string>, value: string): this;
2725
+ /**
2726
+ * @description Adds an AND WHERE LIKE condition to the query.
2727
+ */
2728
+ andWhereLike(column: SelectableColumn<string>, value: string): this;
2729
+ /**
2730
+ * @description Adds an OR WHERE LIKE condition to the query.
2731
+ */
2732
+ orWhereLike(column: SelectableColumn<string>, value: string): this;
2733
+ /**
2734
+ * @description Adds a WHERE ILIKE condition to the query.
2735
+ */
2736
+ whereILike(column: SelectableColumn<string>, value: string): this;
2737
+ /**
2738
+ * @description Adds an AND WHERE ILIKE condition to the query.
2739
+ */
2740
+ andWhereILike(column: SelectableColumn<string>, value: string): this;
2741
+ /**
2742
+ * @description Adds an OR WHERE ILIKE condition to the query.
2743
+ */
2744
+ orWhereILike(column: SelectableColumn<string>, value: string): this;
2745
+ /**
2746
+ * @description Adds a WHERE NOT LIKE condition to the query.
2747
+ */
2748
+ whereNotLike(column: SelectableColumn<string>, value: string): this;
2749
+ /**
2750
+ * @description Adds an AND WHERE NOT LIKE condition to the query.
2751
+ */
2752
+ andWhereNotLike(column: SelectableColumn<string>, value: string): this;
2753
+ /**
2754
+ * @description Adds an OR WHERE NOT LIKE condition to the query.
2755
+ */
2756
+ orWhereNotLike(column: SelectableColumn<string>, value: string): this;
2757
+ /**
2758
+ * @description Adds a WHERE NOT ILIKE condition to the query.
2759
+ */
2760
+ whereNotILike(column: SelectableColumn<string>, value: string): this;
2761
+ /**
2762
+ * @description Adds an AND WHERE NOT ILIKE condition to the query.
2763
+ */
2764
+ andWhereNotILike(column: SelectableColumn<string>, value: string): this;
2765
+ /**
2766
+ * @description Adds an OR WHERE NOT ILIKE condition to the query.
2767
+ */
2768
+ orWhereNotILike(column: SelectableColumn<string>, value: string): this;
2769
+ /**
2770
+ * @description Adds a WHERE IN condition to the query.
2771
+ */
2772
+ whereIn(column: SelectableColumn<string>, values: BaseValues[]): this;
2773
+ /**
2774
+ * @description Adds an AND WHERE IN condition to the query.
2775
+ */
2776
+ andWhereIn(column: SelectableColumn<string>, values: BaseValues[]): this;
2777
+ /**
2778
+ * @description Adds an OR WHERE IN condition to the query.
2779
+ */
2780
+ orWhereIn(column: SelectableColumn<string>, values: BaseValues[]): this;
2781
+ /**
2782
+ * @description Adds a WHERE NOT IN condition to the query.
2783
+ */
2784
+ whereNotIn(column: SelectableColumn<string>, values: BaseValues[]): this;
2785
+ /**
2786
+ * @description Adds an AND WHERE NOT IN condition to the query.
2787
+ */
2788
+ andWhereNotIn(column: SelectableColumn<string>, values: BaseValues[]): this;
2789
+ /**
2790
+ * @description Adds an OR WHERE NOT IN condition to the query.
2791
+ */
2792
+ orWhereNotIn(column: SelectableColumn<string>, values: BaseValues[]): this;
2793
+ /**
2794
+ * @description Adds a WHERE NULL condition to the query.
2795
+ */
2796
+ whereNull(column: SelectableColumn<string>): this;
2797
+ /**
2798
+ * @description Adds an AND WHERE NULL condition to the query.
2799
+ */
2800
+ andWhereNull(column: SelectableColumn<string>): this;
2801
+ /**
2802
+ * @description Adds an OR WHERE NULL condition to the query.
2803
+ */
2804
+ orWhereNull(column: SelectableColumn<string>): this;
2805
+ /**
2806
+ * @description Adds a WHERE NOT NULL condition to the query.
2807
+ */
2808
+ whereNotNull(column: SelectableColumn<string>): this;
2809
+ /**
2810
+ * @description Adds an AND WHERE NOT NULL condition to the query.
2811
+ */
2812
+ andWhereNotNull(column: SelectableColumn<string>): this;
2813
+ /**
2814
+ * @description Adds an OR WHERE NOT NULL condition to the query.
2815
+ */
2816
+ orWhereNotNull(column: SelectableColumn<string>): this;
2817
+ /**
2818
+ * @description Adds a WHERE REGEXP condition to the query.
2819
+ */
2820
+ whereRegexp(column: SelectableColumn<string>, regexp: RegExp): this;
2821
+ /**
2822
+ * @description Adds an AND WHERE REGEXP condition to the query.
2823
+ */
2824
+ andWhereRegexp(column: SelectableColumn<string>, regexp: RegExp): this;
2825
+ /**
2826
+ * @description Adds an OR WHERE REGEXP condition to the query.
2827
+ */
2828
+ orWhereRegexp(column: SelectableColumn<string>, regexp: RegExp): this;
2829
+ /**
2830
+ * @description Adds a WHERE NOT REGEXP condition to the query.
2831
+ */
2832
+ whereNotRegexp(column: SelectableColumn<string>, regexp: RegExp): this;
2833
+ /**
2834
+ * @description Adds an AND WHERE NOT REGEXP condition to the query.
2835
+ */
2836
+ andWhereNotRegexp(column: SelectableColumn<string>, regexp: RegExp): this;
2837
+ /**
2838
+ * @description Adds an OR WHERE NOT REGEXP condition to the query.
2839
+ */
2840
+ orWhereNotRegexp(column: SelectableColumn<string>, regexp: RegExp): this;
2841
+ /**
2842
+ * @description Adds a WHERE group condition with AND.
2843
+ */
2844
+ whereGroup(cb: (queryBuilder: JoinOnQueryBuilder) => void): this;
2845
+ /**
2846
+ * @description Adds a WHERE group condition with AND.
2847
+ */
2848
+ andWhereGroup(cb: (queryBuilder: JoinOnQueryBuilder) => void): this;
2849
+ /**
2850
+ * @description Adds a WHERE group condition with OR.
2851
+ */
2852
+ orWhereGroup(cb: (queryBuilder: JoinOnQueryBuilder) => void): this;
2853
+ /**
2854
+ * @description Adds a raw WHERE condition to the query.
2855
+ */
2856
+ whereRaw(sql: string, bindings?: BaseValues[]): this;
2857
+ /**
2858
+ * @description Adds an AND raw WHERE condition to the query.
2859
+ */
2860
+ andWhereRaw(sql: string, bindings?: BaseValues[]): this;
2861
+ /**
2862
+ * @description Adds an OR raw WHERE condition to the query.
2863
+ */
2864
+ orWhereRaw(sql: string, bindings?: BaseValues[]): this;
2865
+ }
2866
+
2867
+ /**
2868
+ * @description Callback type for join conditions
2869
+ */
2870
+ type JoinOnCallback = (query: JoinOnQueryBuilder) => void;
2654
2871
  declare abstract class JoinQueryBuilder<T extends Model> extends FooterQueryBuilder<T> {
2655
2872
  protected joinNodes: JoinNode[];
2656
2873
  protected constructor(model: typeof Model, sqlDataSource: SqlDataSource);
@@ -2693,6 +2910,10 @@ declare abstract class JoinQueryBuilder<T extends Model> extends FooterQueryBuil
2693
2910
  innerJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType): this;
2694
2911
  innerJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator?: BinaryOperatorType): this;
2695
2912
  innerJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn?: ModelKey<T>, operator?: BinaryOperatorType): this;
2913
+ innerJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, operator: BinaryOperatorType, callback: JoinOnCallback): this;
2914
+ innerJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, callback: JoinOnCallback): this;
2915
+ innerJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator: BinaryOperatorType, callback: JoinOnCallback): this;
2916
+ innerJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, callback: JoinOnCallback): this;
2696
2917
  /**
2697
2918
  * @description Join a table with the current model
2698
2919
  * @param relationTable - The table to join
@@ -2704,6 +2925,10 @@ declare abstract class JoinQueryBuilder<T extends Model> extends FooterQueryBuil
2704
2925
  join(relationTable: string, referencingColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType): this;
2705
2926
  join<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator?: BinaryOperatorType): this;
2706
2927
  join<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn?: ModelKey<T>, operator?: BinaryOperatorType): this;
2928
+ join(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, operator: BinaryOperatorType, callback: JoinOnCallback): this;
2929
+ join(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, callback: JoinOnCallback): this;
2930
+ join<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator: BinaryOperatorType, callback: JoinOnCallback): this;
2931
+ join<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, callback: JoinOnCallback): this;
2707
2932
  /**
2708
2933
  * @description Join a table with the current model
2709
2934
  * @param relationTable - The table to join
@@ -2715,6 +2940,10 @@ declare abstract class JoinQueryBuilder<T extends Model> extends FooterQueryBuil
2715
2940
  leftJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType): this;
2716
2941
  leftJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator?: BinaryOperatorType): this;
2717
2942
  leftJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn?: ModelKey<T>, operator?: BinaryOperatorType): this;
2943
+ leftJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, operator: BinaryOperatorType, callback: JoinOnCallback): this;
2944
+ leftJoin(relationTable: string, referencingColumn: JoinableColumn, primaryColumn: JoinableColumn, callback: JoinOnCallback): this;
2945
+ leftJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, operator: BinaryOperatorType, callback: JoinOnCallback): this;
2946
+ leftJoin<R extends typeof Model>(relationModel: R, referencingColumn: ModelKey<InstanceType<R>>, primaryColumn: ModelKey<T>, callback: JoinOnCallback): this;
2718
2947
  /**
2719
2948
  * @description Join a table with the current model
2720
2949
  * @param relationTable - The table to join
@@ -2724,6 +2953,9 @@ declare abstract class JoinQueryBuilder<T extends Model> extends FooterQueryBuil
2724
2953
  */
2725
2954
  rightJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, operator?: BinaryOperatorType): this;
2726
2955
  rightJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType): this;
2956
+ rightJoin<R extends typeof Model>(relationTable: string | R, referencingColumnOrPrimaryColumn: ModelKey<InstanceType<R>> | JoinableColumn | ModelKey<T>, primaryColumn?: JoinableColumn | ModelKey<T>, operator?: BinaryOperatorType): this;
2957
+ rightJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, operator: BinaryOperatorType, callback: JoinOnCallback): this;
2958
+ rightJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, callback: JoinOnCallback): this;
2727
2959
  /**
2728
2960
  * @description Perform a FULL OUTER JOIN with another table
2729
2961
  * @param relationTable - The table to join
@@ -2733,6 +2965,9 @@ declare abstract class JoinQueryBuilder<T extends Model> extends FooterQueryBuil
2733
2965
  */
2734
2966
  fullJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, operator?: BinaryOperatorType): this;
2735
2967
  fullJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn?: JoinableColumn, operator?: BinaryOperatorType): this;
2968
+ fullJoin<R extends typeof Model>(relationTable: string | R, referencingColumnOrPrimaryColumn: ModelKey<InstanceType<R>> | JoinableColumn | ModelKey<T>, primaryColumn?: JoinableColumn | ModelKey<T>, operator?: BinaryOperatorType): this;
2969
+ fullJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, operator: BinaryOperatorType, callback: JoinOnCallback): this;
2970
+ fullJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, callback: JoinOnCallback): this;
2736
2971
  }
2737
2972
 
2738
2973
  declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
@@ -2751,8 +2986,8 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
2751
2986
  * @warning For annotations, use the `annotate` method instead, aliases and methods are not supported in the select method and will give error `column "${columnName} as ${alias}" does not exist`
2752
2987
  * @example
2753
2988
  * ```ts
2754
- * const user = await User.query().select("name", "age").first(); // SELECT name, age FROM users
2755
- * const user = await User.query().select("name", "users.age").first(); // SELECT name, users.age FROM users
2989
+ * const user = await User.query().select("name", "age").one(); // SELECT name, age FROM users
2990
+ * const user = await User.query().select("name", "users.age").one(); // SELECT name, users.age FROM users
2756
2991
  * ```
2757
2992
  */
2758
2993
  select<S extends string>(...columns: SelectableColumn<S>[]): this;
@@ -2783,9 +3018,9 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
2783
3018
  * @description If using a model, the result will be available in the $annotations property of the model, else it will be available in the result of the query
2784
3019
  * @example
2785
3020
  * ```ts
2786
- * const user = await User.query().annotate("max", "id", "maxId").first(); // max(id) as maxId
2787
- * const user = await User.query().annotate("id", "superId").first(); // id as superId
2788
- * const user = await User.query().annotate("id", "superId").first(); // id as superId
3021
+ * const user = await User.query().annotate("max", "id", "maxId").one(); // max(id) as maxId
3022
+ * const user = await User.query().annotate("id", "superId").one(); // id as superId
3023
+ * const user = await User.query().annotate("id", "superId").one(); // id as superId
2789
3024
  * ```
2790
3025
  */
2791
3026
  annotate<A extends string>(column: string, alias: A): this;
@@ -2824,15 +3059,15 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
2824
3059
  * @example
2825
3060
  * ```ts
2826
3061
  * // All databases accept the same path format:
2827
- * const user = await User.query().selectJson("data", "$.user.name", "userName").first();
3062
+ * const user = await User.query().selectJson("data", "$.user.name", "userName").one();
2828
3063
  * console.log(user?.$annotations?.userName); // Typed!
2829
3064
  *
2830
- * await User.query().selectJson("data", "user.name", "userName").first(); // $ is optional
2831
- * await User.query().selectJson("data", ["user", "name"], "userName").first();
3065
+ * await User.query().selectJson("data", "user.name", "userName").one(); // $ is optional
3066
+ * await User.query().selectJson("data", ["user", "name"], "userName").one();
2832
3067
  *
2833
3068
  * // Array indices:
2834
- * await User.query().selectJson("data", "items.0.name", "firstItemName").first();
2835
- * await User.query().selectJson("data", ["items", 0, "name"], "firstItemName").first();
3069
+ * await User.query().selectJson("data", "items.0.name", "firstItemName").one();
3070
+ * await User.query().selectJson("data", ["items", 0, "name"], "firstItemName").one();
2836
3071
  * ```
2837
3072
  */
2838
3073
  selectJson<A extends string>(column: ModelKey<T>, path: JsonPathInput, alias: A): this;
@@ -2847,10 +3082,10 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
2847
3082
  * @example
2848
3083
  * ```ts
2849
3084
  * // All databases accept the same path format:
2850
- * const user = await User.query().selectJsonText("data", "$.user.name", "userName").first();
3085
+ * const user = await User.query().selectJsonText("data", "$.user.name", "userName").one();
2851
3086
  * console.log(user?.$annotations?.userName); // Typed!
2852
3087
  *
2853
- * await User.query().selectJsonText("data", ["user", "name"], "userName").first();
3088
+ * await User.query().selectJsonText("data", ["user", "name"], "userName").one();
2854
3089
  * ```
2855
3090
  */
2856
3091
  selectJsonText<A extends string>(column: ModelKey<T>, path: JsonPathInput, alias: A): this;
@@ -2865,11 +3100,11 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
2865
3100
  * @example
2866
3101
  * ```ts
2867
3102
  * // All databases accept the same path format:
2868
- * const user = await User.query().selectJsonArrayLength("data", "$.items", "itemCount").first();
3103
+ * const user = await User.query().selectJsonArrayLength("data", "$.items", "itemCount").one();
2869
3104
  * console.log(user?.$annotations?.itemCount); // Typed!
2870
3105
  *
2871
- * await User.query().selectJsonArrayLength("data", "items", "itemCount").first();
2872
- * await User.query().selectJsonArrayLength("data", "$", "totalCount").first(); // root array
3106
+ * await User.query().selectJsonArrayLength("data", "items", "itemCount").one();
3107
+ * await User.query().selectJsonArrayLength("data", "$", "totalCount").one(); // root array
2873
3108
  * ```
2874
3109
  */
2875
3110
  selectJsonArrayLength<A extends string>(column: ModelKey<T>, path: JsonPathInput, alias: A): this;
@@ -2886,11 +3121,11 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
2886
3121
  * @example
2887
3122
  * ```ts
2888
3123
  * // All databases accept the same path format:
2889
- * const user = await User.query().selectJsonKeys("data", "$.user", "userKeys").first();
3124
+ * const user = await User.query().selectJsonKeys("data", "$.user", "userKeys").one();
2890
3125
  * console.log(user?.$annotations?.userKeys); // Typed!
2891
3126
  *
2892
- * await User.query().selectJsonKeys("data", "user", "userKeys").first();
2893
- * await User.query().selectJsonKeys("data", "$", "rootKeys").first(); // root object
3127
+ * await User.query().selectJsonKeys("data", "user", "userKeys").one();
3128
+ * await User.query().selectJsonKeys("data", "$", "rootKeys").one(); // root object
2894
3129
  * ```
2895
3130
  */
2896
3131
  selectJsonKeys<A extends string>(column: ModelKey<T>, path: JsonPathInput, alias: A): this;
@@ -2902,7 +3137,7 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
2902
3137
  * @description Result will be available in model.$annotations[alias]
2903
3138
  * @example
2904
3139
  * ```ts
2905
- * const user = await User.query().selectJsonRaw("data->>'email'", "userEmail").first();
3140
+ * const user = await User.query().selectJsonRaw("data->>'email'", "userEmail").one();
2906
3141
  * console.log(user?.$annotations?.userEmail); // Typed!
2907
3142
  * ```
2908
3143
  */
@@ -3450,14 +3685,6 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
3450
3685
  data: AnnotatedModel<T, A, R>;
3451
3686
  time: number;
3452
3687
  }>;
3453
- first: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
3454
- data: AnnotatedModel<T, A, R> | null;
3455
- time: number;
3456
- }>;
3457
- firstOrFail: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
3458
- data: AnnotatedModel<T, A, R>;
3459
- time: number;
3460
- }>;
3461
3688
  paginate: (page: number, perPage: number, options?: {
3462
3689
  ignoreHooks?: boolean;
3463
3690
  }, returnType?: "millis" | "seconds") => Promise<{
@@ -3504,7 +3731,6 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
3504
3731
  */
3505
3732
  static from(model: typeof Model, options?: BaseModelMethodOptions): ModelQueryBuilder<InstanceType<typeof model>>;
3506
3733
  one(options?: OneOptions): Promise<AnnotatedModel<T, A, R> | null>;
3507
- first(options?: OneOptions): Promise<AnnotatedModel<T, A, R> | null>;
3508
3734
  oneOrFail(options?: {
3509
3735
  ignoreHooks?: OneOptions["ignoreHooks"] & {
3510
3736
  customError?: Error;
@@ -3555,10 +3781,10 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
3555
3781
  * @description If the alias matches a model field name, it overrides that field. Otherwise, it's available in $annotations
3556
3782
  * @example
3557
3783
  * ```ts
3558
- * const user = await User.query().annotate("max", "id", "maxId").first(); // max(id) as maxId
3559
- * const user = await User.query().annotate("id", "superId").first(); // id as superId
3784
+ * const user = await User.query().annotate("max", "id", "maxId").one(); // max(id) as maxId
3785
+ * const user = await User.query().annotate("id", "superId").one(); // id as superId
3560
3786
  * // If alias matches model field, it overrides it:
3561
- * const user = await User.query().annotate("COUNT(*)", "email").first(); // user.email is now a number
3787
+ * const user = await User.query().annotate("COUNT(*)", "email").one(); // user.email is now a number
3562
3788
  * ```
3563
3789
  */
3564
3790
  annotate<K extends string, V = any>(column: string, alias: K): AnnotationResult<T, A, R, K, V>;
@@ -3577,29 +3803,29 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
3577
3803
  * // All these path formats are supported:
3578
3804
  *
3579
3805
  * // 1. With $ prefix (standard JSON path)
3580
- * await User.query().selectJson("data", "$.user.name", "userName").first();
3806
+ * await User.query().selectJson("data", "$.user.name", "userName").one();
3581
3807
  *
3582
3808
  * // 2. Without $ prefix ($ is optional)
3583
- * await User.query().selectJson("data", "user.name", "userName").first();
3809
+ * await User.query().selectJson("data", "user.name", "userName").one();
3584
3810
  *
3585
3811
  * // 3. Array format
3586
- * await User.query().selectJson("data", ["user", "name"], "userName").first();
3812
+ * await User.query().selectJson("data", ["user", "name"], "userName").one();
3587
3813
  *
3588
3814
  * // 4. Array indices with dot notation
3589
- * await User.query().selectJson("data", "items.0.name", "firstItemName").first();
3815
+ * await User.query().selectJson("data", "items.0.name", "firstItemName").one();
3590
3816
  *
3591
3817
  * // 5. Array indices with array format
3592
- * await User.query().selectJson("data", ["items", 0, "name"], "firstItemName").first();
3818
+ * await User.query().selectJson("data", ["items", 0, "name"], "firstItemName").one();
3593
3819
  *
3594
3820
  * // 6. Root object
3595
- * await User.query().selectJson("data", "$", "allData").first();
3821
+ * await User.query().selectJson("data", "$", "allData").one();
3596
3822
  *
3597
3823
  * // Access the result - in $annotations if not a model field
3598
- * const user = await User.query().selectJson("data", "user.name", "userName").first();
3824
+ * const user = await User.query().selectJson("data", "user.name", "userName").one();
3599
3825
  * console.log(user?.$annotations?.userName); // Typed as any
3600
3826
  *
3601
3827
  * // If alias matches model field, it overrides it
3602
- * const user2 = await User.query().selectJson("data", "$.name", "email").first();
3828
+ * const user2 = await User.query().selectJson("data", "$.name", "email").one();
3603
3829
  * console.log(user2?.email); // Overrides model's email field
3604
3830
  * ```
3605
3831
  */
@@ -3617,23 +3843,23 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
3617
3843
  * // All these path formats are supported:
3618
3844
  *
3619
3845
  * // 1. With $ prefix
3620
- * await User.query().selectJsonText("data", "$.user.email", "userEmail").first();
3846
+ * await User.query().selectJsonText("data", "$.user.email", "userEmail").one();
3621
3847
  *
3622
3848
  * // 2. Without $ prefix
3623
- * await User.query().selectJsonText("data", "user.email", "userEmail").first();
3849
+ * await User.query().selectJsonText("data", "user.email", "userEmail").one();
3624
3850
  *
3625
3851
  * // 3. Array format
3626
- * await User.query().selectJsonText("data", ["user", "email"], "userEmail").first();
3852
+ * await User.query().selectJsonText("data", ["user", "email"], "userEmail").one();
3627
3853
  *
3628
3854
  * // 4. Array indices
3629
- * await User.query().selectJsonText("data", "tags.0", "firstTag").first();
3630
- * await User.query().selectJsonText("data", ["tags", 0], "firstTag").first();
3855
+ * await User.query().selectJsonText("data", "tags.0", "firstTag").one();
3856
+ * await User.query().selectJsonText("data", ["tags", 0], "firstTag").one();
3631
3857
  *
3632
3858
  * // 5. Deep nesting
3633
- * await User.query().selectJsonText("data", "user.profile.bio", "biography").first();
3859
+ * await User.query().selectJsonText("data", "user.profile.bio", "biography").one();
3634
3860
  *
3635
3861
  * // Access the result - in $annotations if not a model field
3636
- * const user = await User.query().selectJsonText("data", "user.email", "userEmail").first();
3862
+ * const user = await User.query().selectJsonText("data", "user.email", "userEmail").one();
3637
3863
  * console.log(user?.$annotations?.userEmail); // Typed as string
3638
3864
  * ```
3639
3865
  */
@@ -3652,27 +3878,27 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
3652
3878
  * // All these path formats are supported:
3653
3879
  *
3654
3880
  * // 1. With $ prefix
3655
- * await User.query().selectJsonArrayLength("data", "$.items", "itemCount").first();
3881
+ * await User.query().selectJsonArrayLength("data", "$.items", "itemCount").one();
3656
3882
  *
3657
3883
  * // 2. Without $ prefix
3658
- * await User.query().selectJsonArrayLength("data", "items", "itemCount").first();
3884
+ * await User.query().selectJsonArrayLength("data", "items", "itemCount").one();
3659
3885
  *
3660
3886
  * // 3. Array format
3661
- * await User.query().selectJsonArrayLength("data", ["items"], "itemCount").first();
3887
+ * await User.query().selectJsonArrayLength("data", ["items"], "itemCount").one();
3662
3888
  *
3663
3889
  * // 4. Root array (use "$" or "")
3664
- * await User.query().selectJsonArrayLength("data", "$", "totalCount").first();
3665
- * await User.query().selectJsonArrayLength("data", "", "totalCount").first();
3890
+ * await User.query().selectJsonArrayLength("data", "$", "totalCount").one();
3891
+ * await User.query().selectJsonArrayLength("data", "", "totalCount").one();
3666
3892
  *
3667
3893
  * // 5. Nested arrays
3668
- * await User.query().selectJsonArrayLength("data", "user.roles", "roleCount").first();
3669
- * await User.query().selectJsonArrayLength("data", ["user", "roles"], "roleCount").first();
3894
+ * await User.query().selectJsonArrayLength("data", "user.roles", "roleCount").one();
3895
+ * await User.query().selectJsonArrayLength("data", ["user", "roles"], "roleCount").one();
3670
3896
  *
3671
3897
  * // 6. Deeply nested arrays
3672
- * await User.query().selectJsonArrayLength("data", "level1.level2.items", "deepCount").first();
3898
+ * await User.query().selectJsonArrayLength("data", "level1.level2.items", "deepCount").one();
3673
3899
  *
3674
3900
  * // Access the result - in $annotations if not a model field
3675
- * const user = await User.query().selectJsonArrayLength("data", "items", "count").first();
3901
+ * const user = await User.query().selectJsonArrayLength("data", "items", "count").one();
3676
3902
  * console.log(user?.$annotations?.count); // Typed as number
3677
3903
  * ```
3678
3904
  */
@@ -3693,27 +3919,27 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
3693
3919
  * // All these path formats are supported:
3694
3920
  *
3695
3921
  * // 1. With $ prefix
3696
- * await User.query().selectJsonKeys("data", "$.settings", "settingKeys").first();
3922
+ * await User.query().selectJsonKeys("data", "$.settings", "settingKeys").one();
3697
3923
  *
3698
3924
  * // 2. Without $ prefix
3699
- * await User.query().selectJsonKeys("data", "settings", "settingKeys").first();
3925
+ * await User.query().selectJsonKeys("data", "settings", "settingKeys").one();
3700
3926
  *
3701
3927
  * // 3. Array format
3702
- * await User.query().selectJsonKeys("data", ["settings"], "settingKeys").first();
3928
+ * await User.query().selectJsonKeys("data", ["settings"], "settingKeys").one();
3703
3929
  *
3704
3930
  * // 4. Root object (use "$" or "")
3705
- * await User.query().selectJsonKeys("data", "$", "rootKeys").first();
3706
- * await User.query().selectJsonKeys("data", "", "rootKeys").first();
3931
+ * await User.query().selectJsonKeys("data", "$", "rootKeys").one();
3932
+ * await User.query().selectJsonKeys("data", "", "rootKeys").one();
3707
3933
  *
3708
3934
  * // 5. Nested objects
3709
- * await User.query().selectJsonKeys("data", "user.profile", "profileKeys").first();
3710
- * await User.query().selectJsonKeys("data", ["user", "profile"], "profileKeys").first();
3935
+ * await User.query().selectJsonKeys("data", "user.profile", "profileKeys").one();
3936
+ * await User.query().selectJsonKeys("data", ["user", "profile"], "profileKeys").one();
3711
3937
  *
3712
3938
  * // 6. Deeply nested objects
3713
- * await User.query().selectJsonKeys("data", "settings.display.theme", "themeKeys").first();
3939
+ * await User.query().selectJsonKeys("data", "settings.display.theme", "themeKeys").one();
3714
3940
  *
3715
3941
  * // Access the result - in $annotations if not a model field
3716
- * const user = await User.query().selectJsonKeys("data", "settings", "keys").first();
3942
+ * const user = await User.query().selectJsonKeys("data", "settings", "keys").one();
3717
3943
  * console.log(user?.$annotations?.keys); // Typed as any[] - ["theme", "fontSize", "autoSave"]
3718
3944
  * ```
3719
3945
  */
@@ -3729,28 +3955,28 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
3729
3955
  * @example
3730
3956
  * ```ts
3731
3957
  * // PostgreSQL - Extract as text with ->> operator
3732
- * await User.query().selectJsonRaw("data->>'email'", "userEmail").first();
3958
+ * await User.query().selectJsonRaw("data->>'email'", "userEmail").one();
3733
3959
  *
3734
3960
  * // PostgreSQL - Extract nested JSON with -> operator
3735
- * await User.query().selectJsonRaw("data->'user'->'profile'->>'name'", "profileName").first();
3961
+ * await User.query().selectJsonRaw("data->'user'->'profile'->>'name'", "profileName").one();
3736
3962
  *
3737
3963
  * // PostgreSQL - Array element access
3738
- * await User.query().selectJsonRaw("data->'items'->0->>'name'", "firstName").first();
3964
+ * await User.query().selectJsonRaw("data->'items'->0->>'name'", "firstName").one();
3739
3965
  *
3740
3966
  * // MySQL - Extract value with JSON_EXTRACT and ->>
3741
- * await User.query().selectJsonRaw("data->>'$.email'", "userEmail").first();
3967
+ * await User.query().selectJsonRaw("data->>'$.email'", "userEmail").one();
3742
3968
  *
3743
3969
  * // MySQL - Array length with JSON_LENGTH
3744
- * await User.query().selectJsonRaw("JSON_LENGTH(data, '$.items')", "itemCount").first();
3970
+ * await User.query().selectJsonRaw("JSON_LENGTH(data, '$.items')", "itemCount").one();
3745
3971
  *
3746
3972
  * // MSSQL - Extract value with JSON_VALUE
3747
- * await User.query().selectJsonRaw("JSON_VALUE(data, '$.email')", "userEmail").first();
3973
+ * await User.query().selectJsonRaw("JSON_VALUE(data, '$.email')", "userEmail").one();
3748
3974
  *
3749
3975
  * // SQLite - Extract value with json_extract
3750
- * await User.query().selectJsonRaw("json_extract(data, '$.email')", "userEmail").first();
3976
+ * await User.query().selectJsonRaw("json_extract(data, '$.email')", "userEmail").one();
3751
3977
  *
3752
3978
  * // Access the result - in $annotations if not a model field
3753
- * const user = await User.query().selectJsonRaw("data->>'email'", "userEmail").first();
3979
+ * const user = await User.query().selectJsonRaw("data->>'email'", "userEmail").one();
3754
3980
  * console.log(user?.$annotations?.userEmail); // Typed as any
3755
3981
  * ```
3756
3982
  */
@@ -3831,7 +4057,6 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
3831
4057
  private oneWithPerformance;
3832
4058
  private oneOrFailWithPerformance;
3833
4059
  private firstOrFailWithPerformance;
3834
- private firstWithPerformance;
3835
4060
  private paginateWithPerformance;
3836
4061
  private paginateWithCursorWithPerformance;
3837
4062
  private existsWithPerformance;
@@ -4028,7 +4253,7 @@ type TransactionExecutionOptions = {
4028
4253
  };
4029
4254
 
4030
4255
  /**
4031
- * @description Transaction class, not meant to be used directly, use sql.startTransaction() instead
4256
+ * @description Transaction class, not meant to be used directly, use sql.transaction() instead
4032
4257
  */
4033
4258
  declare class Transaction {
4034
4259
  /**
@@ -4039,7 +4264,7 @@ declare class Transaction {
4039
4264
  * import { User } from "./models/user";
4040
4265
  *
4041
4266
  * // Raw queries
4042
- * const trx = await sql.startTransaction();
4267
+ * const trx = await sql.transaction();
4043
4268
  * await trx.rawQuery("SELECT * FROM users");
4044
4269
  *
4045
4270
  * // Model manager
@@ -4052,7 +4277,7 @@ declare class Transaction {
4052
4277
  * await trx.commit();
4053
4278
  * ```
4054
4279
  */
4055
- sql: Omit<SqlDataSource, "transaction" | "startGlobalTransaction" | "startTransaction">;
4280
+ sql: Omit<SqlDataSource, "transaction" | "startGlobalTransaction">;
4056
4281
  /**
4057
4282
  * @description Whether the transaction is active
4058
4283
  */
@@ -4073,9 +4298,9 @@ declare class Transaction {
4073
4298
  nestedTransaction(): Promise<Transaction>;
4074
4299
  nestedTransaction(cb: (trx: Transaction) => Promise<void>): Promise<void>;
4075
4300
  /**
4076
- * @description Starts a transaction, automatically handled from the sql data source instance in the `startTransaction` method
4301
+ * @description Starts a transaction, automatically handled from the sql data source instance in the `transaction` method
4077
4302
  */
4078
- startTransaction(): Promise<void>;
4303
+ transaction(): Promise<void>;
4079
4304
  /**
4080
4305
  * @description Commit the transaction releasing the connection
4081
4306
  * @throws {HysteriaError} if the transaction is not active and options.throwErrorOnInactiveTransaction is true
@@ -4228,10 +4453,6 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
4228
4453
  /**
4229
4454
  * @description Closes the primary connection (singleton instance)
4230
4455
  */
4231
- static closeConnection(): Promise<void>;
4232
- /**
4233
- * @alias closeConnection
4234
- */
4235
4456
  static disconnect(): Promise<void>;
4236
4457
  /**
4237
4458
  * @description Starts a global transaction on the primary database connection
@@ -4375,11 +4596,6 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
4375
4596
  * @param options.isolationLevel The isolation level to use for the transaction
4376
4597
  * @sqlite ignores the isolation level
4377
4598
  */
4378
- startTransaction(options?: StartTransactionOptions): Promise<Transaction>;
4379
- startTransaction(cb: (trx: Transaction) => Promise<void>, options?: StartTransactionOptions): Promise<void>;
4380
- /**
4381
- * @alias startTransaction
4382
- */
4383
4599
  transaction(options?: StartTransactionOptions): Promise<Transaction>;
4384
4600
  transaction(cb: (trx: Transaction) => Promise<void>, options?: StartTransactionOptions): Promise<void>;
4385
4601
  /**
@@ -4403,15 +4619,11 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
4403
4619
  * @description If there is an active global transaction, it will be rolled back
4404
4620
  * @description Also disconnects all slave connections if any are configured
4405
4621
  */
4406
- closeConnection(): Promise<void>;
4622
+ disconnect(): Promise<void>;
4407
4623
  /**
4408
4624
  * @description Returns the connection details
4409
4625
  */
4410
4626
  getConnectionDetails(): SqlDataSourceInput<D, T, C>;
4411
- /**
4412
- * @alias closeConnection
4413
- */
4414
- disconnect(): Promise<void>;
4415
4627
  /**
4416
4628
  * @description Syncs the schema of the database with the models metadata
4417
4629
  * @warning This will drop and recreate all the indexes and constraints, use with caution
@@ -4420,6 +4632,11 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
4420
4632
  syncSchema(options?: {
4421
4633
  transactional: boolean;
4422
4634
  }): Promise<void>;
4635
+ /**
4636
+ * @description Extracts rows from raw query result based on database type
4637
+ * MySQL/MariaDB returns [rows, fields], Postgres returns {rows: []}, others return rows directly
4638
+ */
4639
+ private extractRowsFromRawResult;
4423
4640
  /**
4424
4641
  * @description Executes a raw query on the database and returns the raw driver result
4425
4642
  */
@@ -4539,7 +4756,7 @@ type BaseModelMethodOptions = {
4539
4756
  * port: 5432,
4540
4757
  * });
4541
4758
  *
4542
- * const user = await User.query({ connection: customConnection }).first();
4759
+ * const user = await User.query({ connection: customConnection }).one();
4543
4760
  * ```
4544
4761
  */
4545
4762
  connection?: SqlDataSource;
@@ -4612,14 +4829,6 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
4612
4829
  data: any;
4613
4830
  time: number;
4614
4831
  }>;
4615
- first: (returnType?: "millis" | "seconds") => Promise<{
4616
- data: AnnotatedModel<T, any, any> | null;
4617
- time: number;
4618
- }>;
4619
- firstOrFail: (returnType?: "millis" | "seconds") => Promise<{
4620
- data: any;
4621
- time: number;
4622
- }>;
4623
4832
  paginate: (page: number, perPage: number, returnType?: "millis" | "seconds") => Promise<{
4624
4833
  data: PaginatedData<T>;
4625
4834
  time: number;
@@ -4687,10 +4896,6 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
4687
4896
  * @description Executes the query and retrieves a single result.
4688
4897
  */
4689
4898
  one(): Promise<AnnotatedModel<T, any, any> | null>;
4690
- /**
4691
- * @alias one
4692
- */
4693
- first(): Promise<AnnotatedModel<T, any, any> | null>;
4694
4899
  /**
4695
4900
  * @description Executes the query and retrieves the first result. Fail if no result is found.
4696
4901
  */
@@ -4937,10 +5142,6 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
4937
5142
  * @description Makes a one query and returns the time that took to execute that query
4938
5143
  */
4939
5144
  private oneWithPerformance;
4940
- /**
4941
- * @alias oneWithPerformance
4942
- */
4943
- private firstWithPerformance;
4944
5145
  /**
4945
5146
  * @alias oneOrFailWithPerformance
4946
5147
  */
@@ -5111,7 +5312,7 @@ declare abstract class Model extends Entity {
5111
5312
  static dryQuery<T extends Model>(this: new () => T | typeof Model, options?: Omit<BaseModelMethodOptions, "ignoreHooks">): DryModelQueryBuilderWithoutReadOperations<T>;
5112
5313
  /**
5113
5314
  * @description Finds the first record in the database
5114
- * @deprecated Used only for debugging purposes, use findOne or query instead
5315
+ * @deprecated Used only for debugging purposes, use `.findOne` or `.query` instead
5115
5316
  */
5116
5317
  static first<T extends Model>(this: new () => T | typeof Model, options?: BaseModelMethodOptions): Promise<AnnotatedModel<T, {}> | null>;
5117
5318
  /**
@@ -5304,6 +5505,76 @@ declare abstract class Model extends Entity {
5304
5505
  * @javascript
5305
5506
  */
5306
5507
  static column(columnName: string, ...args: Parameters<typeof column>): void;
5508
+ /**
5509
+ * @description Defines a column in the model, useful in javascript in order to not have to rely on decorators since are not supported without a transpiler like babel
5510
+ * @javascript
5511
+ */
5512
+ static dateColumn(columnName: string, ...args: Parameters<(typeof column)["date"]>): void;
5513
+ /**
5514
+ * @description Defines a column in the model, useful in javascript in order to not have to rely on decorators since are not supported without a transpiler like babel
5515
+ * @javascript
5516
+ */
5517
+ static datetimeColumn(columnName: string, ...args: Parameters<(typeof column)["datetime"]>): void;
5518
+ /**
5519
+ * @description Defines a column in the model, useful in javascript in order to not have to rely on decorators since are not supported without a transpiler like babel
5520
+ * @javascript
5521
+ */
5522
+ static timestampColumn(columnName: string, ...args: Parameters<(typeof column)["timestamp"]>): void;
5523
+ /**
5524
+ * @description Defines a column in the model, useful in javascript in order to not have to rely on decorators since are not supported without a transpiler like babel
5525
+ * @javascript
5526
+ */
5527
+ static timeColumn(columnName: string, ...args: Parameters<(typeof column)["time"]>): void;
5528
+ /**
5529
+ * @description Defines a column in the model, useful in javascript in order to not have to rely on decorators since are not supported without a transpiler like babel
5530
+ * @javascript
5531
+ */
5532
+ static booleanColumn(columnName: string, ...args: Parameters<(typeof column)["boolean"]>): void;
5533
+ /**
5534
+ * @description Defines a column in the model, useful in javascript in order to not have to rely on decorators since are not supported without a transpiler like babel
5535
+ * @javascript
5536
+ */
5537
+ static jsonColumn(columnName: string, ...args: Parameters<(typeof column)["json"]>): void;
5538
+ /**
5539
+ * @description Defines a column in the model, useful in javascript in order to not have to rely on decorators since are not supported without a transpiler like babel
5540
+ * @javascript
5541
+ */
5542
+ static uuidColumn(columnName: string, ...args: Parameters<(typeof column)["uuid"]>): void;
5543
+ /**
5544
+ * @description Defines a column in the model, useful in javascript in order to not have to rely on decorators since are not supported without a transpiler like babel
5545
+ * @javascript
5546
+ */
5547
+ static ulidColumn(columnName: string, ...args: Parameters<(typeof column)["ulid"]>): void;
5548
+ /**
5549
+ * @description Defines a column in the model, useful in javascript in order to not have to rely on decorators since are not supported without a transpiler like babel
5550
+ * @javascript
5551
+ */
5552
+ static integerColumn(columnName: string, ...args: Parameters<(typeof column)["integer"]>): void;
5553
+ /**
5554
+ * @description Defines a column in the model, useful in javascript in order to not have to rely on decorators since are not supported without a transpiler like babel
5555
+ * @javascript
5556
+ */
5557
+ static floatColumn(columnName: string, ...args: Parameters<(typeof column)["float"]>): void;
5558
+ /**
5559
+ * @description Defines a column in the model, useful in javascript in order to not have to rely on decorators since are not supported without a transpiler like babel
5560
+ * @javascript
5561
+ */
5562
+ static incrementColumn(columnName: string, ...args: Parameters<(typeof column)["increment"]>): void;
5563
+ /**
5564
+ * @description Defines a column in the model, useful in javascript in order to not have to rely on decorators since are not supported without a transpiler like babel
5565
+ * @javascript
5566
+ */
5567
+ static bigIncrementColumn(columnName: string, ...args: Parameters<(typeof column)["bigIncrement"]>): void;
5568
+ /**
5569
+ * @description Defines a column in the model, useful in javascript in order to not have to rely on decorators since are not supported without a transpiler like babel
5570
+ * @javascript
5571
+ */
5572
+ static encryptionSymmetricColumn(columnName: string, ...args: Parameters<(typeof column)["encryption"]["symmetric"]>): void;
5573
+ /**
5574
+ * @description Defines a column in the model, useful in javascript in order to not have to rely on decorators since are not supported without a transpiler like babel
5575
+ * @javascript
5576
+ */
5577
+ static encryptionAsymmetricColumn(columnName: string, ...args: Parameters<(typeof column)["encryption"]["asymmetric"]>): void;
5307
5578
  /**
5308
5579
  * @description Defines an hasOne relation
5309
5580
  * @javascript
@@ -5626,39 +5897,155 @@ declare class ModelFactory<M extends Model> {
5626
5897
  }
5627
5898
  declare const createModelFactory: <M extends Model>(typeofModel: typeof Model, modelData: Partial<ModelWithoutRelations<M>>) => ModelFactory<M>;
5628
5899
 
5900
+ type Constructor<T = Model> = new (...args: any[]) => T;
5901
+ type AbstractConstructor<T = Model> = abstract new (...args: any[]) => T;
5902
+ type AnyConstructor<T = Model> = Constructor<T> | AbstractConstructor<T>;
5903
+
5904
+ interface BigIntFields {
5905
+ id: number;
5906
+ }
5629
5907
  /**
5630
- * @description Mixin to add createdAt, updatedAt and deletedAt columns to a model
5908
+ * Mixin to add a bigint primary key column with auto-increment.
5909
+ * Uses bigint database type but TypeScript number type.
5910
+ *
5911
+ * @example
5912
+ * ```ts
5913
+ * class User extends bigIntMixin() {
5914
+ * declare name: string;
5915
+ * }
5916
+ *
5917
+ * // Composable with other mixins
5918
+ * class Post extends timestampMixin(bigIntMixin()) {}
5919
+ * ```
5631
5920
  */
5632
- declare class TimestampedModel extends Model {
5633
- createdAt: Date;
5634
- updatedAt: Date;
5635
- deletedAt: Date | null;
5636
- }
5921
+ declare function bigIntMixin(): typeof Model & Constructor<BigIntFields>;
5922
+ declare function bigIntMixin<TBase extends AnyConstructor>(Base: TBase): TBase & Constructor<BigIntFields>;
5923
+ declare const BigIntMixin: typeof bigIntMixin;
5637
5924
 
5925
+ interface IncrementFields {
5926
+ id: number;
5927
+ }
5638
5928
  /**
5639
- * @description Mixin to add a uuid column to a model
5929
+ * Mixin to add an auto-incrementing integer primary key column.
5930
+ *
5931
+ * @example
5932
+ * ```ts
5933
+ * class User extends incrementMixin() {
5934
+ * declare name: string;
5935
+ * }
5936
+ *
5937
+ * // Composable with other mixins
5938
+ * class Post extends timestampMixin(incrementMixin()) {}
5939
+ * ```
5640
5940
  */
5641
- declare class UuidModel extends Model {
5941
+ declare function incrementMixin(): typeof Model & Constructor<IncrementFields>;
5942
+ declare function incrementMixin<TBase extends AnyConstructor>(Base: TBase): TBase & Constructor<IncrementFields>;
5943
+ declare const IncrementMixin: typeof incrementMixin;
5944
+
5945
+ interface UlidFields {
5642
5946
  id: string;
5643
5947
  }
5644
-
5645
5948
  /**
5646
- * @description Mixin to add an autogenerated id column to a model
5949
+ * Mixin to add a ULID primary key column.
5950
+ * ULID = Universally Unique Lexicographically Sortable Identifier.
5951
+ * Automatically generates ULID if not provided.
5952
+ *
5953
+ * @example
5954
+ * ```ts
5955
+ * class User extends ulidMixin() {
5956
+ * declare name: string;
5957
+ * }
5958
+ *
5959
+ * // Composable with other mixins
5960
+ * class Post extends timestampMixin(ulidMixin()) {}
5961
+ * ```
5647
5962
  */
5648
- declare class AutogeneratedModel extends Model {
5649
- id: BigInt;
5650
- }
5963
+ declare function ulidMixin(): typeof Model & Constructor<UlidFields>;
5964
+ declare function ulidMixin<TBase extends AnyConstructor>(Base: TBase): TBase & Constructor<UlidFields>;
5965
+ declare const UlidMixin: typeof ulidMixin;
5651
5966
 
5967
+ interface UuidFields {
5968
+ id: string;
5969
+ }
5652
5970
  /**
5653
- * @description Mixin to add a user model with id, email, createdAt, updatedAt and deletedAt columns
5971
+ * Mixin to add a UUID primary key column.
5972
+ * Automatically generates UUID if not provided.
5973
+ *
5974
+ * @example
5975
+ * ```ts
5976
+ * class User extends uuidMixin() {
5977
+ * declare name: string;
5978
+ * }
5979
+ *
5980
+ * // Composable with other mixins
5981
+ * class Post extends timestampMixin(uuidMixin()) {}
5982
+ * ```
5654
5983
  */
5655
- declare class UserMixin extends Model {
5656
- id: BigInt;
5657
- email: string;
5984
+ declare function uuidMixin(): typeof Model & Constructor<UuidFields>;
5985
+ declare function uuidMixin<TBase extends AnyConstructor>(Base: TBase): TBase & Constructor<UuidFields>;
5986
+ declare const UuidMixin: typeof uuidMixin;
5987
+
5988
+ interface TimestampFields {
5658
5989
  createdAt: Date;
5659
5990
  updatedAt: Date;
5660
5991
  deletedAt: Date | null;
5661
5992
  }
5993
+ /**
5994
+ * Mixin to add timestamp columns for tracking record creation and updates.
5995
+ * Adds createdAt, updatedAt, and deletedAt columns.
5996
+ * - createdAt: Auto-set on record creation
5997
+ * - updatedAt: Auto-set on creation and updates
5998
+ * - deletedAt: Nullable, for soft deletes
5999
+ *
6000
+ * @example
6001
+ * ```ts
6002
+ * class User extends timestampMixin() {
6003
+ * declare name: string;
6004
+ * }
6005
+ *
6006
+ * // Composable with other mixins
6007
+ * class Post extends timestampMixin(uuidMixin()) {}
6008
+ * ```
6009
+ */
6010
+ declare function timestampMixin(): typeof Model & Constructor<TimestampFields>;
6011
+ declare function timestampMixin<TBase extends AnyConstructor>(Base: TBase): TBase & Constructor<TimestampFields>;
6012
+ declare const TimestampMixin: typeof timestampMixin;
6013
+
6014
+ /**
6015
+ * Column definitions map for the mixin factory.
6016
+ * Keys are property names, values are ColumnOptions.
6017
+ */
6018
+ type MixinColumns<TFields> = {
6019
+ [K in keyof TFields]: ColumnOptions;
6020
+ };
6021
+ /**
6022
+ * Creates a custom mixin function with the specified columns.
6023
+ *
6024
+ * @example
6025
+ * ```ts
6026
+ * interface AuditFields {
6027
+ * createdBy: string | null;
6028
+ * updatedBy: string | null;
6029
+ * }
6030
+ *
6031
+ * const auditMixin = createMixin<AuditFields>({
6032
+ * createdBy: { nullable: true },
6033
+ * updatedBy: { nullable: true },
6034
+ * });
6035
+ *
6036
+ * class User extends auditMixin(timestampMixin(uuidMixin())) {
6037
+ * static table = 'users';
6038
+ * }
6039
+ * ```
6040
+ */
6041
+ declare const createMixin: <TFields>(columns: MixinColumns<TFields>) => {
6042
+ (): typeof Model & Constructor<TFields>;
6043
+ <TBase extends AnyConstructor>(base: TBase): TBase & Constructor<TFields>;
6044
+ };
6045
+ declare const MixinFactory: <TFields>(columns: MixinColumns<TFields>) => {
6046
+ (): typeof Model & Constructor<TFields>;
6047
+ <TBase extends AnyConstructor>(base: TBase): TBase & Constructor<TFields>;
6048
+ };
5662
6049
 
5663
6050
  declare class InMemoryAdapter implements CacheAdapter {
5664
6051
  get<T = void>(key: string): Promise<T>;
@@ -6523,4 +6910,4 @@ declare const generateOpenApiModelWithMetadata: <T extends new () => Model>(mode
6523
6910
  $id?: string;
6524
6911
  }>;
6525
6912
 
6526
- export { type AdminJsActionOptions, type AdminJsAssets, type AdminJsBranding, type AdminJsInstance, type AdminJsLocale, type AdminJsOptions, type AdminJsPage, type AdminJsPropertyOptions, type AdminJsResourceOptions, type AdminJsSettings, type AnnotatedModel, type AsymmetricEncryptionOptions, AutogeneratedModel, type BaseModelMethodOptions, type BaseModelRelationType, BaseSeeder, type CacheAdapter, type CacheKeys, ClientMigrator, Collection, type ColumnDataTypeOption, type ColumnDataTypeOptionSimple, type ColumnDataTypeOptionWithBinary, type ColumnDataTypeOptionWithDatePrecision, type ColumnDataTypeOptionWithEnum, type ColumnDataTypeOptionWithLength, type ColumnDataTypeOptionWithPrecision, type ColumnDataTypeOptionWithScaleAndPrecision, type ColumnDataTypeOptionWithText, type ColumnOptions, type ColumnType, type CommonDataSourceInput, type CommonSqlMethodReturnType, type ConnectionPolicies, type DataSourceInput, type DataSourceType, type DateColumnOptions, DryModelQueryBuilder, DryQueryBuilder, type FetchHooks, type GetConnectionReturnType, HysteriaError, InMemoryAdapter, type IndexType, type LazyRelationType, type ManyOptions, type ManyToManyOptions, type ManyToManyStringOptions, Migration, type MigrationConfig, type MigrationConfigBase, Model, type ModelInstanceType, ModelQueryBuilder, type ModelWithoutRelations, MongoDataSource, type MongoDataSourceInput$1 as MongoDataSourceInput, type MssqlConnectionInstance, type MssqlDataSourceInput, type MssqlPoolInstance, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullableOracleDBDataSourceInput, type NotNullableOracleMssqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NumberModelKey, type OneOptions, type OracleDBDataSourceInput, type OracleDBPoolInstance, type PgPoolClientInstance, type PostgresSqlDataSourceInput, QueryBuilder, type RawModelOptions, RawNode, type RawQueryOptions, RedisCacheAdapter, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationQueryBuilderType, type ReplicationType, type SeederConfig, type SlaveAlgorithm, type SlaveContext, type SqlCloneOptions, SqlDataSource, type SqlDataSourceInput, type SqlDataSourceModel, type SqlDataSourceType, type SqlDriverSpecificOptions, type SqlPoolType, type Sqlite3ConnectionOptions, type SqliteConnectionInstance, type SqliteDataSourceInput, type StartTransactionOptions, type SymmetricEncryptionOptions, type TableFormat, type ThroughModel, TimestampedModel, Transaction, type TransactionExecutionOptions, type UniqueType, type UseCacheReturnType, type UseConnectionInput, UserMixin, UuidModel, belongsTo, column, createModelFactory, defineMigrator, generateOpenApiModel, generateOpenApiModelSchema, generateOpenApiModelWithMetadata, getCollectionProperties, getIndexes, getModelColumns, type getPoolReturnType, getPrimaryKey, getRelations, getRelationsMetadata, getUniques, hasMany, hasOne, index, HysteriaLogger as logger, manyToMany, property, RedisDataSource as redis, unique, view, withPerformance };
6913
+ export { type AbstractConstructor, type AdminJsActionOptions, type AdminJsAssets, type AdminJsBranding, type AdminJsInstance, type AdminJsLocale, type AdminJsOptions, type AdminJsPage, type AdminJsPropertyOptions, type AdminJsResourceOptions, type AdminJsSettings, type AnnotatedModel, type AnyConstructor, type AsymmetricEncryptionOptions, type BaseModelMethodOptions, type BaseModelRelationType, BaseSeeder, type BigIntFields, BigIntMixin, type CacheAdapter, type CacheKeys, ClientMigrator, Collection, type ColumnDataTypeOption, type ColumnDataTypeOptionSimple, type ColumnDataTypeOptionWithBinary, type ColumnDataTypeOptionWithDatePrecision, type ColumnDataTypeOptionWithEnum, type ColumnDataTypeOptionWithLength, type ColumnDataTypeOptionWithPrecision, type ColumnDataTypeOptionWithScaleAndPrecision, type ColumnDataTypeOptionWithText, type ColumnOptions, type ColumnType, type CommonDataSourceInput, type CommonSqlMethodReturnType, type ConnectionPolicies, type Constructor, type DataSourceInput, type DataSourceType, type DateColumnOptions, DryModelQueryBuilder, DryQueryBuilder, type FetchHooks, type GetConnectionReturnType, HysteriaError, InMemoryAdapter, type IncrementFields, IncrementMixin, type IndexType, type LazyRelationType, type ManyOptions, type ManyToManyOptions, type ManyToManyStringOptions, Migration, type MigrationConfig, type MigrationConfigBase, type MixinColumns, MixinFactory, Model, type ModelInstanceType, ModelQueryBuilder, type ModelWithoutRelations, MongoDataSource, type MongoDataSourceInput$1 as MongoDataSourceInput, type MssqlConnectionInstance, type MssqlDataSourceInput, type MssqlPoolInstance, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullableOracleDBDataSourceInput, type NotNullableOracleMssqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NumberModelKey, type OneOptions, type OracleDBDataSourceInput, type OracleDBPoolInstance, type PgPoolClientInstance, type PostgresSqlDataSourceInput, QueryBuilder, type RawModelOptions, RawNode, type RawQueryOptions, RedisCacheAdapter, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationQueryBuilderType, type ReplicationType, type SeederConfig, type SlaveAlgorithm, type SlaveContext, type SqlCloneOptions, SqlDataSource, type SqlDataSourceInput, type SqlDataSourceModel, type SqlDataSourceType, type SqlDriverSpecificOptions, type SqlPoolType, type Sqlite3ConnectionOptions, type SqliteConnectionInstance, type SqliteDataSourceInput, type StartTransactionOptions, type SymmetricEncryptionOptions, type TableFormat, type ThroughModel, type TimestampFields, TimestampMixin, Transaction, type TransactionExecutionOptions, type UlidFields, UlidMixin, type UniqueType, type UseCacheReturnType, type UseConnectionInput, type UuidFields, UuidMixin, belongsTo, bigIntMixin, column, createMixin, createModelFactory, defineMigrator, generateOpenApiModel, generateOpenApiModelSchema, generateOpenApiModelWithMetadata, getCollectionProperties, getIndexes, getModelColumns, type getPoolReturnType, getPrimaryKey, getRelations, getRelationsMetadata, getUniques, hasMany, hasOne, incrementMixin, index, HysteriaLogger as logger, manyToMany, property, RedisDataSource as redis, timestampMixin, ulidMixin, unique, uuidMixin, view, withPerformance };