hysteria-orm 10.4.4 → 10.4.6

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.ts 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> {
@@ -3418,6 +3653,16 @@ type UpdateOptions = {
3418
3653
  */
3419
3654
  type RelationQueryBuilderType<T extends Model, A extends Record<string, any> = {}, R extends Record<string, any> = {}> = Omit<ModelQueryBuilder<T, A, R>, "increment" | "decrement" | "first" | "firstOrFail" | "paginate" | "pluck" | "truncate" | "many" | "one" | "oneOrFail" | "insert" | "insertMany" | "update" | "delete" | "softDelete" | "getSum" | "getAvg" | "getMin" | "getMax" | "getCount" | "getMin" | "getMax" | "getCount">;
3420
3655
 
3656
+ /**
3657
+ * Helper type to determine if annotation overrides model field or goes to $annotations
3658
+ * If K is a key of the model T, it overrides that field in the model.
3659
+ * Otherwise, it goes into the annotations object A.
3660
+ */
3661
+ type AnnotationResult<T extends Model, A extends Record<string, any>, R extends Record<string, any>, K extends string, V> = K extends keyof T ? ModelQueryBuilder<T & {
3662
+ [P in K]: V;
3663
+ }, A, R> : ModelQueryBuilder<T, A & {
3664
+ [P in K]: V;
3665
+ }, R>;
3421
3666
  declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> = {}, R extends Record<string, any> = {}> extends QueryBuilder<T> {
3422
3667
  relation: Relation;
3423
3668
  protected sqlModelManagerUtils: SqlModelManagerUtils<T>;
@@ -3512,11 +3757,11 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
3512
3757
  /**
3513
3758
  * @description Inserts a new record into the database, it is not advised to use this method directly from the query builder if using a ModelQueryBuilder (`Model.query()`), use the `Model.insert` method instead.
3514
3759
  */
3515
- insert(...args: Parameters<typeof this$1.model.insert>): ReturnType<typeof this$1.model.insert>;
3760
+ insert(...args: Parameters<typeof this$1.model.insert<T>>): ReturnType<typeof this$1.model.insert>;
3516
3761
  /**
3517
3762
  * @description Inserts multiple records into the database, it is not advised to use this method directly from the query builder if using a ModelQueryBuilder (`Model.query()`), use the `Model.insertMany` method instead.
3518
3763
  */
3519
- insertMany(...args: Parameters<typeof this$1.model.insertMany>): ReturnType<typeof this$1.model.insertMany>;
3764
+ insertMany(...args: Parameters<typeof this$1.model.insertMany<T>>): ReturnType<typeof this$1.model.insertMany>;
3520
3765
  update(data: Partial<ModelWithoutRelations<T>>, options?: UpdateOptions): Promise<number>;
3521
3766
  softDelete(options?: SoftDeleteOptions<T>): Promise<number>;
3522
3767
  delete(options?: DeleteOptions): Promise<number>;
@@ -3542,32 +3787,26 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
3542
3787
  select(...columns: (ModelKey<T> | "*")[]): this;
3543
3788
  /**
3544
3789
  * @description Annotates a column with a SQL method or a simple alias
3545
- * @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
3790
+ * @description If the alias matches a model field name, it overrides that field. Otherwise, it's available in $annotations
3546
3791
  * @example
3547
3792
  * ```ts
3548
3793
  * const user = await User.query().annotate("max", "id", "maxId").first(); // max(id) as maxId
3549
3794
  * const user = await User.query().annotate("id", "superId").first(); // id as superId
3795
+ * // If alias matches model field, it overrides it:
3796
+ * const user = await User.query().annotate("COUNT(*)", "email").first(); // user.email is now a number
3550
3797
  * ```
3551
3798
  */
3552
- annotate<K extends string, V = any>(column: string, alias: K): ModelQueryBuilder<T, A & {
3553
- [P in K]: V;
3554
- }, R>;
3555
- annotate<K extends string, S extends SqlMethod, V = CommonSqlMethodReturnType<S>>(sqlMethod: string, column: string, alias: K): ModelQueryBuilder<T, A & {
3556
- [P in K]: V;
3557
- }, R>;
3558
- annotate<K extends string, S extends SqlMethod, V = CommonSqlMethodReturnType<S>>(sqlMethod: S, column: string, alias: K): ModelQueryBuilder<T, A & {
3559
- [P in K]: V;
3560
- }, R>;
3561
- annotate<K extends string, S extends SqlMethod, V = CommonSqlMethodReturnType<S>>(sqlMethod: S, column: string, alias: K): ModelQueryBuilder<T, A & {
3562
- [P in K]: V;
3563
- }, R>;
3799
+ annotate<K extends string, V = any>(column: string, alias: K): AnnotationResult<T, A, R, K, V>;
3800
+ annotate<K extends string, S extends SqlMethod, V = CommonSqlMethodReturnType<S>>(sqlMethod: string, column: string, alias: K): AnnotationResult<T, A, R, K, V>;
3801
+ annotate<K extends string, S extends SqlMethod, V = CommonSqlMethodReturnType<S>>(sqlMethod: S, column: string, alias: K): AnnotationResult<T, A, R, K, V>;
3802
+ annotate<K extends string, S extends SqlMethod, V = CommonSqlMethodReturnType<S>>(sqlMethod: S, column: string, alias: K): AnnotationResult<T, A, R, K, V>;
3564
3803
  /**
3565
3804
  * @description Selects a JSON value at the specified path and returns it as JSON
3566
3805
  * @param column The column containing JSON data
3567
3806
  * @param path The JSON path to extract (standardized format: "$.user.name", "user.name", or ["user", "name"])
3568
3807
  * @param alias The alias for the selected value
3569
3808
  * @description Path format is standardized across all databases - ORM converts to DB-specific syntax
3570
- * @description Result will be available in model.$annotations[alias]
3809
+ * @description If alias matches a model field, it overrides that field. Otherwise, it's in $annotations
3571
3810
  * @example
3572
3811
  * ```ts
3573
3812
  * // All these path formats are supported:
@@ -3590,24 +3829,24 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
3590
3829
  * // 6. Root object
3591
3830
  * await User.query().selectJson("data", "$", "allData").first();
3592
3831
  *
3593
- * // Access the result
3832
+ * // Access the result - in $annotations if not a model field
3594
3833
  * const user = await User.query().selectJson("data", "user.name", "userName").first();
3595
3834
  * console.log(user?.$annotations?.userName); // Typed as any
3835
+ *
3836
+ * // If alias matches model field, it overrides it
3837
+ * const user2 = await User.query().selectJson("data", "$.name", "email").first();
3838
+ * console.log(user2?.email); // Overrides model's email field
3596
3839
  * ```
3597
3840
  */
3598
- selectJson<K extends string>(column: ModelKey<T>, path: JsonPathInput, alias: K): ModelQueryBuilder<T, A & {
3599
- [P in K]: any;
3600
- }, R>;
3601
- selectJson<K extends string>(column: string, path: JsonPathInput, alias: K): ModelQueryBuilder<T, A & {
3602
- [P in K]: any;
3603
- }, R>;
3841
+ selectJson<K extends string>(column: ModelKey<T>, path: JsonPathInput, alias: K): AnnotationResult<T, A, R, K, any>;
3842
+ selectJson<K extends string>(column: string, path: JsonPathInput, alias: K): AnnotationResult<T, A, R, K, any>;
3604
3843
  /**
3605
3844
  * @description Selects a JSON value at the specified path and returns it as text
3606
3845
  * @param column The column containing JSON data
3607
3846
  * @param path The JSON path to extract (standardized format)
3608
3847
  * @param alias The alias for the selected value
3609
3848
  * @description Path format is standardized across all databases - ORM converts to DB-specific syntax
3610
- * @description Result will be available in model.$annotations[alias]
3849
+ * @description If alias matches a model field, it overrides that field. Otherwise, it's in $annotations
3611
3850
  * @example
3612
3851
  * ```ts
3613
3852
  * // All these path formats are supported:
@@ -3628,24 +3867,20 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
3628
3867
  * // 5. Deep nesting
3629
3868
  * await User.query().selectJsonText("data", "user.profile.bio", "biography").first();
3630
3869
  *
3631
- * // Access the result
3632
- * const user = await User.query().selectJsonText("data", "user.email", "email").first();
3633
- * console.log(user?.$annotations?.email); // Typed as string
3870
+ * // Access the result - in $annotations if not a model field
3871
+ * const user = await User.query().selectJsonText("data", "user.email", "userEmail").first();
3872
+ * console.log(user?.$annotations?.userEmail); // Typed as string
3634
3873
  * ```
3635
3874
  */
3636
- selectJsonText<K extends string>(column: ModelKey<T>, path: any, alias: K): ModelQueryBuilder<T, A & {
3637
- [P in K]: string;
3638
- }, R>;
3639
- selectJsonText<K extends string>(column: string, path: any, alias: K): ModelQueryBuilder<T, A & {
3640
- [P in K]: string;
3641
- }, R>;
3875
+ selectJsonText<K extends string>(column: ModelKey<T>, path: JsonPathInput, alias: K): AnnotationResult<T, A, R, K, string>;
3876
+ selectJsonText<K extends string>(column: string, path: JsonPathInput, alias: K): AnnotationResult<T, A, R, K, string>;
3642
3877
  /**
3643
3878
  * @description Selects the length of a JSON array
3644
3879
  * @param column The column containing JSON array data
3645
3880
  * @param path The JSON path to the array (standardized format, use "$" or "" for root)
3646
3881
  * @param alias The alias for the length value
3647
3882
  * @description Path format is standardized across all databases - ORM converts to DB-specific syntax
3648
- * @description Result will be available in model.$annotations[alias]
3883
+ * @description If alias matches a model field, it overrides that field. Otherwise, it's in $annotations
3649
3884
  * @warning Not supported in SQLite
3650
3885
  * @example
3651
3886
  * ```ts
@@ -3671,24 +3906,20 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
3671
3906
  * // 6. Deeply nested arrays
3672
3907
  * await User.query().selectJsonArrayLength("data", "level1.level2.items", "deepCount").first();
3673
3908
  *
3674
- * // Access the result
3909
+ * // Access the result - in $annotations if not a model field
3675
3910
  * const user = await User.query().selectJsonArrayLength("data", "items", "count").first();
3676
3911
  * console.log(user?.$annotations?.count); // Typed as number
3677
3912
  * ```
3678
3913
  */
3679
- selectJsonArrayLength<K extends string>(column: ModelKey<T>, path: JsonPathInput, alias: K): ModelQueryBuilder<T, A & {
3680
- [P in K]: number;
3681
- }, R>;
3682
- selectJsonArrayLength<K extends string>(column: string, path: JsonPathInput, alias: K): ModelQueryBuilder<T, A & {
3683
- [P in K]: number;
3684
- }, R>;
3914
+ selectJsonArrayLength<K extends string>(column: ModelKey<T>, path: JsonPathInput, alias: K): AnnotationResult<T, A, R, K, number>;
3915
+ selectJsonArrayLength<K extends string>(column: string, path: JsonPathInput, alias: K): AnnotationResult<T, A, R, K, number>;
3685
3916
  /**
3686
3917
  * @description Selects the keys of a JSON object
3687
3918
  * @param column The column containing JSON object data
3688
3919
  * @param path The JSON path to the object (standardized format, use "$" or "" for root)
3689
3920
  * @param alias The alias for the keys
3690
3921
  * @description Path format is standardized across all databases - ORM converts to DB-specific syntax
3691
- * @description Result will be available in model.$annotations[alias]
3922
+ * @description If alias matches a model field, it overrides that field. Otherwise, it's in $annotations
3692
3923
  * @warning Not supported in SQLite or MSSQL
3693
3924
  * @postgresql Returns a native array of keys
3694
3925
  * @mysql Returns a JSON array of keys
@@ -3716,22 +3947,18 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
3716
3947
  * // 6. Deeply nested objects
3717
3948
  * await User.query().selectJsonKeys("data", "settings.display.theme", "themeKeys").first();
3718
3949
  *
3719
- * // Access the result
3950
+ * // Access the result - in $annotations if not a model field
3720
3951
  * const user = await User.query().selectJsonKeys("data", "settings", "keys").first();
3721
3952
  * console.log(user?.$annotations?.keys); // Typed as any[] - ["theme", "fontSize", "autoSave"]
3722
3953
  * ```
3723
3954
  */
3724
- selectJsonKeys<K extends string>(column: ModelKey<T>, path: JsonPathInput, alias: K): ModelQueryBuilder<T, A & {
3725
- [P in K]: any[];
3726
- }, R>;
3727
- selectJsonKeys<K extends string>(column: string, path: JsonPathInput, alias: K): ModelQueryBuilder<T, A & {
3728
- [P in K]: any[];
3729
- }, R>;
3955
+ selectJsonKeys<K extends string>(column: ModelKey<T>, path: JsonPathInput, alias: K): AnnotationResult<T, A, R, K, any[]>;
3956
+ selectJsonKeys<K extends string>(column: string, path: JsonPathInput, alias: K): AnnotationResult<T, A, R, K, any[]>;
3730
3957
  /**
3731
3958
  * @description Adds a raw JSON select expression for database-specific operations
3732
3959
  * @param raw The raw SQL expression (database-specific syntax)
3733
3960
  * @param alias The alias for the selected value
3734
- * @description Result will be available in model.$annotations[alias]
3961
+ * @description If alias matches a model field, it overrides that field. Otherwise, it's in $annotations
3735
3962
  * @description Use this for advanced JSON operations not covered by other selectJson* methods
3736
3963
  * @warning This bypasses path standardization - you must write database-specific SQL
3737
3964
  * @example
@@ -3757,14 +3984,12 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
3757
3984
  * // SQLite - Extract value with json_extract
3758
3985
  * await User.query().selectJsonRaw("json_extract(data, '$.email')", "userEmail").first();
3759
3986
  *
3760
- * // Access the result
3761
- * const user = await User.query().selectJsonRaw("data->>'email'", "email").first();
3762
- * console.log(user?.$annotations?.email); // Typed as any
3987
+ * // Access the result - in $annotations if not a model field
3988
+ * const user = await User.query().selectJsonRaw("data->>'email'", "userEmail").first();
3989
+ * console.log(user?.$annotations?.userEmail); // Typed as any
3763
3990
  * ```
3764
3991
  */
3765
- selectJsonRaw<K extends string>(raw: string, alias: K): ModelQueryBuilder<T, A & {
3766
- [P in K]: any;
3767
- }, R>;
3992
+ selectJsonRaw<K extends string>(raw: string, alias: K): AnnotationResult<T, A, R, K, any>;
3768
3993
  /**
3769
3994
  * @description Removes annotations from the serialized model, by default, annotations are maintained in the serialized model if `annotate` is used
3770
3995
  */
@@ -4529,7 +4754,7 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
4529
4754
  private connectWithoutSettingPrimary;
4530
4755
  }
4531
4756
 
4532
- type ModelWithoutRelations<T extends Model> = Pick<T, ExcludeRelations<Omit<T, "*">>>;
4757
+ type ModelWithoutRelations<T extends Model> = Pick<Omit<T, "*">, ExcludeRelations<Omit<T, "*">>> & Pick<Model, keyof Model>;
4533
4758
  type NumberModelKey<T extends Model> = {
4534
4759
  [K in keyof T]: T[K] extends number | bigint ? K : never;
4535
4760
  }[keyof T];
@@ -5376,6 +5601,12 @@ declare abstract class Model extends Entity {
5376
5601
  * @throws {HysteriaError} If the model has no primary key valorized in the instance
5377
5602
  */
5378
5603
  refresh<T extends Model = this>(options?: Omit<BaseModelMethodOptions, "ignoreHooks">): Promise<T>;
5604
+ /**
5605
+ * @description Converts the model to a JSON object
5606
+ * @description Flattens all `$annotations` into the JSON object at first level including the relations
5607
+ * @warning Use with caution, this method flattens the `$annotations` into the JSON object at first level including the relations, so if you have conflicting column names between model columns and annotations, the annotation could override the model column value
5608
+ */
5609
+ toJSON(): Record<string, any>;
5379
5610
  }
5380
5611
 
5381
5612
  type BaseModelRelationType = {