hysteria-orm 10.4.3 → 10.4.4

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
@@ -2279,6 +2279,8 @@ declare class WhereGroupNode extends QueryNode {
2279
2279
  constructor(nodes: (WhereNode | WhereGroupNode | WhereSubqueryNode)[], chainsWith?: "and" | "or");
2280
2280
  }
2281
2281
 
2282
+ type JsonPathInput = string | (string | number)[];
2283
+
2282
2284
  declare class DistinctNode extends QueryNode {
2283
2285
  chainsWith: string;
2284
2286
  canKeywordBeSeenMultipleTimes: boolean;
@@ -2786,9 +2788,9 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
2786
2788
  * const user = await User.query().annotate("id", "superId").first(); // id as superId
2787
2789
  * ```
2788
2790
  */
2789
- annotate(column: string, alias: string): this;
2790
- annotate(sqlMethod: SqlMethod, column: string, alias: string): this;
2791
- annotate(sqlMethod: string, column: string, alias: string): this;
2791
+ annotate<A extends string>(column: string, alias: A): this;
2792
+ annotate<A extends string>(sqlMethod: SqlMethod, column: string, alias: A): this;
2793
+ annotate<A extends string>(sqlMethod: string, column: string, alias: A): this;
2792
2794
  /**
2793
2795
  * @description Sets the table to select from, by default is the table defined in the Model
2794
2796
  * @description Can be used on non select queries too, it will only specify the table name (es. INSERT INTO $table)
@@ -2812,6 +2814,99 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
2812
2814
  */
2813
2815
  distinctOn(...columns: ModelKey<T>[]): this;
2814
2816
  distinctOn<S extends string>(...columns: SelectableColumn<S>[]): this;
2817
+ /**
2818
+ * @description Selects a JSON value at the specified path and returns it as JSON
2819
+ * @param column The column containing JSON data
2820
+ * @param path The JSON path to extract (standardized format: "$.user.name", "user.name", or ["user", "name"])
2821
+ * @param alias The alias for the selected value
2822
+ * @description Path format is standardized across all databases - ORM converts to DB-specific syntax
2823
+ * @description Result will be available in model.$annotations[alias]
2824
+ * @example
2825
+ * ```ts
2826
+ * // All databases accept the same path format:
2827
+ * const user = await User.query().selectJson("data", "$.user.name", "userName").first();
2828
+ * console.log(user?.$annotations?.userName); // Typed!
2829
+ *
2830
+ * await User.query().selectJson("data", "user.name", "userName").first(); // $ is optional
2831
+ * await User.query().selectJson("data", ["user", "name"], "userName").first();
2832
+ *
2833
+ * // Array indices:
2834
+ * await User.query().selectJson("data", "items.0.name", "firstItemName").first();
2835
+ * await User.query().selectJson("data", ["items", 0, "name"], "firstItemName").first();
2836
+ * ```
2837
+ */
2838
+ selectJson<A extends string>(column: ModelKey<T>, path: JsonPathInput, alias: A): this;
2839
+ selectJson<A extends string>(column: string, path: JsonPathInput, alias: A): this;
2840
+ /**
2841
+ * @description Selects a JSON value at the specified path and returns it as text
2842
+ * @param column The column containing JSON data
2843
+ * @param path The JSON path to extract (standardized format)
2844
+ * @param alias The alias for the selected value
2845
+ * @description Path format is standardized across all databases - ORM converts to DB-specific syntax
2846
+ * @description Result will be available in model.$annotations[alias]
2847
+ * @example
2848
+ * ```ts
2849
+ * // All databases accept the same path format:
2850
+ * const user = await User.query().selectJsonText("data", "$.user.name", "userName").first();
2851
+ * console.log(user?.$annotations?.userName); // Typed!
2852
+ *
2853
+ * await User.query().selectJsonText("data", ["user", "name"], "userName").first();
2854
+ * ```
2855
+ */
2856
+ selectJsonText<A extends string>(column: ModelKey<T>, path: JsonPathInput, alias: A): this;
2857
+ selectJsonText<A extends string>(column: string, path: JsonPathInput, alias: A): this;
2858
+ /**
2859
+ * @description Selects the length of a JSON array
2860
+ * @param column The column containing JSON array data
2861
+ * @param path The JSON path to the array (standardized format, use "$" or "" for root)
2862
+ * @param alias The alias for the length value
2863
+ * @description Path format is standardized across all databases - ORM converts to DB-specific syntax
2864
+ * @description Result will be available in model.$annotations[alias]
2865
+ * @example
2866
+ * ```ts
2867
+ * // All databases accept the same path format:
2868
+ * const user = await User.query().selectJsonArrayLength("data", "$.items", "itemCount").first();
2869
+ * console.log(user?.$annotations?.itemCount); // Typed!
2870
+ *
2871
+ * await User.query().selectJsonArrayLength("data", "items", "itemCount").first();
2872
+ * await User.query().selectJsonArrayLength("data", "$", "totalCount").first(); // root array
2873
+ * ```
2874
+ */
2875
+ selectJsonArrayLength<A extends string>(column: ModelKey<T>, path: JsonPathInput, alias: A): this;
2876
+ selectJsonArrayLength<A extends string>(column: string, path: JsonPathInput, alias: A): this;
2877
+ /**
2878
+ * @description Selects the keys of a JSON object
2879
+ * @param column The column containing JSON object data
2880
+ * @param path The JSON path to the object (standardized format, use "$" or "" for root)
2881
+ * @param alias The alias for the keys
2882
+ * @description Path format is standardized across all databases - ORM converts to DB-specific syntax
2883
+ * @description Result will be available in model.$annotations[alias]
2884
+ * @postgres Returns an array of keys
2885
+ * @mysql Returns a JSON array of keys
2886
+ * @example
2887
+ * ```ts
2888
+ * // All databases accept the same path format:
2889
+ * const user = await User.query().selectJsonKeys("data", "$.user", "userKeys").first();
2890
+ * console.log(user?.$annotations?.userKeys); // Typed!
2891
+ *
2892
+ * await User.query().selectJsonKeys("data", "user", "userKeys").first();
2893
+ * await User.query().selectJsonKeys("data", "$", "rootKeys").first(); // root object
2894
+ * ```
2895
+ */
2896
+ selectJsonKeys<A extends string>(column: ModelKey<T>, path: JsonPathInput, alias: A): this;
2897
+ selectJsonKeys<A extends string>(column: string, path: JsonPathInput, alias: A): this;
2898
+ /**
2899
+ * @description Adds a raw JSON select expression
2900
+ * @param raw The raw SQL expression
2901
+ * @param alias The alias for the selected value
2902
+ * @description Result will be available in model.$annotations[alias]
2903
+ * @example
2904
+ * ```ts
2905
+ * const user = await User.query().selectJsonRaw("data->>'email'", "userEmail").first();
2906
+ * console.log(user?.$annotations?.userEmail); // Typed!
2907
+ * ```
2908
+ */
2909
+ selectJsonRaw<A extends string>(raw: string, alias: A): this;
2815
2910
  }
2816
2911
 
2817
2912
  declare abstract class WhereQueryBuilder<T extends Model> extends SelectQueryBuilder<T> {
@@ -3466,6 +3561,210 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
3466
3561
  annotate<K extends string, S extends SqlMethod, V = CommonSqlMethodReturnType<S>>(sqlMethod: S, column: string, alias: K): ModelQueryBuilder<T, A & {
3467
3562
  [P in K]: V;
3468
3563
  }, R>;
3564
+ /**
3565
+ * @description Selects a JSON value at the specified path and returns it as JSON
3566
+ * @param column The column containing JSON data
3567
+ * @param path The JSON path to extract (standardized format: "$.user.name", "user.name", or ["user", "name"])
3568
+ * @param alias The alias for the selected value
3569
+ * @description Path format is standardized across all databases - ORM converts to DB-specific syntax
3570
+ * @description Result will be available in model.$annotations[alias]
3571
+ * @example
3572
+ * ```ts
3573
+ * // All these path formats are supported:
3574
+ *
3575
+ * // 1. With $ prefix (standard JSON path)
3576
+ * await User.query().selectJson("data", "$.user.name", "userName").first();
3577
+ *
3578
+ * // 2. Without $ prefix ($ is optional)
3579
+ * await User.query().selectJson("data", "user.name", "userName").first();
3580
+ *
3581
+ * // 3. Array format
3582
+ * await User.query().selectJson("data", ["user", "name"], "userName").first();
3583
+ *
3584
+ * // 4. Array indices with dot notation
3585
+ * await User.query().selectJson("data", "items.0.name", "firstItemName").first();
3586
+ *
3587
+ * // 5. Array indices with array format
3588
+ * await User.query().selectJson("data", ["items", 0, "name"], "firstItemName").first();
3589
+ *
3590
+ * // 6. Root object
3591
+ * await User.query().selectJson("data", "$", "allData").first();
3592
+ *
3593
+ * // Access the result
3594
+ * const user = await User.query().selectJson("data", "user.name", "userName").first();
3595
+ * console.log(user?.$annotations?.userName); // Typed as any
3596
+ * ```
3597
+ */
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>;
3604
+ /**
3605
+ * @description Selects a JSON value at the specified path and returns it as text
3606
+ * @param column The column containing JSON data
3607
+ * @param path The JSON path to extract (standardized format)
3608
+ * @param alias The alias for the selected value
3609
+ * @description Path format is standardized across all databases - ORM converts to DB-specific syntax
3610
+ * @description Result will be available in model.$annotations[alias]
3611
+ * @example
3612
+ * ```ts
3613
+ * // All these path formats are supported:
3614
+ *
3615
+ * // 1. With $ prefix
3616
+ * await User.query().selectJsonText("data", "$.user.email", "userEmail").first();
3617
+ *
3618
+ * // 2. Without $ prefix
3619
+ * await User.query().selectJsonText("data", "user.email", "userEmail").first();
3620
+ *
3621
+ * // 3. Array format
3622
+ * await User.query().selectJsonText("data", ["user", "email"], "userEmail").first();
3623
+ *
3624
+ * // 4. Array indices
3625
+ * await User.query().selectJsonText("data", "tags.0", "firstTag").first();
3626
+ * await User.query().selectJsonText("data", ["tags", 0], "firstTag").first();
3627
+ *
3628
+ * // 5. Deep nesting
3629
+ * await User.query().selectJsonText("data", "user.profile.bio", "biography").first();
3630
+ *
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
3634
+ * ```
3635
+ */
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>;
3642
+ /**
3643
+ * @description Selects the length of a JSON array
3644
+ * @param column The column containing JSON array data
3645
+ * @param path The JSON path to the array (standardized format, use "$" or "" for root)
3646
+ * @param alias The alias for the length value
3647
+ * @description Path format is standardized across all databases - ORM converts to DB-specific syntax
3648
+ * @description Result will be available in model.$annotations[alias]
3649
+ * @warning Not supported in SQLite
3650
+ * @example
3651
+ * ```ts
3652
+ * // All these path formats are supported:
3653
+ *
3654
+ * // 1. With $ prefix
3655
+ * await User.query().selectJsonArrayLength("data", "$.items", "itemCount").first();
3656
+ *
3657
+ * // 2. Without $ prefix
3658
+ * await User.query().selectJsonArrayLength("data", "items", "itemCount").first();
3659
+ *
3660
+ * // 3. Array format
3661
+ * await User.query().selectJsonArrayLength("data", ["items"], "itemCount").first();
3662
+ *
3663
+ * // 4. Root array (use "$" or "")
3664
+ * await User.query().selectJsonArrayLength("data", "$", "totalCount").first();
3665
+ * await User.query().selectJsonArrayLength("data", "", "totalCount").first();
3666
+ *
3667
+ * // 5. Nested arrays
3668
+ * await User.query().selectJsonArrayLength("data", "user.roles", "roleCount").first();
3669
+ * await User.query().selectJsonArrayLength("data", ["user", "roles"], "roleCount").first();
3670
+ *
3671
+ * // 6. Deeply nested arrays
3672
+ * await User.query().selectJsonArrayLength("data", "level1.level2.items", "deepCount").first();
3673
+ *
3674
+ * // Access the result
3675
+ * const user = await User.query().selectJsonArrayLength("data", "items", "count").first();
3676
+ * console.log(user?.$annotations?.count); // Typed as number
3677
+ * ```
3678
+ */
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>;
3685
+ /**
3686
+ * @description Selects the keys of a JSON object
3687
+ * @param column The column containing JSON object data
3688
+ * @param path The JSON path to the object (standardized format, use "$" or "" for root)
3689
+ * @param alias The alias for the keys
3690
+ * @description Path format is standardized across all databases - ORM converts to DB-specific syntax
3691
+ * @description Result will be available in model.$annotations[alias]
3692
+ * @warning Not supported in SQLite or MSSQL
3693
+ * @postgresql Returns a native array of keys
3694
+ * @mysql Returns a JSON array of keys
3695
+ * @example
3696
+ * ```ts
3697
+ * // All these path formats are supported:
3698
+ *
3699
+ * // 1. With $ prefix
3700
+ * await User.query().selectJsonKeys("data", "$.settings", "settingKeys").first();
3701
+ *
3702
+ * // 2. Without $ prefix
3703
+ * await User.query().selectJsonKeys("data", "settings", "settingKeys").first();
3704
+ *
3705
+ * // 3. Array format
3706
+ * await User.query().selectJsonKeys("data", ["settings"], "settingKeys").first();
3707
+ *
3708
+ * // 4. Root object (use "$" or "")
3709
+ * await User.query().selectJsonKeys("data", "$", "rootKeys").first();
3710
+ * await User.query().selectJsonKeys("data", "", "rootKeys").first();
3711
+ *
3712
+ * // 5. Nested objects
3713
+ * await User.query().selectJsonKeys("data", "user.profile", "profileKeys").first();
3714
+ * await User.query().selectJsonKeys("data", ["user", "profile"], "profileKeys").first();
3715
+ *
3716
+ * // 6. Deeply nested objects
3717
+ * await User.query().selectJsonKeys("data", "settings.display.theme", "themeKeys").first();
3718
+ *
3719
+ * // Access the result
3720
+ * const user = await User.query().selectJsonKeys("data", "settings", "keys").first();
3721
+ * console.log(user?.$annotations?.keys); // Typed as any[] - ["theme", "fontSize", "autoSave"]
3722
+ * ```
3723
+ */
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>;
3730
+ /**
3731
+ * @description Adds a raw JSON select expression for database-specific operations
3732
+ * @param raw The raw SQL expression (database-specific syntax)
3733
+ * @param alias The alias for the selected value
3734
+ * @description Result will be available in model.$annotations[alias]
3735
+ * @description Use this for advanced JSON operations not covered by other selectJson* methods
3736
+ * @warning This bypasses path standardization - you must write database-specific SQL
3737
+ * @example
3738
+ * ```ts
3739
+ * // PostgreSQL - Extract as text with ->> operator
3740
+ * await User.query().selectJsonRaw("data->>'email'", "userEmail").first();
3741
+ *
3742
+ * // PostgreSQL - Extract nested JSON with -> operator
3743
+ * await User.query().selectJsonRaw("data->'user'->'profile'->>'name'", "profileName").first();
3744
+ *
3745
+ * // PostgreSQL - Array element access
3746
+ * await User.query().selectJsonRaw("data->'items'->0->>'name'", "firstName").first();
3747
+ *
3748
+ * // MySQL - Extract value with JSON_EXTRACT and ->>
3749
+ * await User.query().selectJsonRaw("data->>'$.email'", "userEmail").first();
3750
+ *
3751
+ * // MySQL - Array length with JSON_LENGTH
3752
+ * await User.query().selectJsonRaw("JSON_LENGTH(data, '$.items')", "itemCount").first();
3753
+ *
3754
+ * // MSSQL - Extract value with JSON_VALUE
3755
+ * await User.query().selectJsonRaw("JSON_VALUE(data, '$.email')", "userEmail").first();
3756
+ *
3757
+ * // SQLite - Extract value with json_extract
3758
+ * await User.query().selectJsonRaw("json_extract(data, '$.email')", "userEmail").first();
3759
+ *
3760
+ * // Access the result
3761
+ * const user = await User.query().selectJsonRaw("data->>'email'", "email").first();
3762
+ * console.log(user?.$annotations?.email); // Typed as any
3763
+ * ```
3764
+ */
3765
+ selectJsonRaw<K extends string>(raw: string, alias: K): ModelQueryBuilder<T, A & {
3766
+ [P in K]: any;
3767
+ }, R>;
3469
3768
  /**
3470
3769
  * @description Removes annotations from the serialized model, by default, annotations are maintained in the serialized model if `annotate` is used
3471
3770
  */
package/lib/index.d.ts CHANGED
@@ -2279,6 +2279,8 @@ declare class WhereGroupNode extends QueryNode {
2279
2279
  constructor(nodes: (WhereNode | WhereGroupNode | WhereSubqueryNode)[], chainsWith?: "and" | "or");
2280
2280
  }
2281
2281
 
2282
+ type JsonPathInput = string | (string | number)[];
2283
+
2282
2284
  declare class DistinctNode extends QueryNode {
2283
2285
  chainsWith: string;
2284
2286
  canKeywordBeSeenMultipleTimes: boolean;
@@ -2786,9 +2788,9 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
2786
2788
  * const user = await User.query().annotate("id", "superId").first(); // id as superId
2787
2789
  * ```
2788
2790
  */
2789
- annotate(column: string, alias: string): this;
2790
- annotate(sqlMethod: SqlMethod, column: string, alias: string): this;
2791
- annotate(sqlMethod: string, column: string, alias: string): this;
2791
+ annotate<A extends string>(column: string, alias: A): this;
2792
+ annotate<A extends string>(sqlMethod: SqlMethod, column: string, alias: A): this;
2793
+ annotate<A extends string>(sqlMethod: string, column: string, alias: A): this;
2792
2794
  /**
2793
2795
  * @description Sets the table to select from, by default is the table defined in the Model
2794
2796
  * @description Can be used on non select queries too, it will only specify the table name (es. INSERT INTO $table)
@@ -2812,6 +2814,99 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
2812
2814
  */
2813
2815
  distinctOn(...columns: ModelKey<T>[]): this;
2814
2816
  distinctOn<S extends string>(...columns: SelectableColumn<S>[]): this;
2817
+ /**
2818
+ * @description Selects a JSON value at the specified path and returns it as JSON
2819
+ * @param column The column containing JSON data
2820
+ * @param path The JSON path to extract (standardized format: "$.user.name", "user.name", or ["user", "name"])
2821
+ * @param alias The alias for the selected value
2822
+ * @description Path format is standardized across all databases - ORM converts to DB-specific syntax
2823
+ * @description Result will be available in model.$annotations[alias]
2824
+ * @example
2825
+ * ```ts
2826
+ * // All databases accept the same path format:
2827
+ * const user = await User.query().selectJson("data", "$.user.name", "userName").first();
2828
+ * console.log(user?.$annotations?.userName); // Typed!
2829
+ *
2830
+ * await User.query().selectJson("data", "user.name", "userName").first(); // $ is optional
2831
+ * await User.query().selectJson("data", ["user", "name"], "userName").first();
2832
+ *
2833
+ * // Array indices:
2834
+ * await User.query().selectJson("data", "items.0.name", "firstItemName").first();
2835
+ * await User.query().selectJson("data", ["items", 0, "name"], "firstItemName").first();
2836
+ * ```
2837
+ */
2838
+ selectJson<A extends string>(column: ModelKey<T>, path: JsonPathInput, alias: A): this;
2839
+ selectJson<A extends string>(column: string, path: JsonPathInput, alias: A): this;
2840
+ /**
2841
+ * @description Selects a JSON value at the specified path and returns it as text
2842
+ * @param column The column containing JSON data
2843
+ * @param path The JSON path to extract (standardized format)
2844
+ * @param alias The alias for the selected value
2845
+ * @description Path format is standardized across all databases - ORM converts to DB-specific syntax
2846
+ * @description Result will be available in model.$annotations[alias]
2847
+ * @example
2848
+ * ```ts
2849
+ * // All databases accept the same path format:
2850
+ * const user = await User.query().selectJsonText("data", "$.user.name", "userName").first();
2851
+ * console.log(user?.$annotations?.userName); // Typed!
2852
+ *
2853
+ * await User.query().selectJsonText("data", ["user", "name"], "userName").first();
2854
+ * ```
2855
+ */
2856
+ selectJsonText<A extends string>(column: ModelKey<T>, path: JsonPathInput, alias: A): this;
2857
+ selectJsonText<A extends string>(column: string, path: JsonPathInput, alias: A): this;
2858
+ /**
2859
+ * @description Selects the length of a JSON array
2860
+ * @param column The column containing JSON array data
2861
+ * @param path The JSON path to the array (standardized format, use "$" or "" for root)
2862
+ * @param alias The alias for the length value
2863
+ * @description Path format is standardized across all databases - ORM converts to DB-specific syntax
2864
+ * @description Result will be available in model.$annotations[alias]
2865
+ * @example
2866
+ * ```ts
2867
+ * // All databases accept the same path format:
2868
+ * const user = await User.query().selectJsonArrayLength("data", "$.items", "itemCount").first();
2869
+ * console.log(user?.$annotations?.itemCount); // Typed!
2870
+ *
2871
+ * await User.query().selectJsonArrayLength("data", "items", "itemCount").first();
2872
+ * await User.query().selectJsonArrayLength("data", "$", "totalCount").first(); // root array
2873
+ * ```
2874
+ */
2875
+ selectJsonArrayLength<A extends string>(column: ModelKey<T>, path: JsonPathInput, alias: A): this;
2876
+ selectJsonArrayLength<A extends string>(column: string, path: JsonPathInput, alias: A): this;
2877
+ /**
2878
+ * @description Selects the keys of a JSON object
2879
+ * @param column The column containing JSON object data
2880
+ * @param path The JSON path to the object (standardized format, use "$" or "" for root)
2881
+ * @param alias The alias for the keys
2882
+ * @description Path format is standardized across all databases - ORM converts to DB-specific syntax
2883
+ * @description Result will be available in model.$annotations[alias]
2884
+ * @postgres Returns an array of keys
2885
+ * @mysql Returns a JSON array of keys
2886
+ * @example
2887
+ * ```ts
2888
+ * // All databases accept the same path format:
2889
+ * const user = await User.query().selectJsonKeys("data", "$.user", "userKeys").first();
2890
+ * console.log(user?.$annotations?.userKeys); // Typed!
2891
+ *
2892
+ * await User.query().selectJsonKeys("data", "user", "userKeys").first();
2893
+ * await User.query().selectJsonKeys("data", "$", "rootKeys").first(); // root object
2894
+ * ```
2895
+ */
2896
+ selectJsonKeys<A extends string>(column: ModelKey<T>, path: JsonPathInput, alias: A): this;
2897
+ selectJsonKeys<A extends string>(column: string, path: JsonPathInput, alias: A): this;
2898
+ /**
2899
+ * @description Adds a raw JSON select expression
2900
+ * @param raw The raw SQL expression
2901
+ * @param alias The alias for the selected value
2902
+ * @description Result will be available in model.$annotations[alias]
2903
+ * @example
2904
+ * ```ts
2905
+ * const user = await User.query().selectJsonRaw("data->>'email'", "userEmail").first();
2906
+ * console.log(user?.$annotations?.userEmail); // Typed!
2907
+ * ```
2908
+ */
2909
+ selectJsonRaw<A extends string>(raw: string, alias: A): this;
2815
2910
  }
2816
2911
 
2817
2912
  declare abstract class WhereQueryBuilder<T extends Model> extends SelectQueryBuilder<T> {
@@ -3466,6 +3561,210 @@ declare class ModelQueryBuilder<T extends Model, A extends Record<string, any> =
3466
3561
  annotate<K extends string, S extends SqlMethod, V = CommonSqlMethodReturnType<S>>(sqlMethod: S, column: string, alias: K): ModelQueryBuilder<T, A & {
3467
3562
  [P in K]: V;
3468
3563
  }, R>;
3564
+ /**
3565
+ * @description Selects a JSON value at the specified path and returns it as JSON
3566
+ * @param column The column containing JSON data
3567
+ * @param path The JSON path to extract (standardized format: "$.user.name", "user.name", or ["user", "name"])
3568
+ * @param alias The alias for the selected value
3569
+ * @description Path format is standardized across all databases - ORM converts to DB-specific syntax
3570
+ * @description Result will be available in model.$annotations[alias]
3571
+ * @example
3572
+ * ```ts
3573
+ * // All these path formats are supported:
3574
+ *
3575
+ * // 1. With $ prefix (standard JSON path)
3576
+ * await User.query().selectJson("data", "$.user.name", "userName").first();
3577
+ *
3578
+ * // 2. Without $ prefix ($ is optional)
3579
+ * await User.query().selectJson("data", "user.name", "userName").first();
3580
+ *
3581
+ * // 3. Array format
3582
+ * await User.query().selectJson("data", ["user", "name"], "userName").first();
3583
+ *
3584
+ * // 4. Array indices with dot notation
3585
+ * await User.query().selectJson("data", "items.0.name", "firstItemName").first();
3586
+ *
3587
+ * // 5. Array indices with array format
3588
+ * await User.query().selectJson("data", ["items", 0, "name"], "firstItemName").first();
3589
+ *
3590
+ * // 6. Root object
3591
+ * await User.query().selectJson("data", "$", "allData").first();
3592
+ *
3593
+ * // Access the result
3594
+ * const user = await User.query().selectJson("data", "user.name", "userName").first();
3595
+ * console.log(user?.$annotations?.userName); // Typed as any
3596
+ * ```
3597
+ */
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>;
3604
+ /**
3605
+ * @description Selects a JSON value at the specified path and returns it as text
3606
+ * @param column The column containing JSON data
3607
+ * @param path The JSON path to extract (standardized format)
3608
+ * @param alias The alias for the selected value
3609
+ * @description Path format is standardized across all databases - ORM converts to DB-specific syntax
3610
+ * @description Result will be available in model.$annotations[alias]
3611
+ * @example
3612
+ * ```ts
3613
+ * // All these path formats are supported:
3614
+ *
3615
+ * // 1. With $ prefix
3616
+ * await User.query().selectJsonText("data", "$.user.email", "userEmail").first();
3617
+ *
3618
+ * // 2. Without $ prefix
3619
+ * await User.query().selectJsonText("data", "user.email", "userEmail").first();
3620
+ *
3621
+ * // 3. Array format
3622
+ * await User.query().selectJsonText("data", ["user", "email"], "userEmail").first();
3623
+ *
3624
+ * // 4. Array indices
3625
+ * await User.query().selectJsonText("data", "tags.0", "firstTag").first();
3626
+ * await User.query().selectJsonText("data", ["tags", 0], "firstTag").first();
3627
+ *
3628
+ * // 5. Deep nesting
3629
+ * await User.query().selectJsonText("data", "user.profile.bio", "biography").first();
3630
+ *
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
3634
+ * ```
3635
+ */
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>;
3642
+ /**
3643
+ * @description Selects the length of a JSON array
3644
+ * @param column The column containing JSON array data
3645
+ * @param path The JSON path to the array (standardized format, use "$" or "" for root)
3646
+ * @param alias The alias for the length value
3647
+ * @description Path format is standardized across all databases - ORM converts to DB-specific syntax
3648
+ * @description Result will be available in model.$annotations[alias]
3649
+ * @warning Not supported in SQLite
3650
+ * @example
3651
+ * ```ts
3652
+ * // All these path formats are supported:
3653
+ *
3654
+ * // 1. With $ prefix
3655
+ * await User.query().selectJsonArrayLength("data", "$.items", "itemCount").first();
3656
+ *
3657
+ * // 2. Without $ prefix
3658
+ * await User.query().selectJsonArrayLength("data", "items", "itemCount").first();
3659
+ *
3660
+ * // 3. Array format
3661
+ * await User.query().selectJsonArrayLength("data", ["items"], "itemCount").first();
3662
+ *
3663
+ * // 4. Root array (use "$" or "")
3664
+ * await User.query().selectJsonArrayLength("data", "$", "totalCount").first();
3665
+ * await User.query().selectJsonArrayLength("data", "", "totalCount").first();
3666
+ *
3667
+ * // 5. Nested arrays
3668
+ * await User.query().selectJsonArrayLength("data", "user.roles", "roleCount").first();
3669
+ * await User.query().selectJsonArrayLength("data", ["user", "roles"], "roleCount").first();
3670
+ *
3671
+ * // 6. Deeply nested arrays
3672
+ * await User.query().selectJsonArrayLength("data", "level1.level2.items", "deepCount").first();
3673
+ *
3674
+ * // Access the result
3675
+ * const user = await User.query().selectJsonArrayLength("data", "items", "count").first();
3676
+ * console.log(user?.$annotations?.count); // Typed as number
3677
+ * ```
3678
+ */
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>;
3685
+ /**
3686
+ * @description Selects the keys of a JSON object
3687
+ * @param column The column containing JSON object data
3688
+ * @param path The JSON path to the object (standardized format, use "$" or "" for root)
3689
+ * @param alias The alias for the keys
3690
+ * @description Path format is standardized across all databases - ORM converts to DB-specific syntax
3691
+ * @description Result will be available in model.$annotations[alias]
3692
+ * @warning Not supported in SQLite or MSSQL
3693
+ * @postgresql Returns a native array of keys
3694
+ * @mysql Returns a JSON array of keys
3695
+ * @example
3696
+ * ```ts
3697
+ * // All these path formats are supported:
3698
+ *
3699
+ * // 1. With $ prefix
3700
+ * await User.query().selectJsonKeys("data", "$.settings", "settingKeys").first();
3701
+ *
3702
+ * // 2. Without $ prefix
3703
+ * await User.query().selectJsonKeys("data", "settings", "settingKeys").first();
3704
+ *
3705
+ * // 3. Array format
3706
+ * await User.query().selectJsonKeys("data", ["settings"], "settingKeys").first();
3707
+ *
3708
+ * // 4. Root object (use "$" or "")
3709
+ * await User.query().selectJsonKeys("data", "$", "rootKeys").first();
3710
+ * await User.query().selectJsonKeys("data", "", "rootKeys").first();
3711
+ *
3712
+ * // 5. Nested objects
3713
+ * await User.query().selectJsonKeys("data", "user.profile", "profileKeys").first();
3714
+ * await User.query().selectJsonKeys("data", ["user", "profile"], "profileKeys").first();
3715
+ *
3716
+ * // 6. Deeply nested objects
3717
+ * await User.query().selectJsonKeys("data", "settings.display.theme", "themeKeys").first();
3718
+ *
3719
+ * // Access the result
3720
+ * const user = await User.query().selectJsonKeys("data", "settings", "keys").first();
3721
+ * console.log(user?.$annotations?.keys); // Typed as any[] - ["theme", "fontSize", "autoSave"]
3722
+ * ```
3723
+ */
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>;
3730
+ /**
3731
+ * @description Adds a raw JSON select expression for database-specific operations
3732
+ * @param raw The raw SQL expression (database-specific syntax)
3733
+ * @param alias The alias for the selected value
3734
+ * @description Result will be available in model.$annotations[alias]
3735
+ * @description Use this for advanced JSON operations not covered by other selectJson* methods
3736
+ * @warning This bypasses path standardization - you must write database-specific SQL
3737
+ * @example
3738
+ * ```ts
3739
+ * // PostgreSQL - Extract as text with ->> operator
3740
+ * await User.query().selectJsonRaw("data->>'email'", "userEmail").first();
3741
+ *
3742
+ * // PostgreSQL - Extract nested JSON with -> operator
3743
+ * await User.query().selectJsonRaw("data->'user'->'profile'->>'name'", "profileName").first();
3744
+ *
3745
+ * // PostgreSQL - Array element access
3746
+ * await User.query().selectJsonRaw("data->'items'->0->>'name'", "firstName").first();
3747
+ *
3748
+ * // MySQL - Extract value with JSON_EXTRACT and ->>
3749
+ * await User.query().selectJsonRaw("data->>'$.email'", "userEmail").first();
3750
+ *
3751
+ * // MySQL - Array length with JSON_LENGTH
3752
+ * await User.query().selectJsonRaw("JSON_LENGTH(data, '$.items')", "itemCount").first();
3753
+ *
3754
+ * // MSSQL - Extract value with JSON_VALUE
3755
+ * await User.query().selectJsonRaw("JSON_VALUE(data, '$.email')", "userEmail").first();
3756
+ *
3757
+ * // SQLite - Extract value with json_extract
3758
+ * await User.query().selectJsonRaw("json_extract(data, '$.email')", "userEmail").first();
3759
+ *
3760
+ * // Access the result
3761
+ * const user = await User.query().selectJsonRaw("data->>'email'", "email").first();
3762
+ * console.log(user?.$annotations?.email); // Typed as any
3763
+ * ```
3764
+ */
3765
+ selectJsonRaw<K extends string>(raw: string, alias: K): ModelQueryBuilder<T, A & {
3766
+ [P in K]: any;
3767
+ }, R>;
3469
3768
  /**
3470
3769
  * @description Removes annotations from the serialized model, by default, annotations are maintained in the serialized model if `annotate` is used
3471
3770
  */