hysteria-orm 10.5.1 → 10.5.2
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/cli.js +20 -20
- package/lib/cli.js.map +1 -1
- package/lib/index.cjs +19 -19
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +335 -449
- package/lib/index.d.ts +335 -449
- package/lib/index.js +19 -19
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.cts
CHANGED
|
@@ -2969,22 +2969,30 @@ declare class SelectQueryBuilder<T extends Model, S extends Record<string, any>
|
|
|
2969
2969
|
/**
|
|
2970
2970
|
* @description Adds a SELECT condition to the query.
|
|
2971
2971
|
* @description Can be stacked multiple times
|
|
2972
|
-
* @description Supports: "column", "table.column", "
|
|
2972
|
+
* @description Supports: "column", "table.column", "*", "table.*", or [column, alias] tuples
|
|
2973
|
+
* @example
|
|
2974
|
+
* .select("id", "name") // Simple columns
|
|
2975
|
+
* .select(["id", "userId"], ["name", "userName"]) // Columns with aliases
|
|
2976
|
+
* .select("id", ["name", "userName"]) // Mixed
|
|
2973
2977
|
*/
|
|
2974
|
-
select<C extends string>(...columns: SelectableColumn$1<C>[]): this;
|
|
2975
|
-
select(...columns: (ModelKey<T> | "*")[]): this;
|
|
2976
|
-
/**
|
|
2977
|
-
* @description Parses a column string that may contain an alias (e.g., "column as alias")
|
|
2978
|
-
* @returns The column part and optional alias part
|
|
2979
|
-
*/
|
|
2980
|
-
protected parseColumnAlias(column: string): {
|
|
2981
|
-
columnPart: string;
|
|
2982
|
-
aliasPart: string | undefined;
|
|
2983
|
-
};
|
|
2978
|
+
select<C extends string>(...columns: (SelectableColumn$1<C> | Selectable)[]): this;
|
|
2979
|
+
select(...columns: (ModelKey<T> | "*" | Selectable)[]): this;
|
|
2984
2980
|
/**
|
|
2985
2981
|
* @description Adds a raw SELECT statement to the query
|
|
2986
2982
|
*/
|
|
2987
2983
|
selectRaw(statement: string): this;
|
|
2984
|
+
/**
|
|
2985
|
+
* @description Selects a SQL function applied to a column with a typed alias.
|
|
2986
|
+
* @description Provides intellisense for common SQL functions while accepting any custom function.
|
|
2987
|
+
* @param func The SQL function name (count, sum, avg, min, max, upper, lower, etc.)
|
|
2988
|
+
* @param column The column to apply the function to (use "*" for count(*))
|
|
2989
|
+
* @param alias The alias for the result
|
|
2990
|
+
* @example
|
|
2991
|
+
* .selectFunc("count", "*", "total")
|
|
2992
|
+
* .selectFunc("upper", "name", "upperName")
|
|
2993
|
+
* .selectFunc("custom_fn", "column", "result")
|
|
2994
|
+
*/
|
|
2995
|
+
selectFunc<A extends string>(sqlFunc: SqlFunction, column: string, alias: A): this;
|
|
2988
2996
|
/**
|
|
2989
2997
|
* @description Clears the SELECT clause
|
|
2990
2998
|
*/
|
|
@@ -3044,88 +3052,6 @@ declare class SelectQueryBuilder<T extends Model, S extends Record<string, any>
|
|
|
3044
3052
|
* @description Adds a raw JSON select expression
|
|
3045
3053
|
*/
|
|
3046
3054
|
selectJsonRaw<A extends string>(raw: string, alias: A): this;
|
|
3047
|
-
/**
|
|
3048
|
-
* @description Selects COUNT(column) with an alias
|
|
3049
|
-
*/
|
|
3050
|
-
selectCount<A extends string>(column: ModelKey<T> | "*", alias: A): this;
|
|
3051
|
-
selectCount<A extends string>(column: string, alias: A): this;
|
|
3052
|
-
/**
|
|
3053
|
-
* @description Selects SUM(column) with an alias
|
|
3054
|
-
*/
|
|
3055
|
-
selectSum<A extends string>(column: ModelKey<T>, alias: A): this;
|
|
3056
|
-
selectSum<A extends string>(column: string, alias: A): this;
|
|
3057
|
-
/**
|
|
3058
|
-
* @description Selects AVG(column) with an alias
|
|
3059
|
-
*/
|
|
3060
|
-
selectAvg<A extends string>(column: ModelKey<T>, alias: A): this;
|
|
3061
|
-
selectAvg<A extends string>(column: string, alias: A): this;
|
|
3062
|
-
/**
|
|
3063
|
-
* @description Selects MIN(column) with an alias
|
|
3064
|
-
*/
|
|
3065
|
-
selectMin<A extends string>(column: ModelKey<T>, alias: A): this;
|
|
3066
|
-
selectMin<A extends string>(column: string, alias: A): this;
|
|
3067
|
-
/**
|
|
3068
|
-
* @description Selects MAX(column) with an alias
|
|
3069
|
-
*/
|
|
3070
|
-
selectMax<A extends string>(column: ModelKey<T>, alias: A): this;
|
|
3071
|
-
selectMax<A extends string>(column: string, alias: A): this;
|
|
3072
|
-
/**
|
|
3073
|
-
* @description Selects COUNT(DISTINCT column) with an alias
|
|
3074
|
-
*/
|
|
3075
|
-
selectCountDistinct<A extends string>(column: ModelKey<T>, alias: A): this;
|
|
3076
|
-
selectCountDistinct<A extends string>(column: string, alias: A): this;
|
|
3077
|
-
/**
|
|
3078
|
-
* @description Selects UPPER(column) with an alias
|
|
3079
|
-
*/
|
|
3080
|
-
selectUpper<A extends string>(column: ModelKey<T>, alias: A): this;
|
|
3081
|
-
selectUpper<A extends string>(column: string, alias: A): this;
|
|
3082
|
-
/**
|
|
3083
|
-
* @description Selects LOWER(column) with an alias
|
|
3084
|
-
*/
|
|
3085
|
-
selectLower<A extends string>(column: ModelKey<T>, alias: A): this;
|
|
3086
|
-
selectLower<A extends string>(column: string, alias: A): this;
|
|
3087
|
-
/**
|
|
3088
|
-
* @description Selects LENGTH(column) with an alias
|
|
3089
|
-
* @note MSSQL uses LEN() instead of LENGTH()
|
|
3090
|
-
*/
|
|
3091
|
-
selectLength<A extends string>(column: ModelKey<T>, alias: A): this;
|
|
3092
|
-
selectLength<A extends string>(column: string, alias: A): this;
|
|
3093
|
-
/**
|
|
3094
|
-
* @description Selects TRIM(column) with an alias
|
|
3095
|
-
*/
|
|
3096
|
-
selectTrim<A extends string>(column: ModelKey<T>, alias: A): this;
|
|
3097
|
-
selectTrim<A extends string>(column: string, alias: A): this;
|
|
3098
|
-
/**
|
|
3099
|
-
* @description Selects ABS(column) with an alias
|
|
3100
|
-
*/
|
|
3101
|
-
selectAbs<A extends string>(column: ModelKey<T>, alias: A): this;
|
|
3102
|
-
selectAbs<A extends string>(column: string, alias: A): this;
|
|
3103
|
-
/**
|
|
3104
|
-
* @description Selects ROUND(column, decimals) with an alias
|
|
3105
|
-
*/
|
|
3106
|
-
selectRound<A extends string>(column: ModelKey<T>, decimals: number, alias: A): this;
|
|
3107
|
-
selectRound<A extends string>(column: string, decimals: number, alias: A): this;
|
|
3108
|
-
/**
|
|
3109
|
-
* @description Selects COALESCE(column, defaultValue) with an alias
|
|
3110
|
-
*/
|
|
3111
|
-
selectCoalesce<A extends string>(column: ModelKey<T>, defaultValue: string | number, alias: A): this;
|
|
3112
|
-
selectCoalesce<A extends string>(column: string, defaultValue: string | number, alias: A): this;
|
|
3113
|
-
/**
|
|
3114
|
-
* @description Selects CEIL(column) with an alias
|
|
3115
|
-
* @mssql Uses CEILING instead of CEIL
|
|
3116
|
-
*/
|
|
3117
|
-
selectCeil<A extends string>(column: ModelKey<T>, alias: A): this;
|
|
3118
|
-
selectCeil<A extends string>(column: string, alias: A): this;
|
|
3119
|
-
/**
|
|
3120
|
-
* @description Selects FLOOR(column) with an alias
|
|
3121
|
-
*/
|
|
3122
|
-
selectFloor<A extends string>(column: ModelKey<T>, alias: A): this;
|
|
3123
|
-
selectFloor<A extends string>(column: string, alias: A): this;
|
|
3124
|
-
/**
|
|
3125
|
-
* @description Selects SQRT(column) with an alias
|
|
3126
|
-
*/
|
|
3127
|
-
selectSqrt<A extends string>(column: ModelKey<T>, alias: A): this;
|
|
3128
|
-
selectSqrt<A extends string>(column: string, alias: A): this;
|
|
3129
3055
|
}
|
|
3130
3056
|
|
|
3131
3057
|
declare abstract class WhereQueryBuilder<T extends Model, S extends Record<string, any> = Record<string, any>> extends SelectQueryBuilder<T, S> {
|
|
@@ -3637,17 +3563,17 @@ declare class QueryBuilder<T extends Model = any, S extends Record<string, any>
|
|
|
3637
3563
|
/**
|
|
3638
3564
|
* @description Adds a SELECT condition to the query with type safety.
|
|
3639
3565
|
* @description Can be stacked multiple times
|
|
3640
|
-
* @description Supports: "column", "table.column", "
|
|
3566
|
+
* @description Supports: "column", "table.column", "*", "table.*", or [column, alias] tuples
|
|
3641
3567
|
* @example
|
|
3642
3568
|
* ```ts
|
|
3643
3569
|
* const user = await sql.query("users").select("name", "age").one();
|
|
3644
3570
|
* // user type: { name: any, age: any } | null
|
|
3645
3571
|
*
|
|
3646
|
-
* const user = await sql.query("users").select("name
|
|
3572
|
+
* const user = await sql.query("users").select(["name", "userName"]).one();
|
|
3647
3573
|
* // user type: { userName: any } | null
|
|
3648
3574
|
* ```
|
|
3649
3575
|
*/
|
|
3650
|
-
select<Columns extends readonly
|
|
3576
|
+
select<const Columns extends readonly Selectable[]>(...columns: Columns): QueryBuilder<T, ComposeBuildRawSelect<S, Columns>>;
|
|
3651
3577
|
/**
|
|
3652
3578
|
* @description Adds a raw SELECT statement to the query with type safety.
|
|
3653
3579
|
* @description Use the generic parameter to specify the type of the selected columns.
|
|
@@ -3664,6 +3590,24 @@ declare class QueryBuilder<T extends Model = any, S extends Record<string, any>
|
|
|
3664
3590
|
* @description Clears the SELECT clause and resets type to default
|
|
3665
3591
|
*/
|
|
3666
3592
|
clearSelect(): QueryBuilder<T, Record<string, any>>;
|
|
3593
|
+
/**
|
|
3594
|
+
* @description Selects a SQL function applied to a column with a typed alias.
|
|
3595
|
+
* @description Provides intellisense for common SQL functions while accepting any custom function.
|
|
3596
|
+
* @description Return type is auto-inferred based on function name (number for count/sum/avg, string for upper/lower/trim, etc.)
|
|
3597
|
+
* @param sqlFunc The SQL function name (count, sum, avg, min, max, upper, lower, etc.)
|
|
3598
|
+
* @param column The column to apply the function to (use "*" for count(*))
|
|
3599
|
+
* @param alias The alias for the result
|
|
3600
|
+
* @example
|
|
3601
|
+
* ```ts
|
|
3602
|
+
* const result = await sql.query("users")
|
|
3603
|
+
* .selectFunc("count", "*", "total")
|
|
3604
|
+
* .one();
|
|
3605
|
+
* // result type: { total: number } | null - auto-inferred!
|
|
3606
|
+
* ```
|
|
3607
|
+
*/
|
|
3608
|
+
selectFunc<F extends SqlFunction, Alias extends string>(sqlFunc: F, column: string, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3609
|
+
[K in Alias]: SqlFunctionReturnType<F>;
|
|
3610
|
+
}>>;
|
|
3667
3611
|
/**
|
|
3668
3612
|
* @description Selects a subquery, subquery must return a single column
|
|
3669
3613
|
*/
|
|
@@ -3685,54 +3629,6 @@ declare class QueryBuilder<T extends Model = any, S extends Record<string, any>
|
|
|
3685
3629
|
selectJsonRaw<ValueType = any, Alias extends string = string>(raw: string, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3686
3630
|
[K in Alias]: ValueType;
|
|
3687
3631
|
}>>;
|
|
3688
|
-
selectCount<Alias extends string = string>(column: ModelKey<T> | "*" | string, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3689
|
-
[K in Alias]: number;
|
|
3690
|
-
}>>;
|
|
3691
|
-
selectSum<Alias extends string = string>(column: ModelKey<T> | string, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3692
|
-
[K in Alias]: number;
|
|
3693
|
-
}>>;
|
|
3694
|
-
selectAvg<Alias extends string = string>(column: ModelKey<T> | string, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3695
|
-
[K in Alias]: number;
|
|
3696
|
-
}>>;
|
|
3697
|
-
selectMin<Alias extends string = string>(column: ModelKey<T> | string, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3698
|
-
[K in Alias]: any;
|
|
3699
|
-
}>>;
|
|
3700
|
-
selectMax<Alias extends string = string>(column: ModelKey<T> | string, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3701
|
-
[K in Alias]: any;
|
|
3702
|
-
}>>;
|
|
3703
|
-
selectCountDistinct<Alias extends string = string>(column: ModelKey<T> | string, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3704
|
-
[K in Alias]: number;
|
|
3705
|
-
}>>;
|
|
3706
|
-
selectUpper<Alias extends string = string>(column: ModelKey<T> | string, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3707
|
-
[K in Alias]: string;
|
|
3708
|
-
}>>;
|
|
3709
|
-
selectLower<Alias extends string = string>(column: ModelKey<T> | string, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3710
|
-
[K in Alias]: string;
|
|
3711
|
-
}>>;
|
|
3712
|
-
selectLength<Alias extends string = string>(column: ModelKey<T> | string, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3713
|
-
[K in Alias]: number;
|
|
3714
|
-
}>>;
|
|
3715
|
-
selectTrim<Alias extends string = string>(column: ModelKey<T> | string, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3716
|
-
[K in Alias]: string;
|
|
3717
|
-
}>>;
|
|
3718
|
-
selectAbs<Alias extends string = string>(column: ModelKey<T> | string, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3719
|
-
[K in Alias]: number;
|
|
3720
|
-
}>>;
|
|
3721
|
-
selectRound<Alias extends string = string>(column: ModelKey<T> | string, decimals: number, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3722
|
-
[K in Alias]: number;
|
|
3723
|
-
}>>;
|
|
3724
|
-
selectCoalesce<ValueType = any, Alias extends string = string>(column: ModelKey<T> | string, defaultValue: string | number, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3725
|
-
[K in Alias]: ValueType;
|
|
3726
|
-
}>>;
|
|
3727
|
-
selectCeil<Alias extends string = string>(column: ModelKey<T> | string, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3728
|
-
[K in Alias]: number;
|
|
3729
|
-
}>>;
|
|
3730
|
-
selectFloor<Alias extends string = string>(column: ModelKey<T> | string, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3731
|
-
[K in Alias]: number;
|
|
3732
|
-
}>>;
|
|
3733
|
-
selectSqrt<Alias extends string = string>(column: ModelKey<T> | string, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3734
|
-
[K in Alias]: number;
|
|
3735
|
-
}>>;
|
|
3736
3632
|
/**
|
|
3737
3633
|
* @description Executes the query and returns true if the query returns at least one result, false otherwise.
|
|
3738
3634
|
*/
|
|
@@ -4086,6 +3982,40 @@ declare class DryQueryBuilder<T extends Model = any, S extends Record<string, an
|
|
|
4086
3982
|
}
|
|
4087
3983
|
|
|
4088
3984
|
type PluckReturnType<T extends Model, K extends ModelKey<T>> = T[K] extends infer U ? U[] : never;
|
|
3985
|
+
/**
|
|
3986
|
+
* Common SQL functions with intellisense support.
|
|
3987
|
+
* Provides autocomplete for standard SQL aggregate and scalar functions,
|
|
3988
|
+
* while still allowing any custom function name via string fallback.
|
|
3989
|
+
*
|
|
3990
|
+
* @example
|
|
3991
|
+
* selectFunc("count", "*", "total") // Intellisense suggests "count"
|
|
3992
|
+
* selectFunc("custom_fn", "col", "res") // Custom functions still work
|
|
3993
|
+
*/
|
|
3994
|
+
type SqlFunction = "count" | "sum" | "avg" | "min" | "max" | "upper" | "lower" | "length" | "trim" | "abs" | "round" | "coalesce" | "ceil" | "floor" | "sqrt" | (string & {});
|
|
3995
|
+
/**
|
|
3996
|
+
* Maps SQL function names to their return types.
|
|
3997
|
+
* Used by selectFunc to auto-infer the result type.
|
|
3998
|
+
*
|
|
3999
|
+
* - Numeric functions (count, sum, avg, etc.) → number
|
|
4000
|
+
* - String functions (upper, lower, trim) → string
|
|
4001
|
+
* - Unknown functions → any
|
|
4002
|
+
*/
|
|
4003
|
+
type SqlFunctionReturnType<F extends string> = F extends "count" | "sum" | "avg" | "min" | "max" | "length" | "abs" | "round" | "ceil" | "floor" | "sqrt" ? number : F extends "upper" | "lower" | "trim" ? string : any;
|
|
4004
|
+
/**
|
|
4005
|
+
* A tuple type for selecting a column with an alias.
|
|
4006
|
+
* @example ["id", "userId"] selects "id" column as "userId"
|
|
4007
|
+
*/
|
|
4008
|
+
type SelectTuple<C extends string = string, A extends string = string> = readonly [column: C, alias: A];
|
|
4009
|
+
/**
|
|
4010
|
+
* Input type for select() method in raw query builder.
|
|
4011
|
+
* Accepts either a column string or a [column, alias] tuple.
|
|
4012
|
+
*
|
|
4013
|
+
* @example
|
|
4014
|
+
* .select("id", "name") // Simple columns
|
|
4015
|
+
* .select(["id", "userId"], ["name", "n"]) // Columns with aliases
|
|
4016
|
+
* .select("id", ["name", "userName"]) // Mixed
|
|
4017
|
+
*/
|
|
4018
|
+
type Selectable = string | SelectTuple;
|
|
4089
4019
|
/**
|
|
4090
4020
|
* Unique symbol used internally to mark that a raw select() has been called.
|
|
4091
4021
|
*/
|
|
@@ -4103,41 +4033,52 @@ type RawSelectBrand = {
|
|
|
4103
4033
|
*/
|
|
4104
4034
|
type UnionToIntersection$1<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
4105
4035
|
/**
|
|
4106
|
-
* Extracts the final property name from a column selection
|
|
4036
|
+
* Extracts the final property name from a column selection for raw queries.
|
|
4037
|
+
* Supports both string columns and [column, alias] tuples.
|
|
4107
4038
|
*
|
|
4108
|
-
* | Input
|
|
4109
|
-
*
|
|
4110
|
-
* | `"name"`
|
|
4111
|
-
* | `"users.name"`
|
|
4112
|
-
* | `"name
|
|
4113
|
-
* | `"
|
|
4114
|
-
* | `"*"`
|
|
4115
|
-
* | `"users.*"`
|
|
4039
|
+
* | Input | Output |
|
|
4040
|
+
* |------------------------------|---------------|
|
|
4041
|
+
* | `"name"` | `"name"` |
|
|
4042
|
+
* | `"users.name"` | `"name"` |
|
|
4043
|
+
* | `["name", "userName"]` | `"userName"` |
|
|
4044
|
+
* | `["users.id", "id"]` | `"id"` |
|
|
4045
|
+
* | `"*"` | `never` |
|
|
4046
|
+
* | `"users.*"` | `never` |
|
|
4116
4047
|
*/
|
|
4117
|
-
type ExtractRawColumnName<S
|
|
4048
|
+
type ExtractRawColumnName<S> = S extends readonly [
|
|
4049
|
+
string,
|
|
4050
|
+
infer Alias extends string
|
|
4051
|
+
] ? Alias : S extends string ? S extends "*" ? never : S extends `${string}.*` ? never : S extends `${string}.${infer Column}` ? Column extends "*" ? never : Column : S : never;
|
|
4118
4052
|
/**
|
|
4119
4053
|
* Builds the type for a single selected column in a raw query.
|
|
4120
4054
|
* All column types are `any` since we don't have model type information.
|
|
4055
|
+
* Supports both string columns and [column, alias] tuples.
|
|
4121
4056
|
*
|
|
4122
|
-
* | Selection
|
|
4123
|
-
*
|
|
4124
|
-
* | `"*"`
|
|
4125
|
-
* | `"table.*"`
|
|
4126
|
-
* | `"column"`
|
|
4127
|
-
* | `"col
|
|
4057
|
+
* | Selection | Result Type |
|
|
4058
|
+
* |------------------------|---------------------------------------|
|
|
4059
|
+
* | `"*"` | `Record<string, any>` |
|
|
4060
|
+
* | `"table.*"` | `Record<string, any>` |
|
|
4061
|
+
* | `"column"` | `{ column: any }` |
|
|
4062
|
+
* | `["col", "alias"]` | `{ alias: any }` |
|
|
4128
4063
|
*
|
|
4129
4064
|
* @internal
|
|
4130
4065
|
*/
|
|
4131
|
-
type BuildRawSingleSelectType<S
|
|
4132
|
-
|
|
4133
|
-
|
|
4066
|
+
type BuildRawSingleSelectType<S> = S extends readonly [
|
|
4067
|
+
string,
|
|
4068
|
+
infer Alias extends string
|
|
4069
|
+
] ? {
|
|
4070
|
+
[K in Alias]: any;
|
|
4071
|
+
} : S extends string ? S extends "*" ? Record<string, any> : S extends `${string}.*` ? Record<string, any> : ExtractRawColumnName<S> extends never ? {} : {
|
|
4072
|
+
[K in ExtractRawColumnName<S> & string]: any;
|
|
4073
|
+
} : {};
|
|
4134
4074
|
/**
|
|
4135
4075
|
* Checks if a column selection includes wildcards or is empty.
|
|
4136
4076
|
* @internal
|
|
4137
4077
|
*/
|
|
4138
|
-
type HasRawStarOrEmpty<Columns extends readonly
|
|
4078
|
+
type HasRawStarOrEmpty<Columns extends readonly Selectable[]> = Columns["length"] extends 0 ? true : "*" extends Columns[number] ? true : false;
|
|
4139
4079
|
/**
|
|
4140
4080
|
* Builds the combined TypeScript type for multiple selected columns in a raw query.
|
|
4081
|
+
* Supports both string columns and [column, alias] tuples.
|
|
4141
4082
|
*
|
|
4142
4083
|
* ## Rules
|
|
4143
4084
|
*
|
|
@@ -4146,8 +4087,8 @@ type HasRawStarOrEmpty<Columns extends readonly string[]> = Columns["length"] ex
|
|
|
4146
4087
|
* 3. **With `table.*`**: Adds `Record<string, any>` to allow unknown properties
|
|
4147
4088
|
*
|
|
4148
4089
|
* @example
|
|
4149
|
-
* // .select("name", "age
|
|
4150
|
-
* BuildRawSelectType<["name", "age
|
|
4090
|
+
* // .select("name", ["age", "userAge"])
|
|
4091
|
+
* BuildRawSelectType<["name", ["age", "userAge"]]>
|
|
4151
4092
|
* // Result: { name: any; userAge: any } & RawSelectBrand
|
|
4152
4093
|
*
|
|
4153
4094
|
* @example
|
|
@@ -4155,8 +4096,8 @@ type HasRawStarOrEmpty<Columns extends readonly string[]> = Columns["length"] ex
|
|
|
4155
4096
|
* BuildRawSelectType<["*"]>
|
|
4156
4097
|
* // Result: Record<string, any>
|
|
4157
4098
|
*/
|
|
4158
|
-
type BuildRawSelectType<Columns extends readonly
|
|
4159
|
-
[K in keyof Columns]:
|
|
4099
|
+
type BuildRawSelectType<Columns extends readonly Selectable[]> = HasRawStarOrEmpty<Columns> extends true ? Record<string, any> : UnionToIntersection$1<{
|
|
4100
|
+
[K in keyof Columns]: BuildRawSingleSelectType<Columns[K]>;
|
|
4160
4101
|
}[number]> extends infer Result ? Result extends Record<string, any> ? keyof Result extends never ? Record<string, any> : Result & RawSelectBrand : Record<string, any> : Record<string, any>;
|
|
4161
4102
|
/**
|
|
4162
4103
|
* Composes a new selection with the existing selection state for raw queries.
|
|
@@ -4186,10 +4127,15 @@ type ComposeRawSelect<S extends Record<string, any>, Added extends Record<string
|
|
|
4186
4127
|
* @typeParam S - Current selection state
|
|
4187
4128
|
* @typeParam Columns - The columns being selected
|
|
4188
4129
|
*/
|
|
4189
|
-
type ComposeBuildRawSelect<S extends Record<string, any>, Columns extends readonly
|
|
4130
|
+
type ComposeBuildRawSelect<S extends Record<string, any>, Columns extends readonly Selectable[]> = (typeof RAW_SELECT_BRAND extends keyof S ? S : {}) & BuildRawSelectType<Columns>;
|
|
4190
4131
|
type WhereOnlyQueryBuilder<T extends Model> = Pick<WhereQueryBuilder<T>, "where" | "andWhere" | "orWhere" | "whereNot" | "andWhereNot" | "orWhereNot" | "whereIn" | "andWhereIn" | "orWhereIn" | "whereNotIn" | "andWhereNotIn" | "orWhereNotIn" | "whereBetween" | "andWhereBetween" | "orWhereBetween" | "whereNotBetween" | "andWhereNotBetween" | "orWhereNotBetween" | "whereNull" | "andWhereNull" | "orWhereNull" | "whereNotNull" | "andWhereNotNull" | "orWhereNotNull" | "whereLike" | "andWhereLike" | "orWhereLike" | "whereILike" | "andWhereILike" | "orWhereILike" | "whereNotLike" | "andWhereNotLike" | "orWhereNotLike" | "whereNotILike" | "andWhereNotILike" | "orWhereNotILike" | "whereRegexp" | "andWhereRegexp" | "orWhereRegexp" | "whereNotRegexp" | "andWhereNotRegexp" | "orWhereNotRegexp" | "whereRaw" | "andWhereRaw" | "orWhereRaw" | "whereExists" | "orWhereExists" | "andWhereExists"> & Pick<JsonQueryBuilder<T>, "whereJson" | "andWhereJson" | "orWhereJson" | "whereJsonContains" | "andWhereJsonContains" | "orWhereJsonContains" | "whereJsonNotContains" | "andWhereJsonNotContains" | "orWhereJsonNotContains" | "whereJsonNotContains" | "andWhereJsonNotContains" | "orWhereJsonNotContains" | "whereJsonRaw" | "andWhereJsonRaw" | "orWhereJsonRaw" | "whereJsonNotContains" | "andWhereJsonNotContains" | "orWhereJsonNotContains">;
|
|
4191
4132
|
type RelationRetrieveMethod<P extends any> = P extends any[] ? "many" : "one";
|
|
4192
|
-
|
|
4133
|
+
/**
|
|
4134
|
+
* Validates a column string for raw query builder select().
|
|
4135
|
+
* Use [column, alias] tuple format for aliases instead of "column as alias".
|
|
4136
|
+
* Use selectFunction() for SQL functions instead of embedding them in select().
|
|
4137
|
+
*/
|
|
4138
|
+
type SelectableColumn$1<T extends string = string> = T extends `${string}.${string}.${string}` ? never : T extends `${string} ${string}` ? never : T extends `.${string}` | `${string}.` ? never : T extends `${string}-${string}` ? never : T extends `${string}.${string}` ? T : T;
|
|
4193
4139
|
/**
|
|
4194
4140
|
* @description A column that can be used in a join statement e.g. `users.id`
|
|
4195
4141
|
*/
|
|
@@ -4405,7 +4351,7 @@ declare class ModelQueryBuilder<T extends Model, S extends Record<string, any> =
|
|
|
4405
4351
|
}): Promise<PaginatedData<T, S, R>>;
|
|
4406
4352
|
/**
|
|
4407
4353
|
* @description Adds columns to the SELECT clause with full type safety.
|
|
4408
|
-
* @description Supports formats: "column", "table.column", "
|
|
4354
|
+
* @description Supports formats: "column", "table.column", "*", "table.*", or [column, alias] tuples
|
|
4409
4355
|
* @description When columns are selected, the return type reflects only those columns
|
|
4410
4356
|
* @warning This only allows selecting columns that are part of the model. For other columns, use `selectRaw`.
|
|
4411
4357
|
* @example
|
|
@@ -4413,14 +4359,14 @@ declare class ModelQueryBuilder<T extends Model, S extends Record<string, any> =
|
|
|
4413
4359
|
* // Select specific columns - return type is { id: number, name: string }
|
|
4414
4360
|
* const users = await User.query().select("id", "name").many();
|
|
4415
4361
|
*
|
|
4416
|
-
* // Select with alias - return type includes the alias
|
|
4417
|
-
* const users = await User.query().select("id
|
|
4362
|
+
* // Select with alias using tuple - return type includes the alias
|
|
4363
|
+
* const users = await User.query().select(["id", "userId"]).many();
|
|
4418
4364
|
*
|
|
4419
4365
|
* // Select all - return type is the full model
|
|
4420
4366
|
* const users = await User.query().select("*").many();
|
|
4421
4367
|
* ```
|
|
4422
4368
|
*/
|
|
4423
|
-
select<Columns extends readonly
|
|
4369
|
+
select<const Columns extends readonly ModelSelectableInput<T>[]>(...columns: Columns): ModelQueryBuilder<T, ComposeBuildSelect<S, T, Columns extends readonly (string | readonly [string, string])[] ? Columns : readonly (string | readonly [string, string])[]>, R>;
|
|
4424
4370
|
/**
|
|
4425
4371
|
* @description Adds a raw SELECT statement with type-safe return type.
|
|
4426
4372
|
* @description Use the generic parameter to specify the type of the selected columns.
|
|
@@ -4441,6 +4387,30 @@ declare class ModelQueryBuilder<T extends Model, S extends Record<string, any> =
|
|
|
4441
4387
|
* ```
|
|
4442
4388
|
*/
|
|
4443
4389
|
selectRaw<Added extends Record<string, any> = Record<string, any>>(statement: string): ModelQueryBuilder<T, ComposeSelect<S, Added>, R>;
|
|
4390
|
+
/**
|
|
4391
|
+
* @description Selects a SQL function applied to a column with a typed alias.
|
|
4392
|
+
* @description Provides intellisense for common SQL functions while accepting any custom function.
|
|
4393
|
+
* @description Return type is auto-inferred based on function name (number for count/sum/avg, string for upper/lower/trim, etc.)
|
|
4394
|
+
* @param sqlFunc The SQL function name (count, sum, avg, min, max, upper, lower, etc.)
|
|
4395
|
+
* @param column The column to apply the function to (use "*" for count(*))
|
|
4396
|
+
* @param alias The alias for the result
|
|
4397
|
+
* @example
|
|
4398
|
+
* ```ts
|
|
4399
|
+
* const users = await User.query()
|
|
4400
|
+
* .selectFunc("count", "*", "total")
|
|
4401
|
+
* .many();
|
|
4402
|
+
* // users[0].total is typed as number - auto-inferred!
|
|
4403
|
+
*
|
|
4404
|
+
* const users = await User.query()
|
|
4405
|
+
* .select("id")
|
|
4406
|
+
* .selectFunc("upper", "name", "upperName")
|
|
4407
|
+
* .many();
|
|
4408
|
+
* // users[0] is { id: number, upperName: string } - auto-inferred!
|
|
4409
|
+
* ```
|
|
4410
|
+
*/
|
|
4411
|
+
selectFunc<F extends SqlFunction, Alias extends string>(sqlFunc: F, column: ModelKey<T> | "*" | (string & {}), alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4412
|
+
[K in Alias]: SqlFunctionReturnType<F>;
|
|
4413
|
+
}>, R>;
|
|
4444
4414
|
/**
|
|
4445
4415
|
* @description Selects a subquery with a typed alias
|
|
4446
4416
|
* @param cbOrQueryBuilder A callback that receives a QueryBuilder or a QueryBuilder instance
|
|
@@ -4666,241 +4636,6 @@ declare class ModelQueryBuilder<T extends Model, S extends Record<string, any> =
|
|
|
4666
4636
|
selectJsonRaw<ValueType = any, Alias extends string = string>(raw: string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4667
4637
|
[K in Alias]: ValueType;
|
|
4668
4638
|
}>, R>;
|
|
4669
|
-
/**
|
|
4670
|
-
* @description Selects COUNT(column) with a typed alias
|
|
4671
|
-
* @param column The column to count (use "*" for COUNT(*), supports "table.column" format)
|
|
4672
|
-
* @param alias The alias for the count result
|
|
4673
|
-
* @example
|
|
4674
|
-
* ```ts
|
|
4675
|
-
* // Count all rows
|
|
4676
|
-
* const result = await User.query().selectCount("*", "totalUsers").one();
|
|
4677
|
-
* console.log(result?.totalUsers); // Typed as number
|
|
4678
|
-
*
|
|
4679
|
-
* // Count specific column
|
|
4680
|
-
* const result = await User.query().selectCount("id", "userCount").one();
|
|
4681
|
-
*
|
|
4682
|
-
* // With table prefix
|
|
4683
|
-
* const result = await User.query().selectCount("users.id", "total").one();
|
|
4684
|
-
* ```
|
|
4685
|
-
*/
|
|
4686
|
-
selectCount<Alias extends string>(column: ModelKey<T> | "*" | string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4687
|
-
[K in Alias]: number;
|
|
4688
|
-
}>, R>;
|
|
4689
|
-
/**
|
|
4690
|
-
* @description Selects SUM(column) with a typed alias
|
|
4691
|
-
* @param column The column to sum (supports "table.column" format)
|
|
4692
|
-
* @param alias The alias for the sum result
|
|
4693
|
-
* @example
|
|
4694
|
-
* ```ts
|
|
4695
|
-
* const result = await Order.query().selectSum("amount", "totalAmount").one();
|
|
4696
|
-
* console.log(result?.totalAmount); // Typed as number
|
|
4697
|
-
*
|
|
4698
|
-
* // With table prefix
|
|
4699
|
-
* const result = await Order.query().selectSum("orders.amount", "total").one();
|
|
4700
|
-
* ```
|
|
4701
|
-
*/
|
|
4702
|
-
selectSum<Alias extends string>(column: ModelKey<T> | string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4703
|
-
[K in Alias]: number;
|
|
4704
|
-
}>, R>;
|
|
4705
|
-
/**
|
|
4706
|
-
* @description Selects AVG(column) with a typed alias
|
|
4707
|
-
* @param column The column to average (supports "table.column" format)
|
|
4708
|
-
* @param alias The alias for the average result
|
|
4709
|
-
* @example
|
|
4710
|
-
* ```ts
|
|
4711
|
-
* const result = await User.query().selectAvg("age", "averageAge").one();
|
|
4712
|
-
* console.log(result?.averageAge); // Typed as number
|
|
4713
|
-
*
|
|
4714
|
-
* // With table prefix
|
|
4715
|
-
* const result = await User.query().selectAvg("users.age", "avgAge").one();
|
|
4716
|
-
* ```
|
|
4717
|
-
*/
|
|
4718
|
-
selectAvg<Alias extends string>(column: ModelKey<T> | string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4719
|
-
[K in Alias]: number;
|
|
4720
|
-
}>, R>;
|
|
4721
|
-
/**
|
|
4722
|
-
* @description Selects MIN(column) with a typed alias
|
|
4723
|
-
* @param column The column to get minimum value (supports "table.column" format)
|
|
4724
|
-
* @param alias The alias for the min result
|
|
4725
|
-
* @example
|
|
4726
|
-
* ```ts
|
|
4727
|
-
* const result = await User.query().selectMin("age", "youngestAge").one();
|
|
4728
|
-
* console.log(result?.youngestAge); // Typed as number
|
|
4729
|
-
*
|
|
4730
|
-
* // With table prefix
|
|
4731
|
-
* const result = await User.query().selectMin("users.age", "minAge").one();
|
|
4732
|
-
* ```
|
|
4733
|
-
*/
|
|
4734
|
-
selectMin<Alias extends string>(column: ModelKey<T> | string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4735
|
-
[K in Alias]: number;
|
|
4736
|
-
}>, R>;
|
|
4737
|
-
/**
|
|
4738
|
-
* @description Selects MAX(column) with a typed alias
|
|
4739
|
-
* @param column The column to get maximum value (supports "table.column" format)
|
|
4740
|
-
* @param alias The alias for the max result
|
|
4741
|
-
* @example
|
|
4742
|
-
* ```ts
|
|
4743
|
-
* const result = await User.query().selectMax("age", "oldestAge").one();
|
|
4744
|
-
* console.log(result?.oldestAge); // Typed as number
|
|
4745
|
-
*
|
|
4746
|
-
* // With table prefix
|
|
4747
|
-
* const result = await User.query().selectMax("users.age", "maxAge").one();
|
|
4748
|
-
* ```
|
|
4749
|
-
*/
|
|
4750
|
-
selectMax<Alias extends string>(column: ModelKey<T> | string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4751
|
-
[K in Alias]: number;
|
|
4752
|
-
}>, R>;
|
|
4753
|
-
/**
|
|
4754
|
-
* @description Selects COUNT(DISTINCT column) with a typed alias
|
|
4755
|
-
* @param column The column to count distinct values (supports "table.column" format)
|
|
4756
|
-
* @param alias The alias for the count result
|
|
4757
|
-
* @example
|
|
4758
|
-
* ```ts
|
|
4759
|
-
* const result = await User.query().selectCountDistinct("email", "uniqueEmails").one();
|
|
4760
|
-
* console.log(result?.uniqueEmails); // Typed as number
|
|
4761
|
-
* ```
|
|
4762
|
-
*/
|
|
4763
|
-
selectCountDistinct<Alias extends string>(column: ModelKey<T> | string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4764
|
-
[K in Alias]: number;
|
|
4765
|
-
}>, R>;
|
|
4766
|
-
/**
|
|
4767
|
-
* @description Selects UPPER(column) with a typed alias
|
|
4768
|
-
* @param column The column to convert to uppercase
|
|
4769
|
-
* @param alias The alias for the result
|
|
4770
|
-
* @example
|
|
4771
|
-
* ```ts
|
|
4772
|
-
* const result = await User.query().selectUpper("name", "upperName").one();
|
|
4773
|
-
* console.log(result?.upperName); // Typed as string
|
|
4774
|
-
* ```
|
|
4775
|
-
*/
|
|
4776
|
-
selectUpper<Alias extends string>(column: ModelKey<T> | string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4777
|
-
[K in Alias]: string;
|
|
4778
|
-
}>, R>;
|
|
4779
|
-
/**
|
|
4780
|
-
* @description Selects LOWER(column) with a typed alias
|
|
4781
|
-
* @param column The column to convert to lowercase
|
|
4782
|
-
* @param alias The alias for the result
|
|
4783
|
-
* @example
|
|
4784
|
-
* ```ts
|
|
4785
|
-
* const result = await User.query().selectLower("name", "lowerName").one();
|
|
4786
|
-
* console.log(result?.lowerName); // Typed as string
|
|
4787
|
-
* ```
|
|
4788
|
-
*/
|
|
4789
|
-
selectLower<Alias extends string>(column: ModelKey<T> | string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4790
|
-
[K in Alias]: string;
|
|
4791
|
-
}>, R>;
|
|
4792
|
-
/**
|
|
4793
|
-
* @description Selects LENGTH(column) with a typed alias
|
|
4794
|
-
* @param column The column to get length of
|
|
4795
|
-
* @param alias The alias for the result
|
|
4796
|
-
* @note MSSQL uses LEN() instead of LENGTH(), handled automatically
|
|
4797
|
-
* @example
|
|
4798
|
-
* ```ts
|
|
4799
|
-
* const result = await User.query().selectLength("name", "nameLength").one();
|
|
4800
|
-
* console.log(result?.nameLength); // Typed as number
|
|
4801
|
-
* ```
|
|
4802
|
-
*/
|
|
4803
|
-
selectLength<Alias extends string>(column: ModelKey<T> | string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4804
|
-
[K in Alias]: number;
|
|
4805
|
-
}>, R>;
|
|
4806
|
-
/**
|
|
4807
|
-
* @description Selects TRIM(column) with a typed alias
|
|
4808
|
-
* @param column The column to trim whitespace from
|
|
4809
|
-
* @param alias The alias for the result
|
|
4810
|
-
* @example
|
|
4811
|
-
* ```ts
|
|
4812
|
-
* const result = await User.query().selectTrim("name", "trimmedName").one();
|
|
4813
|
-
* console.log(result?.trimmedName); // Typed as string
|
|
4814
|
-
* ```
|
|
4815
|
-
*/
|
|
4816
|
-
selectTrim<Alias extends string>(column: ModelKey<T> | string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4817
|
-
[K in Alias]: string;
|
|
4818
|
-
}>, R>;
|
|
4819
|
-
/**
|
|
4820
|
-
* @description Selects ABS(column) with a typed alias
|
|
4821
|
-
* @param column The column to get absolute value of
|
|
4822
|
-
* @param alias The alias for the result
|
|
4823
|
-
* @example
|
|
4824
|
-
* ```ts
|
|
4825
|
-
* const result = await Order.query().selectAbs("balance", "absoluteBalance").one();
|
|
4826
|
-
* console.log(result?.absoluteBalance); // Typed as number
|
|
4827
|
-
* ```
|
|
4828
|
-
*/
|
|
4829
|
-
selectAbs<Alias extends string>(column: ModelKey<T> | string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4830
|
-
[K in Alias]: number;
|
|
4831
|
-
}>, R>;
|
|
4832
|
-
/**
|
|
4833
|
-
* @description Selects ROUND(column, decimals) with a typed alias
|
|
4834
|
-
* @param column The column to round
|
|
4835
|
-
* @param decimals Number of decimal places
|
|
4836
|
-
* @param alias The alias for the result
|
|
4837
|
-
* @postgres Not fully supported - ROUND with precision requires NUMERIC type, not REAL/FLOAT
|
|
4838
|
-
* @cockroachdb Not fully supported - ROUND with precision requires NUMERIC type, not REAL/FLOAT
|
|
4839
|
-
* @example
|
|
4840
|
-
* ```ts
|
|
4841
|
-
* const result = await Order.query().selectRound("price", 2, "roundedPrice").one();
|
|
4842
|
-
* console.log(result?.roundedPrice); // Typed as number
|
|
4843
|
-
* ```
|
|
4844
|
-
*/
|
|
4845
|
-
selectRound<Alias extends string>(column: ModelKey<T> | string, decimals: number, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4846
|
-
[K in Alias]: number;
|
|
4847
|
-
}>, R>;
|
|
4848
|
-
/**
|
|
4849
|
-
* @description Selects COALESCE(column, defaultValue) with a typed alias
|
|
4850
|
-
* @param column The column to check for NULL
|
|
4851
|
-
* @param defaultValue The value to use if column is NULL
|
|
4852
|
-
* @param alias The alias for the result
|
|
4853
|
-
* @example
|
|
4854
|
-
* ```ts
|
|
4855
|
-
* const result = await User.query().selectCoalesce("nickname", "'Unknown'", "displayName").one();
|
|
4856
|
-
* console.log(result?.displayName); // Typed as any (depends on column type)
|
|
4857
|
-
* ```
|
|
4858
|
-
*/
|
|
4859
|
-
selectCoalesce<Alias extends string>(column: ModelKey<T> | string, defaultValue: string | number, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4860
|
-
[K in Alias]: any;
|
|
4861
|
-
}>, R>;
|
|
4862
|
-
/**
|
|
4863
|
-
* @description Selects CEIL(column) with a typed alias (rounds up to nearest integer)
|
|
4864
|
-
* @param column The column to round up
|
|
4865
|
-
* @param alias The alias for the result
|
|
4866
|
-
* @sqlite Not supported - SQLite does not have a native CEIL function
|
|
4867
|
-
* @mssql Uses CEILING instead of CEIL (handled automatically)
|
|
4868
|
-
* @example
|
|
4869
|
-
* ```ts
|
|
4870
|
-
* const result = await Order.query().selectCeil("price", "ceilPrice").one();
|
|
4871
|
-
* console.log(result?.ceilPrice); // Typed as number
|
|
4872
|
-
* ```
|
|
4873
|
-
*/
|
|
4874
|
-
selectCeil<Alias extends string>(column: ModelKey<T> | string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4875
|
-
[K in Alias]: number;
|
|
4876
|
-
}>, R>;
|
|
4877
|
-
/**
|
|
4878
|
-
* @description Selects FLOOR(column) with a typed alias (rounds down to nearest integer)
|
|
4879
|
-
* @param column The column to round down
|
|
4880
|
-
* @param alias The alias for the result
|
|
4881
|
-
* @sqlite Not supported - SQLite does not have a native FLOOR function
|
|
4882
|
-
* @example
|
|
4883
|
-
* ```ts
|
|
4884
|
-
* const result = await Order.query().selectFloor("price", "floorPrice").one();
|
|
4885
|
-
* console.log(result?.floorPrice); // Typed as number
|
|
4886
|
-
* ```
|
|
4887
|
-
*/
|
|
4888
|
-
selectFloor<Alias extends string>(column: ModelKey<T> | string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4889
|
-
[K in Alias]: number;
|
|
4890
|
-
}>, R>;
|
|
4891
|
-
/**
|
|
4892
|
-
* @description Selects SQRT(column) with a typed alias (square root)
|
|
4893
|
-
* @param column The column to get square root of
|
|
4894
|
-
* @param alias The alias for the result
|
|
4895
|
-
* @example
|
|
4896
|
-
* ```ts
|
|
4897
|
-
* const result = await Data.query().selectSqrt("value", "sqrtValue").one();
|
|
4898
|
-
* console.log(result?.sqrtValue); // Typed as number
|
|
4899
|
-
* ```
|
|
4900
|
-
*/
|
|
4901
|
-
selectSqrt<Alias extends string>(column: ModelKey<T> | string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4902
|
-
[K in Alias]: number;
|
|
4903
|
-
}>, R>;
|
|
4904
4639
|
/**
|
|
4905
4640
|
* @description Fills the relations in the model in the serialized response. Relation must be defined in the model.
|
|
4906
4641
|
* @warning Many to many relations have special behavior, since they require a join, a join clause will always be added to the query.
|
|
@@ -5680,7 +5415,117 @@ type ExcludeMethods<T> = {
|
|
|
5680
5415
|
* like save(), delete(), refresh() are not incorrectly included.
|
|
5681
5416
|
*/
|
|
5682
5417
|
type ModelDataProperties = Pick<Model, ExcludeMethods<Model>>;
|
|
5418
|
+
/**
|
|
5419
|
+
* Model instance methods available on query results.
|
|
5420
|
+
* These methods enable CRUD operations on fetched models.
|
|
5421
|
+
*
|
|
5422
|
+
* All query results from Model static methods (find, findOne, findOneOrFail,
|
|
5423
|
+
* findBy, findOneBy, findOneByPrimaryKey, all, first, insert, insertMany,
|
|
5424
|
+
* upsert, upsertMany, updateRecord, softDelete) and from ModelQueryBuilder
|
|
5425
|
+
* (one, many, oneOrFail) include these instance methods.
|
|
5426
|
+
*
|
|
5427
|
+
* @example
|
|
5428
|
+
* ```typescript
|
|
5429
|
+
* // Using instance methods on query results
|
|
5430
|
+
* const user = await User.findOne({ where: { email: "test@example.com" } });
|
|
5431
|
+
* if (user) {
|
|
5432
|
+
* user.mergeProps({ name: "Updated Name" });
|
|
5433
|
+
* await user.save();
|
|
5434
|
+
*
|
|
5435
|
+
* // Or update directly
|
|
5436
|
+
* await user.update({ name: "Another Name" });
|
|
5437
|
+
*
|
|
5438
|
+
* // Refresh from database
|
|
5439
|
+
* await user.refresh();
|
|
5440
|
+
*
|
|
5441
|
+
* // Soft delete or hard delete
|
|
5442
|
+
* await user.softDelete();
|
|
5443
|
+
* // or: await user.delete();
|
|
5444
|
+
* }
|
|
5445
|
+
*
|
|
5446
|
+
* // Works with query builder too
|
|
5447
|
+
* const user2 = await User.query().where("id", 1).oneOrFail();
|
|
5448
|
+
* await user2.update({ status: "inactive" });
|
|
5449
|
+
*
|
|
5450
|
+
* // Works with select projections
|
|
5451
|
+
* const user3 = await User.query().select("id", "name").one();
|
|
5452
|
+
* if (user3) {
|
|
5453
|
+
* await user3.delete(); // Still has access to instance methods
|
|
5454
|
+
* }
|
|
5455
|
+
* ```
|
|
5456
|
+
*
|
|
5457
|
+
* Note: These signatures are simplified versions that don't carry the
|
|
5458
|
+
* `this: T extends Model` constraint, allowing them to work on selected
|
|
5459
|
+
* model results without requiring full Model type compatibility.
|
|
5460
|
+
*/
|
|
5461
|
+
type ModelInstanceMethods<T extends Model> = {
|
|
5462
|
+
/**
|
|
5463
|
+
* Merges the provided data with the model instance.
|
|
5464
|
+
* Does not persist to database - use save() or update() after merging.
|
|
5465
|
+
*/
|
|
5466
|
+
mergeProps: (data: Partial<ModelWithoutRelations<T>>) => void;
|
|
5467
|
+
/**
|
|
5468
|
+
* Saves the model to the database (insert or update based on primary key).
|
|
5469
|
+
* @throws {HysteriaError} If the model has no primary key defined
|
|
5470
|
+
*/
|
|
5471
|
+
save: (options?: Omit<BaseModelMethodOptions, "ignoreHooks">) => Promise<any>;
|
|
5472
|
+
/**
|
|
5473
|
+
* Updates the model in the database with the provided payload.
|
|
5474
|
+
* @throws {HysteriaError} If the model has no primary key or primary key value
|
|
5475
|
+
*/
|
|
5476
|
+
update: (payload: Partial<ModelWithoutRelations<T>>, options?: Omit<BaseModelMethodOptions, "ignoreHooks">) => Promise<void>;
|
|
5477
|
+
/**
|
|
5478
|
+
* Soft deletes the model by setting the soft delete column.
|
|
5479
|
+
* @throws {HysteriaError} If the model has no primary key or primary key value
|
|
5480
|
+
*/
|
|
5481
|
+
softDelete: (softDeleteOptions?: {
|
|
5482
|
+
column?: string;
|
|
5483
|
+
value?: string | number | boolean | Date;
|
|
5484
|
+
}, options?: Omit<BaseModelMethodOptions, "ignoreHooks">) => Promise<void>;
|
|
5485
|
+
/**
|
|
5486
|
+
* Hard deletes the model from the database.
|
|
5487
|
+
* @throws {HysteriaError} If the model has no primary key or primary key value
|
|
5488
|
+
*/
|
|
5489
|
+
delete: (options?: Omit<BaseModelMethodOptions, "ignoreHooks">) => Promise<void>;
|
|
5490
|
+
/**
|
|
5491
|
+
* Refreshes the model from the database, updating all properties with current values.
|
|
5492
|
+
* @throws {HysteriaError} If the model has no primary key or primary key value
|
|
5493
|
+
*/
|
|
5494
|
+
refresh: (options?: Omit<BaseModelMethodOptions, "ignoreHooks">) => Promise<any>;
|
|
5495
|
+
};
|
|
5496
|
+
/**
|
|
5497
|
+
* Model data without relation properties.
|
|
5498
|
+
* Includes only data columns from the model, excluding foreign keys and relation accessors.
|
|
5499
|
+
*/
|
|
5683
5500
|
type ModelWithoutRelations<T extends Model> = Pick<Omit<T, "*">, ExcludeRelations<Omit<T, "*">>> & ModelDataProperties;
|
|
5501
|
+
/**
|
|
5502
|
+
* Return type for Model query/mutation methods.
|
|
5503
|
+
* Combines data properties with instance methods for CRUD operations.
|
|
5504
|
+
*
|
|
5505
|
+
* This type is used as the return type for:
|
|
5506
|
+
* - Static find methods: find, findOne, findOneOrFail, findBy, findOneBy, findOneByPrimaryKey
|
|
5507
|
+
* - Static retrieval methods: all, first
|
|
5508
|
+
* - Static mutation methods: insert, insertMany, upsert, upsertMany, updateRecord, softDelete
|
|
5509
|
+
* - Static refresh method: refresh
|
|
5510
|
+
*
|
|
5511
|
+
* @example
|
|
5512
|
+
* ```typescript
|
|
5513
|
+
* // All these methods return ModelQueryResult<User> (or arrays/nullables thereof)
|
|
5514
|
+
* const user1 = await User.findOne({ where: { id: 1 } });
|
|
5515
|
+
* const user2 = await User.findOneOrFail({ where: { id: 1 } });
|
|
5516
|
+
* const users = await User.find({});
|
|
5517
|
+
* const allUsers = await User.all();
|
|
5518
|
+
* const newUser = await User.insert({ name: "John" });
|
|
5519
|
+
*
|
|
5520
|
+
* // Each result has instance methods available
|
|
5521
|
+
* if (user1) {
|
|
5522
|
+
* await user1.update({ name: "Jane" });
|
|
5523
|
+
* await user1.refresh();
|
|
5524
|
+
* await user1.delete();
|
|
5525
|
+
* }
|
|
5526
|
+
* ```
|
|
5527
|
+
*/
|
|
5528
|
+
type ModelQueryResult<T extends Model> = ModelWithoutRelations<T> & ModelInstanceMethods<T>;
|
|
5684
5529
|
type NumberModelKey<T extends Model> = {
|
|
5685
5530
|
[K in keyof T]: T[K] extends number | bigint ? K : never;
|
|
5686
5531
|
}[keyof T];
|
|
@@ -5779,7 +5624,9 @@ type RelatedInstance<M extends Model, K extends ModelRelation<M>> = NonNullable<
|
|
|
5779
5624
|
*/
|
|
5780
5625
|
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
5781
5626
|
/**
|
|
5782
|
-
* Represents
|
|
5627
|
+
* Represents valid string column selection formats with intellisense support.
|
|
5628
|
+
* Use [column, alias] tuple format for aliases instead of "column as alias".
|
|
5629
|
+
* Use selectFunction() for SQL functions instead of embedding them in select().
|
|
5783
5630
|
*
|
|
5784
5631
|
* ## Supported Formats
|
|
5785
5632
|
*
|
|
@@ -5787,7 +5634,6 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
|
5787
5634
|
* |---------------------------|--------------------------|--------------------------------|
|
|
5788
5635
|
* | Model column | `"name"` | Direct column with intellisense |
|
|
5789
5636
|
* | Qualified column | `"users.name"` | Table-prefixed column |
|
|
5790
|
-
* | Aliased column | `"name as userName"` | Column with custom alias |
|
|
5791
5637
|
* | Wildcard | `"*"` | Select all from primary table |
|
|
5792
5638
|
* | Table wildcard | `"users.*"` | Select all from specific table |
|
|
5793
5639
|
*
|
|
@@ -5795,17 +5641,32 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
|
5795
5641
|
* User.query().select(
|
|
5796
5642
|
* "name", // Model column with intellisense
|
|
5797
5643
|
* "users.email", // Qualified column
|
|
5798
|
-
* "age as userAge", // Aliased column
|
|
5799
5644
|
* "*" // All columns
|
|
5800
5645
|
* );
|
|
5801
5646
|
*/
|
|
5802
|
-
type SelectableColumn<T extends Model> = ModelKey<T> | `${string}.${string | "*"}` |
|
|
5647
|
+
type SelectableColumn<T extends Model> = ModelKey<T> | `${string}.${string | "*"}` | "*";
|
|
5803
5648
|
/**
|
|
5804
|
-
*
|
|
5649
|
+
* A tuple type for selecting a column with an alias in ModelQueryBuilder.
|
|
5650
|
+
* @example ["id", "userId"] selects "id" column as "userId"
|
|
5651
|
+
*/
|
|
5652
|
+
type ModelSelectTuple<T extends Model, C extends ModelKey<T> | `${string}.${string}` = ModelKey<T> | `${string}.${string}`, A extends string = string> = readonly [column: C, alias: A];
|
|
5653
|
+
/**
|
|
5654
|
+
* Input type for select() method in ModelQueryBuilder.
|
|
5655
|
+
* Accepts either a column string or a [column, alias] tuple for aliasing.
|
|
5656
|
+
*
|
|
5657
|
+
* @example
|
|
5658
|
+
* .select("id", "name") // Simple columns
|
|
5659
|
+
* .select(["id", "userId"], ["name", "userName"]) // Columns with aliases
|
|
5660
|
+
* .select("id", ["name", "userName"]) // Mixed
|
|
5661
|
+
*/
|
|
5662
|
+
type ModelSelectableInput<T extends Model> = SelectableColumn<T> | ModelSelectTuple<T>;
|
|
5663
|
+
/**
|
|
5664
|
+
* Extracts the final property name from a column selection.
|
|
5665
|
+
* Supports both string columns and [column, alias] tuples.
|
|
5805
5666
|
*
|
|
5806
5667
|
* This type determines what property name will be available on the result:
|
|
5807
5668
|
* - Plain columns use their name directly
|
|
5808
|
-
* -
|
|
5669
|
+
* - Tuples use the alias (second element)
|
|
5809
5670
|
* - Wildcards return `never` (handled specially to return full model)
|
|
5810
5671
|
*
|
|
5811
5672
|
* ## Extraction Rules
|
|
@@ -5814,12 +5675,26 @@ type SelectableColumn<T extends Model> = ModelKey<T> | `${string}.${string | "*"
|
|
|
5814
5675
|
* |--------------------------|---------------|--------------------------------|
|
|
5815
5676
|
* | `"name"` | `"name"` | Direct column |
|
|
5816
5677
|
* | `"users.name"` | `"name"` | Extract column from qualified |
|
|
5817
|
-
* | `"name
|
|
5818
|
-
* | `"users.
|
|
5678
|
+
* | `["name", "userName"]` | `"userName"` | Use alias from tuple |
|
|
5679
|
+
* | `["users.id", "id"]` | `"id"` | Use alias from tuple |
|
|
5819
5680
|
* | `"*"` | `never` | Wildcard - full model |
|
|
5820
5681
|
* | `"users.*"` | `never` | Table wildcard - Record<> |
|
|
5821
5682
|
*/
|
|
5822
|
-
type ExtractColumnName<S
|
|
5683
|
+
type ExtractColumnName<S> = S extends readonly [
|
|
5684
|
+
string,
|
|
5685
|
+
infer Alias extends string
|
|
5686
|
+
] ? Alias : S extends string ? S extends "*" ? never : S extends `${string}.*` ? never : S extends `${string}.${infer Column}` ? Column extends "*" ? never : Column : S : never;
|
|
5687
|
+
/**
|
|
5688
|
+
* Extracts the source column name from a selectable input.
|
|
5689
|
+
* For strings, returns the column part (after last dot if qualified).
|
|
5690
|
+
* For tuples, returns the first element (the column).
|
|
5691
|
+
*
|
|
5692
|
+
* @internal
|
|
5693
|
+
*/
|
|
5694
|
+
type ExtractSourceColumn<S> = S extends readonly [
|
|
5695
|
+
infer Column extends string,
|
|
5696
|
+
string
|
|
5697
|
+
] ? Column extends `${string}.${infer Col}` ? Col : Column : S extends string ? S extends `${string}.${infer Column}` ? Column : S : never;
|
|
5823
5698
|
/**
|
|
5824
5699
|
* Resolves the TypeScript type for a selected column.
|
|
5825
5700
|
*
|
|
@@ -5834,28 +5709,34 @@ type ExtractColumnName<S extends string> = S extends `${string} as ${infer Alias
|
|
|
5834
5709
|
type GetColumnType<T extends Model, ColumnName extends string> = ColumnName extends keyof ModelWithoutRelations<T> ? ModelWithoutRelations<T>[ColumnName] : any;
|
|
5835
5710
|
/**
|
|
5836
5711
|
* Builds the type for a single selected column.
|
|
5712
|
+
* Supports both string columns and [column, alias] tuples.
|
|
5837
5713
|
*
|
|
5838
5714
|
* ## Type Resolution
|
|
5839
5715
|
*
|
|
5840
|
-
* | Selection
|
|
5841
|
-
*
|
|
5842
|
-
* | `"*"`
|
|
5843
|
-
* | `"table.*"`
|
|
5844
|
-
* | `"column"`
|
|
5845
|
-
* | `"col
|
|
5716
|
+
* | Selection | Result Type |
|
|
5717
|
+
* |------------------------|---------------------------------------|
|
|
5718
|
+
* | `"*"` | `ModelWithoutRelations<T>` (full) |
|
|
5719
|
+
* | `"table.*"` | `Record<string, any>` (unknown shape) |
|
|
5720
|
+
* | `"column"` | `{ column: ColumnType }` |
|
|
5721
|
+
* | `["col", "alias"]` | `{ alias: ColumnType }` |
|
|
5846
5722
|
*
|
|
5847
5723
|
* @internal
|
|
5848
5724
|
*/
|
|
5849
|
-
type BuildSingleSelectType<T extends Model, S
|
|
5850
|
-
|
|
5851
|
-
|
|
5725
|
+
type BuildSingleSelectType<T extends Model, S> = S extends readonly [
|
|
5726
|
+
infer Column extends string,
|
|
5727
|
+
infer Alias extends string
|
|
5728
|
+
] ? {
|
|
5729
|
+
[K in Alias]: GetColumnType<T, ExtractSourceColumn<S> & string>;
|
|
5730
|
+
} : S extends string ? S extends "*" ? ModelWithoutRelations<T> : S extends `${string}.*` ? Record<string, any> : ExtractColumnName<S> extends never ? {} : {
|
|
5731
|
+
[K in ExtractColumnName<S> & string]: GetColumnType<T, ExtractColumnName<S> & string>;
|
|
5732
|
+
} : {};
|
|
5852
5733
|
/**
|
|
5853
5734
|
* Checks if a column selection includes wildcards or is empty.
|
|
5854
5735
|
* Used to determine if the full model type should be returned.
|
|
5855
5736
|
*
|
|
5856
5737
|
* @internal
|
|
5857
5738
|
*/
|
|
5858
|
-
type HasStarOrEmpty<Columns extends readonly string[]> = Columns["length"] extends 0 ? true : "*" extends Columns[number] ? true : false;
|
|
5739
|
+
type HasStarOrEmpty<Columns extends readonly (string | readonly [string, string])[]> = Columns["length"] extends 0 ? true : "*" extends Columns[number] ? true : false;
|
|
5859
5740
|
/**
|
|
5860
5741
|
* Unique symbol used internally to mark that a select() has been called.
|
|
5861
5742
|
*/
|
|
@@ -5873,6 +5754,7 @@ type SelectBrand = {
|
|
|
5873
5754
|
};
|
|
5874
5755
|
/**
|
|
5875
5756
|
* Builds the combined TypeScript type for multiple selected columns.
|
|
5757
|
+
* Supports both string columns and [column, alias] tuples.
|
|
5876
5758
|
*
|
|
5877
5759
|
* This is the main type used to compute the return type of `select()` calls.
|
|
5878
5760
|
* It handles all the complexity of combining multiple column selections into
|
|
@@ -5886,8 +5768,8 @@ type SelectBrand = {
|
|
|
5886
5768
|
* 4. **Always includes**: Base `Model` methods (save, delete, etc.)
|
|
5887
5769
|
*
|
|
5888
5770
|
* @example
|
|
5889
|
-
* // .select("name", "age
|
|
5890
|
-
* BuildSelectType<User, ["name", "age
|
|
5771
|
+
* // .select("name", ["age", "userAge"])
|
|
5772
|
+
* BuildSelectType<User, ["name", ["age", "userAge"]]>
|
|
5891
5773
|
* // Result: { name: string; userAge: number } & Pick<Model, keyof Model>
|
|
5892
5774
|
*
|
|
5893
5775
|
* @example
|
|
@@ -5895,8 +5777,8 @@ type SelectBrand = {
|
|
|
5895
5777
|
* BuildSelectType<User, ["*"]>
|
|
5896
5778
|
* // Result: ModelWithoutRelations<User> (all columns)
|
|
5897
5779
|
*/
|
|
5898
|
-
type BuildSelectType<T extends Model, Columns extends readonly string[]> = HasStarOrEmpty<Columns> extends true ? ModelWithoutRelations<T> : UnionToIntersection<{
|
|
5899
|
-
[K in keyof Columns]:
|
|
5780
|
+
type BuildSelectType<T extends Model, Columns extends readonly (string | readonly [string, string])[]> = HasStarOrEmpty<Columns> extends true ? ModelWithoutRelations<T> : UnionToIntersection<{
|
|
5781
|
+
[K in keyof Columns]: BuildSingleSelectType<T, Columns[K]>;
|
|
5900
5782
|
}[number]> extends infer Result ? Result extends Record<string, any> ? keyof Result extends never ? ModelWithoutRelations<T> : Result & ModelDataProperties & SelectBrand : ModelWithoutRelations<T> : ModelWithoutRelations<T>;
|
|
5901
5783
|
/**
|
|
5902
5784
|
* Composes a new selection with the existing selection state.
|
|
@@ -5923,6 +5805,7 @@ type BuildSelectType<T extends Model, Columns extends readonly string[]> = HasSt
|
|
|
5923
5805
|
type ComposeSelect<S extends Record<string, any>, Added extends Record<string, any>> = (typeof SELECT_BRAND extends keyof S ? S : ModelDataProperties & SelectBrand) & Added;
|
|
5924
5806
|
/**
|
|
5925
5807
|
* Composes a BuildSelectType result with the existing selection state.
|
|
5808
|
+
* Supports both string columns and [column, alias] tuples.
|
|
5926
5809
|
*
|
|
5927
5810
|
* Similar to ComposeSelect but designed for use with BuildSelectType which already
|
|
5928
5811
|
* includes Pick<Model, keyof Model> and SelectBrand in its result.
|
|
@@ -5945,21 +5828,24 @@ type ComposeSelect<S extends Record<string, any>, Added extends Record<string, a
|
|
|
5945
5828
|
* ComposeBuildSelect<{ count: number } & Pick<Model, keyof Model> & SelectBrand, User, ["id"]>
|
|
5946
5829
|
* // Result: { count: number } & Pick<Model, keyof Model> & SelectBrand & { id: number }
|
|
5947
5830
|
*/
|
|
5948
|
-
type ComposeBuildSelect<S extends Record<string, any>, T extends Model, Columns extends readonly string[]> = (typeof SELECT_BRAND extends keyof S ? S : {}) & BuildSelectType<T, Columns>;
|
|
5831
|
+
type ComposeBuildSelect<S extends Record<string, any>, T extends Model, Columns extends readonly (string | readonly [string, string])[]> = (typeof SELECT_BRAND extends keyof S ? S : {}) & BuildSelectType<T, Columns>;
|
|
5949
5832
|
/**
|
|
5950
5833
|
* The final result type for ModelQueryBuilder queries.
|
|
5951
5834
|
*
|
|
5952
|
-
* Combines selected columns (S) with loaded relations (R)
|
|
5835
|
+
* Combines selected columns (S) with loaded relations (R) and Model instance methods
|
|
5836
|
+
* into a single type. This ensures query results have access to CRUD operations
|
|
5837
|
+
* like save(), update(), delete(), etc.
|
|
5953
5838
|
*
|
|
5839
|
+
* @typeParam M - The Model type
|
|
5954
5840
|
* @typeParam S - Selected columns type from `select()` calls
|
|
5955
5841
|
* @typeParam R - Relations type from `load()` calls
|
|
5956
5842
|
*
|
|
5957
5843
|
* @example
|
|
5958
5844
|
* // User.query().select("name").load("posts").one()
|
|
5959
|
-
* SelectedModel<{ name: string }, { posts: Post[] }>
|
|
5960
|
-
* // Result: { name: string; posts: Post[] }
|
|
5845
|
+
* SelectedModel<User, { name: string }, { posts: Post[] }>
|
|
5846
|
+
* // Result: { name: string; posts: Post[] } & ModelInstanceMethods
|
|
5961
5847
|
*/
|
|
5962
|
-
type SelectedModel<M extends Model, S extends Record<string, any> = {}, R extends Record<string, any> = {}> = S & R
|
|
5848
|
+
type SelectedModel<M extends Model, S extends Record<string, any> = {}, R extends Record<string, any> = {}> = S & R & ModelInstanceMethods<M>;
|
|
5963
5849
|
|
|
5964
5850
|
type NullableAndUndefinable<T> = T | (T | null) | (T | undefined) | (T | null | undefined);
|
|
5965
5851
|
type UpsertOptions<T extends Model> = {
|
|
@@ -6047,7 +5933,7 @@ type FindOneType<T extends Model, S extends ModelKey<T>[] = any[], R extends Mod
|
|
|
6047
5933
|
type FindType<T extends Model, S extends ModelKey<T>[] = any[], R extends ModelRelation<T>[] = never[]> = Omit<FindOneType<T, S, R>, "throwErrorOnNull"> & {
|
|
6048
5934
|
limit?: number;
|
|
6049
5935
|
};
|
|
6050
|
-
type FindReturnType<T extends Model, S extends ModelKey<T>[] = any[], R extends ModelRelation<T>[] = never[]> = S extends readonly any[] ? S[number] extends never ? ModelWithoutRelations<T> & {
|
|
5936
|
+
type FindReturnType<T extends Model, S extends ModelKey<T>[] = any[], R extends ModelRelation<T>[] = never[]> = (S extends readonly any[] ? S[number] extends never ? ModelWithoutRelations<T> & {
|
|
6051
5937
|
[K in R[number] & keyof T]: T[K];
|
|
6052
5938
|
} : {
|
|
6053
5939
|
[K in S[number] & keyof T]: T[K];
|
|
@@ -6055,7 +5941,7 @@ type FindReturnType<T extends Model, S extends ModelKey<T>[] = any[], R extends
|
|
|
6055
5941
|
[K in R[number] & keyof T]: T[K];
|
|
6056
5942
|
} : ModelWithoutRelations<T> & {
|
|
6057
5943
|
[K in R[number] & keyof T]: T[K];
|
|
6058
|
-
}
|
|
5944
|
+
}) & ModelInstanceMethods<T>;
|
|
6059
5945
|
|
|
6060
5946
|
/**
|
|
6061
5947
|
* @description Represents a Table in the Database
|
|
@@ -6091,7 +5977,7 @@ declare abstract class Model extends Entity {
|
|
|
6091
5977
|
/**
|
|
6092
5978
|
* @description Returns all the records for the given model
|
|
6093
5979
|
*/
|
|
6094
|
-
static all<T extends Model>(this: new () => T | typeof Model, options?: BaseModelMethodOptions): Promise<
|
|
5980
|
+
static all<T extends Model>(this: new () => T | typeof Model, options?: BaseModelMethodOptions): Promise<ModelQueryResult<T>[]>;
|
|
6095
5981
|
/**
|
|
6096
5982
|
* @description Gives a query sqlInstance for the given model
|
|
6097
5983
|
*/
|
|
@@ -6105,7 +5991,7 @@ declare abstract class Model extends Entity {
|
|
|
6105
5991
|
* @description Finds the first record in the database
|
|
6106
5992
|
* @deprecated Used only for debugging purposes, use `.findOne` or `.query` instead
|
|
6107
5993
|
*/
|
|
6108
|
-
static first<T extends Model>(this: new () => T | typeof Model, options?: BaseModelMethodOptions): Promise<
|
|
5994
|
+
static first<T extends Model>(this: new () => T | typeof Model, options?: BaseModelMethodOptions): Promise<ModelQueryResult<T> | null>;
|
|
6109
5995
|
/**
|
|
6110
5996
|
* @description Finds records for the given model
|
|
6111
5997
|
*/
|
|
@@ -6135,7 +6021,7 @@ declare abstract class Model extends Entity {
|
|
|
6135
6021
|
/**
|
|
6136
6022
|
* @description Refreshes a model from the database, the model must have a primary key defined
|
|
6137
6023
|
*/
|
|
6138
|
-
static refresh<T extends Model>(this: new () => T | typeof Model, model: T, options?: Omit<BaseModelMethodOptions, "ignoreHooks">): Promise<
|
|
6024
|
+
static refresh<T extends Model>(this: new () => T | typeof Model, model: T, options?: Omit<BaseModelMethodOptions, "ignoreHooks">): Promise<ModelQueryResult<T> | null>;
|
|
6139
6025
|
/**
|
|
6140
6026
|
* @description Saves a new record to the database
|
|
6141
6027
|
* @warning If not using postgres and the model has no primary key, the model will be saved, but it won't be possible to retrieve it so at that point it will be returned as null, this is not typed as Model | null for type safety reasons
|
|
@@ -6143,7 +6029,7 @@ declare abstract class Model extends Entity {
|
|
|
6143
6029
|
* @sqlite If no Primary Key is present in the model definition, the model will be returned
|
|
6144
6030
|
* @sqlite Returning Not supported and won't have effect
|
|
6145
6031
|
*/
|
|
6146
|
-
static insert<T extends Model>(this: new () => T | typeof Model, modelData: Partial<ModelWithoutRelations<T>>, options?: BaseModelMethodOptions & InsertOptions<T>): Promise<
|
|
6032
|
+
static insert<T extends Model>(this: new () => T | typeof Model, modelData: Partial<ModelWithoutRelations<T>>, options?: BaseModelMethodOptions & InsertOptions<T>): Promise<ModelQueryResult<T>>;
|
|
6147
6033
|
/**
|
|
6148
6034
|
* @description Saves multiple records to the database
|
|
6149
6035
|
* @warning If not using postgres and the model has no primary key, the models will be saved, but it won't be possible to retrieve them so at that point they will be returned as an empty array
|
|
@@ -6152,7 +6038,7 @@ declare abstract class Model extends Entity {
|
|
|
6152
6038
|
* @sqlite Returning Not supported and won't have effect
|
|
6153
6039
|
* @oracledb may do multiple inserts with auto-generated identity columns
|
|
6154
6040
|
*/
|
|
6155
|
-
static insertMany<T extends Model>(this: new () => T | typeof Model, modelsData: Partial<ModelWithoutRelations<T>>[], options?: BaseModelMethodOptions & InsertOptions<T>): Promise<
|
|
6041
|
+
static insertMany<T extends Model>(this: new () => T | typeof Model, modelsData: Partial<ModelWithoutRelations<T>>[], options?: BaseModelMethodOptions & InsertOptions<T>): Promise<ModelQueryResult<T>[]>;
|
|
6156
6042
|
/**
|
|
6157
6043
|
* @description Syncs in the through table the given models for the given relation
|
|
6158
6044
|
* @param relation The many to many relation to sync, this is not type safe since many to many relations defined at a decorator level
|
|
@@ -6174,7 +6060,7 @@ declare abstract class Model extends Entity {
|
|
|
6174
6060
|
* @description Can only be used if the model has a primary key, use a massive update if the model has no primary key
|
|
6175
6061
|
* @throws {HysteriaError} If the model has no primary key
|
|
6176
6062
|
*/
|
|
6177
|
-
static updateRecord<T extends Model>(this: new () => T | typeof Model, modelSqlInstance: Partial<T>, updatePayload?: Partial<ModelWithoutRelations<T>>, options?: Omit<BaseModelMethodOptions, "ignoreHooks">): Promise<
|
|
6063
|
+
static updateRecord<T extends Model>(this: new () => T | typeof Model, modelSqlInstance: Partial<T>, updatePayload?: Partial<ModelWithoutRelations<T>>, options?: Omit<BaseModelMethodOptions, "ignoreHooks">): Promise<ModelQueryResult<T>>;
|
|
6178
6064
|
/**
|
|
6179
6065
|
* @description Finds the first record or creates a new one if it doesn't exist
|
|
6180
6066
|
*/
|
|
@@ -6187,12 +6073,12 @@ declare abstract class Model extends Entity {
|
|
|
6187
6073
|
/**
|
|
6188
6074
|
* @description Updates or creates a new record, if no searchCriteria payload is provided, provided data will be inserted as is
|
|
6189
6075
|
*/
|
|
6190
|
-
static upsert<T extends Model>(this: new () => T | typeof Model, searchCriteria: Partial<ModelWithoutRelations<T>>, data: Partial<ModelWithoutRelations<T>>, options?: UpsertOptions<T> & BaseModelMethodOptions): Promise<
|
|
6076
|
+
static upsert<T extends Model>(this: new () => T | typeof Model, searchCriteria: Partial<ModelWithoutRelations<T>>, data: Partial<ModelWithoutRelations<T>>, options?: UpsertOptions<T> & BaseModelMethodOptions): Promise<ModelQueryResult<T>>;
|
|
6191
6077
|
/**
|
|
6192
6078
|
* @description Updates or creates multiple records
|
|
6193
6079
|
* @param {updateOnConflict} If true, the record will be updated if it exists, otherwise it will be ignored
|
|
6194
6080
|
*/
|
|
6195
|
-
static upsertMany<T extends Model>(this: new () => T | typeof Model, conflictColumns: ModelKey<T>[], data: Partial<ModelWithoutRelations<T>>[], options?: UpsertOptions<T> & BaseModelMethodOptions): Promise<
|
|
6081
|
+
static upsertMany<T extends Model>(this: new () => T | typeof Model, conflictColumns: ModelKey<T>[], data: Partial<ModelWithoutRelations<T>>[], options?: UpsertOptions<T> & BaseModelMethodOptions): Promise<ModelQueryResult<T>[]>;
|
|
6196
6082
|
/**
|
|
6197
6083
|
* @description Deletes a record to the database
|
|
6198
6084
|
*/
|
|
@@ -6206,7 +6092,7 @@ declare abstract class Model extends Entity {
|
|
|
6206
6092
|
static softDelete<T extends Model>(this: new () => T | typeof Model, modelSqlInstance: T, softDeleteOptions?: {
|
|
6207
6093
|
column?: ModelKey<T>;
|
|
6208
6094
|
value?: string | number | boolean | Date;
|
|
6209
|
-
}, options?: Omit<BaseModelMethodOptions, "ignoreHooks">): Promise<
|
|
6095
|
+
}, options?: Omit<BaseModelMethodOptions, "ignoreHooks">): Promise<ModelQueryResult<T>>;
|
|
6210
6096
|
/**
|
|
6211
6097
|
* @description Truncates the table for the given model
|
|
6212
6098
|
*/
|
|
@@ -7798,4 +7684,4 @@ declare const generateOpenApiModelWithMetadata: <T extends new () => Model>(mode
|
|
|
7798
7684
|
$id?: string;
|
|
7799
7685
|
}>;
|
|
7800
7686
|
|
|
7801
|
-
export { type AbstractConstructor, type AdminJsActionOptions, type AdminJsAssets, type AdminJsBranding, type AdminJsInstance, type AdminJsLocale, type AdminJsOptions, type AdminJsPage, type AdminJsPropertyOptions, type AdminJsResourceOptions, type AdminJsSettings, type AnyConstructor, type AsymmetricEncryptionOptions, type BaseModelMethodOptions, type BaseModelRelationType, BaseSeeder, type BigIntFields, BigIntMixin, type BuildSelectType, type BuildSingleSelectType, 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 ComposeBuildSelect, type ComposeSelect, type ConnectionPolicies, type Constructor, type DataSourceInput, type DataSourceType, type DateColumnOptions, DryModelQueryBuilder, DryQueryBuilder, type ExcludeMethods, type ExtractColumnName, type FetchHooks, type GetColumnType, 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 ModelDataProperties, 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, Schema, SchemaBuilder, type SeederConfig, type SelectBrand, type SelectableColumn, type SelectedModel, 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 };
|
|
7687
|
+
export { type AbstractConstructor, type AdminJsActionOptions, type AdminJsAssets, type AdminJsBranding, type AdminJsInstance, type AdminJsLocale, type AdminJsOptions, type AdminJsPage, type AdminJsPropertyOptions, type AdminJsResourceOptions, type AdminJsSettings, type AnyConstructor, type AsymmetricEncryptionOptions, type BaseModelMethodOptions, type BaseModelRelationType, BaseSeeder, type BigIntFields, BigIntMixin, type BuildSelectType, type BuildSingleSelectType, 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 ComposeBuildSelect, type ComposeSelect, type ConnectionPolicies, type Constructor, type DataSourceInput, type DataSourceType, type DateColumnOptions, DryModelQueryBuilder, DryQueryBuilder, type ExcludeMethods, type ExtractColumnName, type ExtractSourceColumn, type FetchHooks, type GetColumnType, 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 ModelDataProperties, type ModelInstanceMethods, type ModelInstanceType, ModelQueryBuilder, type ModelQueryResult, type ModelSelectTuple, type ModelSelectableInput, 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, Schema, SchemaBuilder, type SeederConfig, type SelectBrand, type SelectableColumn, type SelectedModel, 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 };
|