hysteria-orm 10.5.0 → 10.5.1
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 +28 -27
- package/lib/cli.js.map +1 -1
- package/lib/index.cjs +23 -22
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +813 -318
- package/lib/index.d.ts +813 -318
- package/lib/index.js +23 -22
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1169,37 +1169,6 @@ declare class RawNode extends QueryNode {
|
|
|
1169
1169
|
constructor(value: string);
|
|
1170
1170
|
}
|
|
1171
1171
|
|
|
1172
|
-
type ConstraintType = "primary_key" | "foreign_key" | "unique" | "not_null" | "null" | "default";
|
|
1173
|
-
declare class ConstraintNode extends QueryNode {
|
|
1174
|
-
constraintType: ConstraintType;
|
|
1175
|
-
columns?: (string | (() => string))[];
|
|
1176
|
-
references?: {
|
|
1177
|
-
table: string;
|
|
1178
|
-
columns: (string | (() => string))[];
|
|
1179
|
-
};
|
|
1180
|
-
constraintName?: string;
|
|
1181
|
-
onDelete?: "cascade" | "restrict" | "set null" | "no action";
|
|
1182
|
-
onUpdate?: "cascade" | "restrict" | "set null" | "no action";
|
|
1183
|
-
defaultValue?: string | RawNode | undefined;
|
|
1184
|
-
checkExpression?: string;
|
|
1185
|
-
chainsWith: string;
|
|
1186
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
1187
|
-
folder: string;
|
|
1188
|
-
file: string;
|
|
1189
|
-
constructor(constraintType: ConstraintType, args?: {
|
|
1190
|
-
columns?: string[];
|
|
1191
|
-
references?: {
|
|
1192
|
-
table: string;
|
|
1193
|
-
columns: string[];
|
|
1194
|
-
};
|
|
1195
|
-
constraintName?: string;
|
|
1196
|
-
onDelete?: "cascade" | "restrict" | "set null" | "no action";
|
|
1197
|
-
onUpdate?: "cascade" | "restrict" | "set null" | "no action";
|
|
1198
|
-
defaultValue?: string | RawNode | undefined;
|
|
1199
|
-
checkExpression?: string;
|
|
1200
|
-
}, isRawValue?: boolean);
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1203
1172
|
type Sqlite3ConnectionOptions = {
|
|
1204
1173
|
mode: number;
|
|
1205
1174
|
};
|
|
@@ -1417,6 +1386,12 @@ type RawQueryOptions = {
|
|
|
1417
1386
|
replicationMode?: ReplicationType;
|
|
1418
1387
|
};
|
|
1419
1388
|
|
|
1389
|
+
declare abstract class BaseBuilder {
|
|
1390
|
+
protected nodes: QueryNode[];
|
|
1391
|
+
constructor(nodes: QueryNode[]);
|
|
1392
|
+
getNodes(): QueryNode[];
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1420
1395
|
declare class ColumnTypeNode extends QueryNode {
|
|
1421
1396
|
column: string | (() => string);
|
|
1422
1397
|
dataType: string;
|
|
@@ -1442,45 +1417,6 @@ declare class ColumnTypeNode extends QueryNode {
|
|
|
1442
1417
|
});
|
|
1443
1418
|
}
|
|
1444
1419
|
|
|
1445
|
-
type LockType = "for_update" | "for_share" | "for_no_key_update" | "for_key_share";
|
|
1446
|
-
declare class LockNode extends QueryNode {
|
|
1447
|
-
lockType: LockType;
|
|
1448
|
-
skipLocked: boolean;
|
|
1449
|
-
noWait: boolean;
|
|
1450
|
-
chainsWith: string;
|
|
1451
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
1452
|
-
folder: string;
|
|
1453
|
-
file: string;
|
|
1454
|
-
constructor(lockType: LockType, skipLocked?: boolean, noWait?: boolean);
|
|
1455
|
-
}
|
|
1456
|
-
|
|
1457
|
-
declare class UnionNode extends QueryNode {
|
|
1458
|
-
query: QueryNode | QueryNode[] | string;
|
|
1459
|
-
isAll: boolean;
|
|
1460
|
-
chainsWith: string;
|
|
1461
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
1462
|
-
folder: string;
|
|
1463
|
-
file: string;
|
|
1464
|
-
constructor(query: QueryNode | QueryNode[] | string, isAll?: boolean);
|
|
1465
|
-
}
|
|
1466
|
-
|
|
1467
|
-
declare class WithNode extends QueryNode {
|
|
1468
|
-
alias: string;
|
|
1469
|
-
body: QueryNode | QueryNode[];
|
|
1470
|
-
clause: string;
|
|
1471
|
-
chainsWith: string;
|
|
1472
|
-
canKeywordBeSeenMultipleTimes: boolean;
|
|
1473
|
-
folder: string;
|
|
1474
|
-
file: string;
|
|
1475
|
-
constructor(clause: string, alias: string, body: QueryNode | QueryNode[]);
|
|
1476
|
-
}
|
|
1477
|
-
|
|
1478
|
-
declare abstract class BaseBuilder {
|
|
1479
|
-
protected nodes: QueryNode[];
|
|
1480
|
-
constructor(nodes: QueryNode[]);
|
|
1481
|
-
getNodes(): QueryNode[];
|
|
1482
|
-
}
|
|
1483
|
-
|
|
1484
1420
|
declare class ConstraintBuilder extends BaseBuilder {
|
|
1485
1421
|
private readonly columnNode;
|
|
1486
1422
|
private readonly tableName?;
|
|
@@ -1858,6 +1794,70 @@ declare class CreateTableBuilder extends BaseBuilder {
|
|
|
1858
1794
|
getNamedConstraints(): QueryNode[];
|
|
1859
1795
|
}
|
|
1860
1796
|
|
|
1797
|
+
type ConstraintType = "primary_key" | "foreign_key" | "unique" | "not_null" | "null" | "default";
|
|
1798
|
+
declare class ConstraintNode extends QueryNode {
|
|
1799
|
+
constraintType: ConstraintType;
|
|
1800
|
+
columns?: (string | (() => string))[];
|
|
1801
|
+
references?: {
|
|
1802
|
+
table: string;
|
|
1803
|
+
columns: (string | (() => string))[];
|
|
1804
|
+
};
|
|
1805
|
+
constraintName?: string;
|
|
1806
|
+
onDelete?: "cascade" | "restrict" | "set null" | "no action";
|
|
1807
|
+
onUpdate?: "cascade" | "restrict" | "set null" | "no action";
|
|
1808
|
+
defaultValue?: string | RawNode | undefined;
|
|
1809
|
+
checkExpression?: string;
|
|
1810
|
+
chainsWith: string;
|
|
1811
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
1812
|
+
folder: string;
|
|
1813
|
+
file: string;
|
|
1814
|
+
constructor(constraintType: ConstraintType, args?: {
|
|
1815
|
+
columns?: string[];
|
|
1816
|
+
references?: {
|
|
1817
|
+
table: string;
|
|
1818
|
+
columns: string[];
|
|
1819
|
+
};
|
|
1820
|
+
constraintName?: string;
|
|
1821
|
+
onDelete?: "cascade" | "restrict" | "set null" | "no action";
|
|
1822
|
+
onUpdate?: "cascade" | "restrict" | "set null" | "no action";
|
|
1823
|
+
defaultValue?: string | RawNode | undefined;
|
|
1824
|
+
checkExpression?: string;
|
|
1825
|
+
}, isRawValue?: boolean);
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
type LockType = "for_update" | "for_share" | "for_no_key_update" | "for_key_share";
|
|
1829
|
+
declare class LockNode extends QueryNode {
|
|
1830
|
+
lockType: LockType;
|
|
1831
|
+
skipLocked: boolean;
|
|
1832
|
+
noWait: boolean;
|
|
1833
|
+
chainsWith: string;
|
|
1834
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
1835
|
+
folder: string;
|
|
1836
|
+
file: string;
|
|
1837
|
+
constructor(lockType: LockType, skipLocked?: boolean, noWait?: boolean);
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
declare class UnionNode extends QueryNode {
|
|
1841
|
+
query: QueryNode | QueryNode[] | string;
|
|
1842
|
+
isAll: boolean;
|
|
1843
|
+
chainsWith: string;
|
|
1844
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
1845
|
+
folder: string;
|
|
1846
|
+
file: string;
|
|
1847
|
+
constructor(query: QueryNode | QueryNode[] | string, isAll?: boolean);
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1850
|
+
declare class WithNode extends QueryNode {
|
|
1851
|
+
alias: string;
|
|
1852
|
+
body: QueryNode | QueryNode[];
|
|
1853
|
+
clause: string;
|
|
1854
|
+
chainsWith: string;
|
|
1855
|
+
canKeywordBeSeenMultipleTimes: boolean;
|
|
1856
|
+
folder: string;
|
|
1857
|
+
file: string;
|
|
1858
|
+
constructor(clause: string, alias: string, body: QueryNode | QueryNode[]);
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
1861
|
declare class AlterTableBuilder extends BaseBuilder {
|
|
1862
1862
|
private table;
|
|
1863
1863
|
private sqlType;
|
|
@@ -1959,105 +1959,146 @@ declare class AlterTableBuilder extends BaseBuilder {
|
|
|
1959
1959
|
dropPrimaryKey(table?: string): void;
|
|
1960
1960
|
}
|
|
1961
1961
|
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1962
|
+
/**
|
|
1963
|
+
* @description SchemaBuilder class for building and executing DDL queries
|
|
1964
|
+
* @description Implements PromiseLike to support both await-based execution and query retrieval
|
|
1965
|
+
*
|
|
1966
|
+
* @example Execute when awaited:
|
|
1967
|
+
* ```ts
|
|
1968
|
+
* await sql.schema().createTable("users", (table) => {
|
|
1969
|
+
* table.addColumn("id", "integer", { primaryKey: true });
|
|
1970
|
+
* });
|
|
1971
|
+
* ```
|
|
1972
|
+
*
|
|
1973
|
+
* @example Get SQL without executing:
|
|
1974
|
+
* ```ts
|
|
1975
|
+
* const sql = sql.schema().createTable("users", (table) => {
|
|
1976
|
+
* table.addColumn("id", "integer", { primaryKey: true });
|
|
1977
|
+
* }).toQuery();
|
|
1978
|
+
* ```
|
|
1979
|
+
*
|
|
1980
|
+
* @example Multiple operations:
|
|
1981
|
+
* ```ts
|
|
1982
|
+
* const builder = sql.schema();
|
|
1983
|
+
* builder.createTable("users", (table) => { ... });
|
|
1984
|
+
* builder.createTable("posts", (table) => { ... });
|
|
1985
|
+
* await builder; // Execute all
|
|
1986
|
+
* ```
|
|
1987
|
+
*/
|
|
1988
|
+
declare class SchemaBuilder implements PromiseLike<void> {
|
|
1989
|
+
#private;
|
|
1990
|
+
private schema;
|
|
1991
|
+
private dataSource;
|
|
1992
|
+
private executionPromise;
|
|
1993
|
+
private state;
|
|
1994
|
+
private executionError;
|
|
1995
|
+
constructor(dataSource: SqlDataSource, sqlType?: SqlDataSourceType);
|
|
1966
1996
|
/**
|
|
1967
|
-
* @description
|
|
1968
|
-
* @
|
|
1969
|
-
* ```ts
|
|
1970
|
-
* schema.rawStatement("CURRENT_TIMESTAMP");
|
|
1971
|
-
* schema.alterTable("users", (table) => {
|
|
1972
|
-
* table.timestamp("created_at").default(this.schema.rawStatement("CURRENT_TIMESTAMP"));
|
|
1973
|
-
* });
|
|
1974
|
-
* ```
|
|
1997
|
+
* @description PromiseLike.then implementation - called when awaiting the builder
|
|
1998
|
+
* @description Executes all pending SQL queries on first await
|
|
1975
1999
|
*/
|
|
1976
|
-
|
|
2000
|
+
then<TResult1 = void, TResult2 = never>(onfulfilled?: ((value: void) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
|
|
1977
2001
|
/**
|
|
1978
|
-
* @description
|
|
2002
|
+
* @description Adds a raw statement to define a default value as is
|
|
1979
2003
|
*/
|
|
1980
|
-
|
|
2004
|
+
rawStatement(value: string): RawNode;
|
|
1981
2005
|
/**
|
|
1982
|
-
* @description
|
|
1983
|
-
* @description File is splitted by semicolons and each statement is executed separately and in order
|
|
2006
|
+
* @description Add raw query to the schema
|
|
1984
2007
|
*/
|
|
1985
|
-
|
|
2008
|
+
rawQuery(query: string): this;
|
|
1986
2009
|
/**
|
|
1987
2010
|
* @description Create table constructor
|
|
1988
|
-
* @mssql Does not support ifNotExists option
|
|
1989
2011
|
*/
|
|
1990
2012
|
createTable(table: string, cb: (table: CreateTableBuilder) => void, options?: {
|
|
1991
2013
|
ifNotExists?: boolean;
|
|
1992
|
-
}):
|
|
2014
|
+
}): this;
|
|
1993
2015
|
/**
|
|
1994
2016
|
* @description Alter table constructor
|
|
1995
|
-
* @mssql Limited support - cannot modify columns with constraints; see AlterTableBuilder methods for details
|
|
1996
2017
|
*/
|
|
1997
|
-
alterTable(table: string, cb: (t: AlterTableBuilder) => void):
|
|
2018
|
+
alterTable(table: string, cb: (t: AlterTableBuilder) => void): this;
|
|
1998
2019
|
/**
|
|
1999
2020
|
* @description Drop table in the database
|
|
2000
2021
|
*/
|
|
2001
|
-
dropTable(table: string, ifExists?: boolean):
|
|
2022
|
+
dropTable(table: string, ifExists?: boolean): this;
|
|
2002
2023
|
/**
|
|
2003
2024
|
* @description Rename table in the database
|
|
2004
|
-
* @mssql Uses sp_rename procedure; does not update references in views/procedures/triggers
|
|
2005
2025
|
*/
|
|
2006
|
-
renameTable(oldTable: string, newTable: string):
|
|
2026
|
+
renameTable(oldTable: string, newTable: string): this;
|
|
2007
2027
|
/**
|
|
2008
2028
|
* @description Truncate table
|
|
2009
2029
|
*/
|
|
2010
|
-
truncateTable(table: string):
|
|
2030
|
+
truncateTable(table: string): this;
|
|
2011
2031
|
/**
|
|
2012
2032
|
* @description Create index on table
|
|
2013
2033
|
*/
|
|
2014
|
-
createIndex(table: string, columns: string[] | string, options
|
|
2034
|
+
createIndex(table: string, columns: string[] | string, options?: CommonConstraintOptions): this;
|
|
2015
2035
|
/**
|
|
2016
2036
|
* @description Drop index on table
|
|
2017
|
-
* @mysql requires table name for index drop
|
|
2018
2037
|
*/
|
|
2019
|
-
dropIndex(indexName: string, table?: string):
|
|
2038
|
+
dropIndex(indexName: string, table?: string): this;
|
|
2020
2039
|
/**
|
|
2021
2040
|
* @description Adds a primary key to a table
|
|
2022
2041
|
*/
|
|
2023
|
-
addPrimaryKey(table: string, columns: string[]):
|
|
2042
|
+
addPrimaryKey(table: string, columns: string[]): this;
|
|
2024
2043
|
/**
|
|
2025
2044
|
* @description Adds a UNIQUE constraint to a table
|
|
2026
2045
|
*/
|
|
2027
|
-
addUnique(table: string, columns: string[] | string, options?: CommonConstraintOptions):
|
|
2046
|
+
addUnique(table: string, columns: string[] | string, options?: CommonConstraintOptions): this;
|
|
2028
2047
|
/**
|
|
2029
|
-
* @description
|
|
2030
|
-
* @description If a custom constraint name was used to generate the foreign key, use `dropConstraint` instead
|
|
2048
|
+
* @description Adds a constraint to a table
|
|
2031
2049
|
*/
|
|
2032
|
-
|
|
2050
|
+
addConstraint(table: string, type: string, ...rest: any[]): this;
|
|
2033
2051
|
/**
|
|
2034
|
-
* @description Drops a
|
|
2035
|
-
* @description If no constraintName is provided, it computes the default name using columns
|
|
2052
|
+
* @description Drops a primary key from a table
|
|
2036
2053
|
*/
|
|
2037
|
-
|
|
2054
|
+
dropPrimaryKey(table: string): this;
|
|
2038
2055
|
/**
|
|
2039
|
-
* @description Drops a
|
|
2056
|
+
* @description Drops a foreign key from a table
|
|
2040
2057
|
*/
|
|
2041
|
-
|
|
2058
|
+
dropForeignKey(table: string, leftColumn: string, rightColumn: string): this;
|
|
2042
2059
|
/**
|
|
2043
|
-
* @description
|
|
2060
|
+
* @description Drops a UNIQUE constraint from a table
|
|
2044
2061
|
*/
|
|
2045
|
-
|
|
2062
|
+
dropUnique(table: string, columnsOrConstraintName: string | string[], options?: CommonConstraintOptions): this;
|
|
2046
2063
|
/**
|
|
2047
2064
|
* @description Drops a constraint from a table
|
|
2048
2065
|
*/
|
|
2049
|
-
dropConstraint(table: string, constraintName: string):
|
|
2066
|
+
dropConstraint(table: string, constraintName: string): this;
|
|
2050
2067
|
/**
|
|
2051
2068
|
* @description Create database extension, only supported for postgres
|
|
2052
|
-
* @postgres Supports extensions like PostGIS, uuid-ossp, hstore, etc.
|
|
2053
|
-
* @mysql Extensions are not supported - outputs a comment
|
|
2054
|
-
* @sqlite Extensions are loaded dynamically - outputs a comment
|
|
2055
|
-
* @mssql Extensions are not supported - outputs a comment
|
|
2056
|
-
* @oracledb Extensions are not supported - outputs a comment
|
|
2057
2069
|
*/
|
|
2058
|
-
createExtension(extensionName: CommonPostgresExtensions, ifNotExists?: boolean):
|
|
2059
|
-
createExtension(extensionName: string, ifNotExists?: boolean):
|
|
2060
|
-
|
|
2070
|
+
createExtension(extensionName: CommonPostgresExtensions, ifNotExists?: boolean): this;
|
|
2071
|
+
createExtension(extensionName: string, ifNotExists?: boolean): this;
|
|
2072
|
+
/**
|
|
2073
|
+
* @description Returns the SQL statement(s)
|
|
2074
|
+
* @returns Single string if one statement, array if multiple
|
|
2075
|
+
*/
|
|
2076
|
+
toQuery(): string | string[];
|
|
2077
|
+
/**
|
|
2078
|
+
* @description Returns all statements as an array
|
|
2079
|
+
*/
|
|
2080
|
+
toQueries(): string[];
|
|
2081
|
+
/**
|
|
2082
|
+
* @description Returns the SQL statement(s) as a formatted string
|
|
2083
|
+
*/
|
|
2084
|
+
toString(): string;
|
|
2085
|
+
/**
|
|
2086
|
+
* @description Executes all pending SQL queries
|
|
2087
|
+
* @description Can be called explicitly or via await (PromiseLike)
|
|
2088
|
+
*/
|
|
2089
|
+
execute(): Promise<void>;
|
|
2090
|
+
/**
|
|
2091
|
+
* @description Returns true if the builder has been executed
|
|
2092
|
+
*/
|
|
2093
|
+
isExecuted(): boolean;
|
|
2094
|
+
/**
|
|
2095
|
+
* @description Returns true if the builder is pending execution
|
|
2096
|
+
*/
|
|
2097
|
+
isPending(): boolean;
|
|
2098
|
+
/**
|
|
2099
|
+
* @description Returns true if the builder execution failed
|
|
2100
|
+
*/
|
|
2101
|
+
hasFailed(): boolean;
|
|
2061
2102
|
}
|
|
2062
2103
|
|
|
2063
2104
|
type AstParserType = {
|
|
@@ -2120,6 +2161,8 @@ type SoftDeleteOptions<T> = {
|
|
|
2120
2161
|
ignoreBeforeUpdateHook?: boolean;
|
|
2121
2162
|
};
|
|
2122
2163
|
|
|
2164
|
+
type JsonPathInput = string | (string | number)[];
|
|
2165
|
+
|
|
2123
2166
|
declare class DeleteNode extends QueryNode {
|
|
2124
2167
|
fromNode: FromNode;
|
|
2125
2168
|
chainsWith: string;
|
|
@@ -2176,31 +2219,6 @@ declare class UpdateNode extends QueryNode {
|
|
|
2176
2219
|
constructor(fromNode: FromNode, columns?: string[], values?: (any | RawNode)[], isRawValue?: boolean);
|
|
2177
2220
|
}
|
|
2178
2221
|
|
|
2179
|
-
type PaginationMetadata = {
|
|
2180
|
-
perPage: number;
|
|
2181
|
-
currentPage: number;
|
|
2182
|
-
firstPage: number;
|
|
2183
|
-
isEmpty: boolean;
|
|
2184
|
-
total: number;
|
|
2185
|
-
lastPage: number;
|
|
2186
|
-
hasMorePages: boolean;
|
|
2187
|
-
hasPages: boolean;
|
|
2188
|
-
};
|
|
2189
|
-
type CursorPaginationMetadata = {
|
|
2190
|
-
perPage: number;
|
|
2191
|
-
firstPage: number;
|
|
2192
|
-
isEmpty: boolean;
|
|
2193
|
-
total: number;
|
|
2194
|
-
};
|
|
2195
|
-
type PaginatedData<T extends Model, S extends Record<string, any> = {}, R extends Record<string, any> = {}> = {
|
|
2196
|
-
paginationMetadata: PaginationMetadata;
|
|
2197
|
-
data: ([keyof S] extends [never] ? T & R : SelectedModel<S, R>)[];
|
|
2198
|
-
};
|
|
2199
|
-
type CursorPaginatedData<T extends Model, S extends Record<string, any> = {}, R extends Record<string, any> = {}> = {
|
|
2200
|
-
paginationMetadata: CursorPaginationMetadata;
|
|
2201
|
-
data: ([keyof S] extends [never] ? T & R : SelectedModel<S, R>)[];
|
|
2202
|
-
};
|
|
2203
|
-
|
|
2204
2222
|
type BaseValues$1 = string | number | boolean | null;
|
|
2205
2223
|
type BinaryOperatorType$1 = "=" | "!=" | "<>" | ">" | "<" | ">=" | "<=" | "like" | "ilike" | "in";
|
|
2206
2224
|
declare class HavingNode extends QueryNode {
|
|
@@ -2250,8 +2268,6 @@ declare class WhereGroupNode extends QueryNode {
|
|
|
2250
2268
|
constructor(nodes: (WhereNode | WhereGroupNode | WhereSubqueryNode)[], chainsWith?: "and" | "or");
|
|
2251
2269
|
}
|
|
2252
2270
|
|
|
2253
|
-
type JsonPathInput = string | (string | number)[];
|
|
2254
|
-
|
|
2255
2271
|
declare class DistinctNode extends QueryNode {
|
|
2256
2272
|
chainsWith: string;
|
|
2257
2273
|
canKeywordBeSeenMultipleTimes: boolean;
|
|
@@ -2568,7 +2584,7 @@ type UniqueType = {
|
|
|
2568
2584
|
name: string;
|
|
2569
2585
|
};
|
|
2570
2586
|
|
|
2571
|
-
declare abstract class FooterQueryBuilder<T extends Model> {
|
|
2587
|
+
declare abstract class FooterQueryBuilder<T extends Model, S extends Record<string, any> = Record<string, any>> {
|
|
2572
2588
|
protected sqlDataSource: SqlDataSource;
|
|
2573
2589
|
protected model: typeof Model;
|
|
2574
2590
|
protected groupByNodes: GroupByNode[];
|
|
@@ -2839,7 +2855,7 @@ declare class JoinOnQueryBuilder {
|
|
|
2839
2855
|
* @description Callback type for join conditions
|
|
2840
2856
|
*/
|
|
2841
2857
|
type JoinOnCallback = (query: JoinOnQueryBuilder) => void;
|
|
2842
|
-
declare abstract class JoinQueryBuilder<T extends Model> extends FooterQueryBuilder<T> {
|
|
2858
|
+
declare abstract class JoinQueryBuilder<T extends Model, S extends Record<string, any> = Record<string, any>> extends FooterQueryBuilder<T, S> {
|
|
2843
2859
|
protected joinNodes: JoinNode[];
|
|
2844
2860
|
protected constructor(model: typeof Model, sqlDataSource: SqlDataSource);
|
|
2845
2861
|
/**
|
|
@@ -2941,7 +2957,7 @@ declare abstract class JoinQueryBuilder<T extends Model> extends FooterQueryBuil
|
|
|
2941
2957
|
fullJoin(relationTable: string, referencingColumnOrPrimaryColumn: JoinableColumn, primaryColumn: JoinableColumn, callback: JoinOnCallback): this;
|
|
2942
2958
|
}
|
|
2943
2959
|
|
|
2944
|
-
declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
|
|
2960
|
+
declare class SelectQueryBuilder<T extends Model, S extends Record<string, any> = Record<string, any>> extends JoinQueryBuilder<T, S> {
|
|
2945
2961
|
protected dbType: SqlDataSourceType;
|
|
2946
2962
|
protected modelSelectedColumns: string[];
|
|
2947
2963
|
protected withQuery?: string;
|
|
@@ -2954,28 +2970,19 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
|
|
|
2954
2970
|
* @description Adds a SELECT condition to the query.
|
|
2955
2971
|
* @description Can be stacked multiple times
|
|
2956
2972
|
* @description Supports: "column", "table.column", "column as alias", "*", "table.*"
|
|
2957
|
-
* @example
|
|
2958
|
-
* ```ts
|
|
2959
|
-
* const user = await User.query().select("name", "age").one(); // SELECT name, age FROM users
|
|
2960
|
-
* const user = await User.query().select("name", "users.age").one(); // SELECT name, users.age FROM users
|
|
2961
|
-
* const user = await User.query().select("name as userName").one(); // SELECT name as userName FROM users
|
|
2962
|
-
* ```
|
|
2963
2973
|
*/
|
|
2964
|
-
select<
|
|
2974
|
+
select<C extends string>(...columns: SelectableColumn$1<C>[]): this;
|
|
2965
2975
|
select(...columns: (ModelKey<T> | "*")[]): this;
|
|
2966
2976
|
/**
|
|
2967
2977
|
* @description Parses a column string that may contain an alias (e.g., "column as alias")
|
|
2968
2978
|
* @returns The column part and optional alias part
|
|
2969
2979
|
*/
|
|
2970
|
-
|
|
2980
|
+
protected parseColumnAlias(column: string): {
|
|
2981
|
+
columnPart: string;
|
|
2982
|
+
aliasPart: string | undefined;
|
|
2983
|
+
};
|
|
2971
2984
|
/**
|
|
2972
2985
|
* @description Adds a raw SELECT statement to the query
|
|
2973
|
-
* @description Useful for SQL functions, expressions, or complex selections
|
|
2974
|
-
* @example
|
|
2975
|
-
* ```ts
|
|
2976
|
-
* const result = await User.query().selectRaw("count(*) as total").one();
|
|
2977
|
-
* const result = await User.query().selectRaw("sum(amount) as total_amount").one();
|
|
2978
|
-
* ```
|
|
2979
2986
|
*/
|
|
2980
2987
|
selectRaw(statement: string): this;
|
|
2981
2988
|
/**
|
|
@@ -2996,13 +3003,10 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
|
|
|
2996
3003
|
clearDistinctOn(): this;
|
|
2997
3004
|
/**
|
|
2998
3005
|
* @description Sets the table to select from, by default is the table defined in the Model
|
|
2999
|
-
* @description Can be used on non select queries too, it will only specify the table name (es. INSERT INTO $table)
|
|
3000
|
-
* @param table The table name to query from, must be in valid sql format `table` or `table as alias`
|
|
3001
3006
|
*/
|
|
3002
|
-
from<
|
|
3007
|
+
from<F extends string>(table: TableFormat<F>): this;
|
|
3003
3008
|
/**
|
|
3004
3009
|
* @description Sets the table to select from, by default is the table defined in the Model
|
|
3005
|
-
* @description Better naming convention for non select queries
|
|
3006
3010
|
* @alias from
|
|
3007
3011
|
*/
|
|
3008
3012
|
table(table: string): this;
|
|
@@ -3011,159 +3015,120 @@ declare class SelectQueryBuilder<T extends Model> extends JoinQueryBuilder<T> {
|
|
|
3011
3015
|
*/
|
|
3012
3016
|
distinct(): this;
|
|
3013
3017
|
/**
|
|
3014
|
-
* @description Adds a DISTINCT ON clause to the query
|
|
3015
|
-
* @warning Cannot use both DISTINCT and DISTINCT ON in the same query, only the DISTINCT ON will be used
|
|
3018
|
+
* @description Adds a DISTINCT ON clause to the query
|
|
3016
3019
|
* @postgresql Only usable with PostgreSQL
|
|
3017
3020
|
*/
|
|
3018
3021
|
distinctOn(...columns: ModelKey<T>[]): this;
|
|
3019
|
-
distinctOn<
|
|
3022
|
+
distinctOn<C extends string>(...columns: SelectableColumn$1<C>[]): this;
|
|
3020
3023
|
/**
|
|
3021
3024
|
* @description Selects a JSON value at the specified path and returns it as JSON
|
|
3022
|
-
* @param column The column containing JSON data
|
|
3023
|
-
* @param path The JSON path to extract (standardized format: "$.user.name", "user.name", or ["user", "name"])
|
|
3024
|
-
* @param alias The alias for the selected value
|
|
3025
|
-
* @description Path format is standardized across all databases - ORM converts to DB-specific syntax
|
|
3026
|
-
* @example
|
|
3027
|
-
* ```ts
|
|
3028
|
-
* // All databases accept the same path format:
|
|
3029
|
-
* const user = await User.query().selectJson("data", "$.user.name", "userName").one();
|
|
3030
|
-
*
|
|
3031
|
-
* await User.query().selectJson("data", "user.name", "userName").one(); // $ is optional
|
|
3032
|
-
* await User.query().selectJson("data", ["user", "name"], "userName").one();
|
|
3033
|
-
*
|
|
3034
|
-
* // Array indices:
|
|
3035
|
-
* await User.query().selectJson("data", "items.0.name", "firstItemName").one();
|
|
3036
|
-
* await User.query().selectJson("data", ["items", 0, "name"], "firstItemName").one();
|
|
3037
|
-
* ```
|
|
3038
3025
|
*/
|
|
3039
3026
|
selectJson<A extends string>(column: ModelKey<T>, path: JsonPathInput, alias: A): this;
|
|
3040
3027
|
selectJson<A extends string>(column: string, path: JsonPathInput, alias: A): this;
|
|
3041
3028
|
/**
|
|
3042
3029
|
* @description Selects a JSON value at the specified path and returns it as text
|
|
3043
|
-
* @param column The column containing JSON data
|
|
3044
|
-
* @param path The JSON path to extract (standardized format)
|
|
3045
|
-
* @param alias The alias for the selected value
|
|
3046
|
-
* @description Path format is standardized across all databases - ORM converts to DB-specific syntax
|
|
3047
|
-
* @example
|
|
3048
|
-
* ```ts
|
|
3049
|
-
* // All databases accept the same path format:
|
|
3050
|
-
* const user = await User.query().selectJsonText("data", "$.user.name", "userName").one();
|
|
3051
|
-
*
|
|
3052
|
-
* await User.query().selectJsonText("data", ["user", "name"], "userName").one();
|
|
3053
|
-
* ```
|
|
3054
3030
|
*/
|
|
3055
3031
|
selectJsonText<A extends string>(column: ModelKey<T>, path: JsonPathInput, alias: A): this;
|
|
3056
3032
|
selectJsonText<A extends string>(column: string, path: JsonPathInput, alias: A): this;
|
|
3057
3033
|
/**
|
|
3058
3034
|
* @description Selects the length of a JSON array
|
|
3059
|
-
* @param column The column containing JSON array data
|
|
3060
|
-
* @param path The JSON path to the array (standardized format, use "$" or "" for root)
|
|
3061
|
-
* @param alias The alias for the length value
|
|
3062
|
-
* @description Path format is standardized across all databases - ORM converts to DB-specific syntax
|
|
3063
|
-
* @example
|
|
3064
|
-
* ```ts
|
|
3065
|
-
* // All databases accept the same path format:
|
|
3066
|
-
* const user = await User.query().selectJsonArrayLength("data", "$.items", "itemCount").one();
|
|
3067
|
-
*
|
|
3068
|
-
* await User.query().selectJsonArrayLength("data", "items", "itemCount").one();
|
|
3069
|
-
* await User.query().selectJsonArrayLength("data", "$", "totalCount").one(); // root array
|
|
3070
|
-
* ```
|
|
3071
3035
|
*/
|
|
3072
3036
|
selectJsonArrayLength<A extends string>(column: ModelKey<T>, path: JsonPathInput, alias: A): this;
|
|
3073
3037
|
selectJsonArrayLength<A extends string>(column: string, path: JsonPathInput, alias: A): this;
|
|
3074
3038
|
/**
|
|
3075
3039
|
* @description Selects the keys of a JSON object
|
|
3076
|
-
* @param column The column containing JSON object data
|
|
3077
|
-
* @param path The JSON path to the object (standardized format, use "$" or "" for root)
|
|
3078
|
-
* @param alias The alias for the keys
|
|
3079
|
-
* @description Path format is standardized across all databases - ORM converts to DB-specific syntax
|
|
3080
|
-
* @postgres Returns an array of keys
|
|
3081
|
-
* @mysql Returns a JSON array of keys
|
|
3082
|
-
* @example
|
|
3083
|
-
* ```ts
|
|
3084
|
-
* // All databases accept the same path format:
|
|
3085
|
-
* const user = await User.query().selectJsonKeys("data", "$.user", "userKeys").one();
|
|
3086
|
-
*
|
|
3087
|
-
* await User.query().selectJsonKeys("data", "user", "userKeys").one();
|
|
3088
|
-
* await User.query().selectJsonKeys("data", "$", "rootKeys").one(); // root object
|
|
3089
|
-
* ```
|
|
3090
3040
|
*/
|
|
3091
3041
|
selectJsonKeys<A extends string>(column: ModelKey<T>, path: JsonPathInput, alias: A): this;
|
|
3092
3042
|
selectJsonKeys<A extends string>(column: string, path: JsonPathInput, alias: A): this;
|
|
3093
3043
|
/**
|
|
3094
3044
|
* @description Adds a raw JSON select expression
|
|
3095
|
-
* @param raw The raw SQL expression
|
|
3096
|
-
* @param alias The alias for the selected value
|
|
3097
|
-
* @example
|
|
3098
|
-
* ```ts
|
|
3099
|
-
* const user = await User.query().selectJsonRaw("data->>'email'", "userEmail").one();
|
|
3100
|
-
* ```
|
|
3101
3045
|
*/
|
|
3102
3046
|
selectJsonRaw<A extends string>(raw: string, alias: A): this;
|
|
3103
3047
|
/**
|
|
3104
3048
|
* @description Selects COUNT(column) with an alias
|
|
3105
|
-
* @param column The column to count (use "*" for COUNT(*))
|
|
3106
|
-
* @param alias The alias for the count result
|
|
3107
|
-
* @example
|
|
3108
|
-
* ```ts
|
|
3109
|
-
* const result = await User.query().selectCount("id", "totalUsers").one();
|
|
3110
|
-
*
|
|
3111
|
-
* const result = await User.query().selectCount("*", "total").one();
|
|
3112
|
-
* ```
|
|
3113
3049
|
*/
|
|
3114
3050
|
selectCount<A extends string>(column: ModelKey<T> | "*", alias: A): this;
|
|
3115
3051
|
selectCount<A extends string>(column: string, alias: A): this;
|
|
3116
3052
|
/**
|
|
3117
3053
|
* @description Selects SUM(column) with an alias
|
|
3118
|
-
* @param column The column to sum
|
|
3119
|
-
* @param alias The alias for the sum result
|
|
3120
|
-
* @example
|
|
3121
|
-
* ```ts
|
|
3122
|
-
* const result = await Order.query().selectSum("amount", "totalAmount").one();
|
|
3123
|
-
* console.log(result?.totalAmount); // number
|
|
3124
|
-
* ```
|
|
3125
3054
|
*/
|
|
3126
3055
|
selectSum<A extends string>(column: ModelKey<T>, alias: A): this;
|
|
3127
3056
|
selectSum<A extends string>(column: string, alias: A): this;
|
|
3128
3057
|
/**
|
|
3129
3058
|
* @description Selects AVG(column) with an alias
|
|
3130
|
-
* @param column The column to average
|
|
3131
|
-
* @param alias The alias for the average result
|
|
3132
|
-
* @example
|
|
3133
|
-
* ```ts
|
|
3134
|
-
* const result = await User.query().selectAvg("age", "averageAge").one();
|
|
3135
|
-
* console.log(result?.averageAge); // number
|
|
3136
|
-
* ```
|
|
3137
3059
|
*/
|
|
3138
3060
|
selectAvg<A extends string>(column: ModelKey<T>, alias: A): this;
|
|
3139
3061
|
selectAvg<A extends string>(column: string, alias: A): this;
|
|
3140
3062
|
/**
|
|
3141
3063
|
* @description Selects MIN(column) with an alias
|
|
3142
|
-
* @param column The column to get minimum value
|
|
3143
|
-
* @param alias The alias for the min result
|
|
3144
|
-
* @example
|
|
3145
|
-
* ```ts
|
|
3146
|
-
* const result = await User.query().selectMin("age", "youngestAge").one();
|
|
3147
|
-
* console.log(result?.youngestAge); // number
|
|
3148
|
-
* ```
|
|
3149
3064
|
*/
|
|
3150
3065
|
selectMin<A extends string>(column: ModelKey<T>, alias: A): this;
|
|
3151
3066
|
selectMin<A extends string>(column: string, alias: A): this;
|
|
3152
3067
|
/**
|
|
3153
3068
|
* @description Selects MAX(column) with an alias
|
|
3154
|
-
* @param column The column to get maximum value
|
|
3155
|
-
* @param alias The alias for the max result
|
|
3156
|
-
* @example
|
|
3157
|
-
* ```ts
|
|
3158
|
-
* const result = await User.query().selectMax("age", "oldestAge").one();
|
|
3159
|
-
* console.log(result?.oldestAge); // number
|
|
3160
|
-
* ```
|
|
3161
3069
|
*/
|
|
3162
3070
|
selectMax<A extends string>(column: ModelKey<T>, alias: A): this;
|
|
3163
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;
|
|
3164
3129
|
}
|
|
3165
3130
|
|
|
3166
|
-
declare abstract class WhereQueryBuilder<T extends Model> extends SelectQueryBuilder<T> {
|
|
3131
|
+
declare abstract class WhereQueryBuilder<T extends Model, S extends Record<string, any> = Record<string, any>> extends SelectQueryBuilder<T, S> {
|
|
3167
3132
|
protected whereNodes: (WhereNode | WhereGroupNode | WhereSubqueryNode)[];
|
|
3168
3133
|
protected havingNodes: HavingNode[];
|
|
3169
3134
|
protected isNestedCondition: boolean;
|
|
@@ -3500,7 +3465,7 @@ declare abstract class WhereQueryBuilder<T extends Model> extends SelectQueryBui
|
|
|
3500
3465
|
}
|
|
3501
3466
|
|
|
3502
3467
|
type JsonParam = Record<string, unknown> | any[];
|
|
3503
|
-
declare class JsonQueryBuilder<T extends Model> extends WhereQueryBuilder<T> {
|
|
3468
|
+
declare class JsonQueryBuilder<T extends Model, S extends Record<string, any> = Record<string, any>> extends WhereQueryBuilder<T, S> {
|
|
3504
3469
|
/**
|
|
3505
3470
|
* @description Filters records matching exact JSON value.
|
|
3506
3471
|
*/
|
|
@@ -3589,7 +3554,7 @@ declare class JsonQueryBuilder<T extends Model> extends WhereQueryBuilder<T> {
|
|
|
3589
3554
|
orWhereJsonRaw(raw: string, params?: any[]): this;
|
|
3590
3555
|
}
|
|
3591
3556
|
|
|
3592
|
-
declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
3557
|
+
declare class QueryBuilder<T extends Model = any, S extends Record<string, any> = Record<string, any>> extends JsonQueryBuilder<T, S> {
|
|
3593
3558
|
model: typeof Model;
|
|
3594
3559
|
protected astParser: AstParser;
|
|
3595
3560
|
protected unionNodes: UnionNode[];
|
|
@@ -3608,23 +3573,23 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
3608
3573
|
*/
|
|
3609
3574
|
performance: {
|
|
3610
3575
|
many: (returnType?: "millis" | "seconds") => Promise<{
|
|
3611
|
-
data:
|
|
3576
|
+
data: S[];
|
|
3612
3577
|
time: number;
|
|
3613
3578
|
}>;
|
|
3614
3579
|
one: (returnType?: "millis" | "seconds") => Promise<{
|
|
3615
|
-
data:
|
|
3580
|
+
data: S | null;
|
|
3616
3581
|
time: number;
|
|
3617
3582
|
}>;
|
|
3618
3583
|
oneOrFail: (returnType?: "millis" | "seconds") => Promise<{
|
|
3619
|
-
data:
|
|
3584
|
+
data: S;
|
|
3620
3585
|
time: number;
|
|
3621
3586
|
}>;
|
|
3622
3587
|
paginate: (page: number, perPage: number, returnType?: "millis" | "seconds") => Promise<{
|
|
3623
|
-
data:
|
|
3588
|
+
data: RawPaginatedData<S>;
|
|
3624
3589
|
time: number;
|
|
3625
3590
|
}>;
|
|
3626
3591
|
paginateWithCursor: (page: number, options: PaginateWithCursorOptions<T, ModelKey<T>>, cursor?: Cursor<T, ModelKey<T>>, returnType?: "millis" | "seconds") => Promise<{
|
|
3627
|
-
data: [
|
|
3592
|
+
data: [RawCursorPaginatedData<S>, Cursor<T, ModelKey<T>>];
|
|
3628
3593
|
time: number;
|
|
3629
3594
|
}>;
|
|
3630
3595
|
exists: (returnType?: "millis" | "seconds") => Promise<{
|
|
@@ -3669,6 +3634,105 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
3669
3634
|
* @description If set to "slave", read operations will use slave and write operations will use master
|
|
3670
3635
|
*/
|
|
3671
3636
|
setReplicationMode(replicationMode: ReplicationType): this;
|
|
3637
|
+
/**
|
|
3638
|
+
* @description Adds a SELECT condition to the query with type safety.
|
|
3639
|
+
* @description Can be stacked multiple times
|
|
3640
|
+
* @description Supports: "column", "table.column", "column as alias", "*", "table.*"
|
|
3641
|
+
* @example
|
|
3642
|
+
* ```ts
|
|
3643
|
+
* const user = await sql.query("users").select("name", "age").one();
|
|
3644
|
+
* // user type: { name: any, age: any } | null
|
|
3645
|
+
*
|
|
3646
|
+
* const user = await sql.query("users").select("name as userName").one();
|
|
3647
|
+
* // user type: { userName: any } | null
|
|
3648
|
+
* ```
|
|
3649
|
+
*/
|
|
3650
|
+
select<Columns extends readonly string[]>(...columns: Columns): QueryBuilder<T, ComposeBuildRawSelect<S, Columns>>;
|
|
3651
|
+
/**
|
|
3652
|
+
* @description Adds a raw SELECT statement to the query with type safety.
|
|
3653
|
+
* @description Use the generic parameter to specify the type of the selected columns.
|
|
3654
|
+
* @example
|
|
3655
|
+
* ```ts
|
|
3656
|
+
* const result = await sql.query("users")
|
|
3657
|
+
* .selectRaw<{ total: number }>("count(*) as total")
|
|
3658
|
+
* .one();
|
|
3659
|
+
* // result type: { total: number } | null
|
|
3660
|
+
* ```
|
|
3661
|
+
*/
|
|
3662
|
+
selectRaw<Added extends Record<string, any> = Record<string, any>>(statement: string): QueryBuilder<T, ComposeRawSelect<S, Added>>;
|
|
3663
|
+
/**
|
|
3664
|
+
* @description Clears the SELECT clause and resets type to default
|
|
3665
|
+
*/
|
|
3666
|
+
clearSelect(): QueryBuilder<T, Record<string, any>>;
|
|
3667
|
+
/**
|
|
3668
|
+
* @description Selects a subquery, subquery must return a single column
|
|
3669
|
+
*/
|
|
3670
|
+
selectSubQuery<ValueType = any, Alias extends string = string>(cbOrQueryBuilder: ((subQuery: QueryBuilder<T>) => void) | QueryBuilder<any>, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3671
|
+
[K in Alias]: ValueType;
|
|
3672
|
+
}>>;
|
|
3673
|
+
selectJson<ValueType = any, Alias extends string = string>(column: ModelKey<T> | string, path: JsonPathInput, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3674
|
+
[K in Alias]: ValueType;
|
|
3675
|
+
}>>;
|
|
3676
|
+
selectJsonText<ValueType = string, Alias extends string = string>(column: ModelKey<T> | string, path: JsonPathInput, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3677
|
+
[K in Alias]: ValueType;
|
|
3678
|
+
}>>;
|
|
3679
|
+
selectJsonArrayLength<Alias extends string = string>(column: ModelKey<T> | string, path: JsonPathInput, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3680
|
+
[K in Alias]: number;
|
|
3681
|
+
}>>;
|
|
3682
|
+
selectJsonKeys<Alias extends string = string>(column: ModelKey<T> | string, path: JsonPathInput, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3683
|
+
[K in Alias]: string[];
|
|
3684
|
+
}>>;
|
|
3685
|
+
selectJsonRaw<ValueType = any, Alias extends string = string>(raw: string, alias: Alias): QueryBuilder<T, ComposeRawSelect<S, {
|
|
3686
|
+
[K in Alias]: ValueType;
|
|
3687
|
+
}>>;
|
|
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
|
+
}>>;
|
|
3672
3736
|
/**
|
|
3673
3737
|
* @description Executes the query and returns true if the query returns at least one result, false otherwise.
|
|
3674
3738
|
*/
|
|
@@ -3676,7 +3740,7 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
3676
3740
|
/**
|
|
3677
3741
|
* @description Executes the query and retrieves multiple results.
|
|
3678
3742
|
*/
|
|
3679
|
-
many(): Promise<
|
|
3743
|
+
many(): Promise<S[]>;
|
|
3680
3744
|
/**
|
|
3681
3745
|
* @description Executes the query and retrieves a single column from the results.
|
|
3682
3746
|
* @param key - The column to retrieve from the results, must be a Model Column
|
|
@@ -3685,18 +3749,18 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
3685
3749
|
/**
|
|
3686
3750
|
* @description Executes the query and retrieves a single result.
|
|
3687
3751
|
*/
|
|
3688
|
-
one(): Promise<
|
|
3752
|
+
one(): Promise<S | null>;
|
|
3689
3753
|
/**
|
|
3690
3754
|
* @description Executes the query and retrieves the first result. Fail if no result is found.
|
|
3691
3755
|
*/
|
|
3692
|
-
oneOrFail(): Promise<
|
|
3756
|
+
oneOrFail(): Promise<S>;
|
|
3693
3757
|
/**
|
|
3694
3758
|
* @description Executes the query and returns a node readable stream.
|
|
3695
3759
|
* @description If used by a model query builder, it will serialize the models and apply the hooks and relations.
|
|
3696
3760
|
* @postgres needs the pg-query-stream package in order to work
|
|
3697
3761
|
* @throws If using postgres and the `pg-query-stream` package is not installed
|
|
3698
3762
|
*/
|
|
3699
|
-
stream<M
|
|
3763
|
+
stream<M = S>(options?: StreamOptions): Promise<PassThrough & AsyncGenerator<M>>;
|
|
3700
3764
|
/**
|
|
3701
3765
|
* @description Chunks the query into smaller queries, it returns a generator of the chunks
|
|
3702
3766
|
* @description It will continue to yield chunks until the query returns no results
|
|
@@ -3726,7 +3790,7 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
3726
3790
|
*
|
|
3727
3791
|
* console.log(chunks);
|
|
3728
3792
|
*/
|
|
3729
|
-
chunk(chunkSize: number): AsyncGenerator<
|
|
3793
|
+
chunk(chunkSize: number): AsyncGenerator<S[], void, unknown>;
|
|
3730
3794
|
/**
|
|
3731
3795
|
* @description Executes the query and retrieves multiple paginated results.
|
|
3732
3796
|
* @description Overrides the limit and offset clauses in order to paginate the results.
|
|
@@ -3740,11 +3804,7 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
3740
3804
|
* @warning If no order by clause is present in the query, the query will add an order by clause to the query `orderBy(discriminator, "asc")`
|
|
3741
3805
|
* @returns the pagination metadata and the cursor for the next page
|
|
3742
3806
|
*/
|
|
3743
|
-
paginateWithCursor<K extends ModelKey<T>>(limit: number, options: PaginateWithCursorOptions<T, K>, cursor?: Cursor<T, K>): Promise<[
|
|
3744
|
-
/**
|
|
3745
|
-
* @description Selects a subquery, subquery must return a single column
|
|
3746
|
-
*/
|
|
3747
|
-
selectSubQuery(cbOrQueryBuilder: ((subQuery: QueryBuilder<T>) => void) | QueryBuilder<any>, alias: string): this;
|
|
3807
|
+
paginateWithCursor<K extends ModelKey<T>>(limit: number, options: PaginateWithCursorOptions<T, K>, cursor?: Cursor<T, K>): Promise<[RawCursorPaginatedData<S>, Cursor<T, K>]>;
|
|
3748
3808
|
/**
|
|
3749
3809
|
* @description Locks the table for update
|
|
3750
3810
|
* @param skipLocked - If true, the query will skip locked rows
|
|
@@ -3814,7 +3874,7 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
3814
3874
|
* @description Executes the query and retrieves multiple paginated results.
|
|
3815
3875
|
* @description Overrides the limit and offset clauses in order to paginate the results.
|
|
3816
3876
|
*/
|
|
3817
|
-
paginate(page: number, perPage: number): Promise<
|
|
3877
|
+
paginate(page: number, perPage: number): Promise<RawPaginatedData<S>>;
|
|
3818
3878
|
/**
|
|
3819
3879
|
* @description Overrides the from clause in the query.
|
|
3820
3880
|
*/
|
|
@@ -3901,11 +3961,11 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
3901
3961
|
/**
|
|
3902
3962
|
* @description Returns a deep clone of the query builder instance.
|
|
3903
3963
|
*/
|
|
3904
|
-
clone():
|
|
3964
|
+
clone(): QueryBuilder<T, S>;
|
|
3905
3965
|
/**
|
|
3906
3966
|
* @description Gives a fresh instance of the query builder
|
|
3907
3967
|
*/
|
|
3908
|
-
clear(): QueryBuilder<any
|
|
3968
|
+
clear(): QueryBuilder<T, Record<string, any>>;
|
|
3909
3969
|
/**
|
|
3910
3970
|
* @description Removes the lock query
|
|
3911
3971
|
*/
|
|
@@ -3972,7 +4032,7 @@ declare class QueryBuilder<T extends Model = any> extends JsonQueryBuilder<T> {
|
|
|
3972
4032
|
/**
|
|
3973
4033
|
* Allows to get queries without executing them
|
|
3974
4034
|
*/
|
|
3975
|
-
declare class DryQueryBuilder extends QueryBuilder {
|
|
4035
|
+
declare class DryQueryBuilder<T extends Model = any, S extends Record<string, any> = Record<string, any>> extends QueryBuilder<T, S> {
|
|
3976
4036
|
constructor(model: typeof Model, sqlDataSource: SqlDataSource);
|
|
3977
4037
|
many(): this;
|
|
3978
4038
|
/**
|
|
@@ -4026,6 +4086,107 @@ declare class DryQueryBuilder extends QueryBuilder {
|
|
|
4026
4086
|
}
|
|
4027
4087
|
|
|
4028
4088
|
type PluckReturnType<T extends Model, K extends ModelKey<T>> = T[K] extends infer U ? U[] : never;
|
|
4089
|
+
/**
|
|
4090
|
+
* Unique symbol used internally to mark that a raw select() has been called.
|
|
4091
|
+
*/
|
|
4092
|
+
declare const RAW_SELECT_BRAND: unique symbol;
|
|
4093
|
+
/**
|
|
4094
|
+
* Marker type to indicate that a raw select() has been called.
|
|
4095
|
+
* @internal
|
|
4096
|
+
*/
|
|
4097
|
+
type RawSelectBrand = {
|
|
4098
|
+
[RAW_SELECT_BRAND]?: never;
|
|
4099
|
+
};
|
|
4100
|
+
/**
|
|
4101
|
+
* Utility type to convert a union to an intersection.
|
|
4102
|
+
* @internal
|
|
4103
|
+
*/
|
|
4104
|
+
type UnionToIntersection$1<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
4105
|
+
/**
|
|
4106
|
+
* Extracts the final property name from a column selection string for raw queries.
|
|
4107
|
+
*
|
|
4108
|
+
* | Input | Output |
|
|
4109
|
+
* |--------------------------|---------------|
|
|
4110
|
+
* | `"name"` | `"name"` |
|
|
4111
|
+
* | `"users.name"` | `"name"` |
|
|
4112
|
+
* | `"name as userName"` | `"userName"` |
|
|
4113
|
+
* | `"count(*) as total"` | `"total"` |
|
|
4114
|
+
* | `"*"` | `never` |
|
|
4115
|
+
* | `"users.*"` | `never` |
|
|
4116
|
+
*/
|
|
4117
|
+
type ExtractRawColumnName<S extends string> = S extends `${string} as ${infer Alias}` ? Alias : S extends "*" ? never : S extends `${string}.*` ? never : S extends `${string}.${infer Column}` ? Column extends "*" ? never : Column : S;
|
|
4118
|
+
/**
|
|
4119
|
+
* Builds the type for a single selected column in a raw query.
|
|
4120
|
+
* All column types are `any` since we don't have model type information.
|
|
4121
|
+
*
|
|
4122
|
+
* | Selection | Result Type |
|
|
4123
|
+
* |--------------------|---------------------------------------|
|
|
4124
|
+
* | `"*"` | `Record<string, any>` |
|
|
4125
|
+
* | `"table.*"` | `Record<string, any>` |
|
|
4126
|
+
* | `"column"` | `{ column: any }` |
|
|
4127
|
+
* | `"col as alias"` | `{ alias: any }` |
|
|
4128
|
+
*
|
|
4129
|
+
* @internal
|
|
4130
|
+
*/
|
|
4131
|
+
type BuildRawSingleSelectType<S extends string> = S extends "*" ? Record<string, any> : S extends `${string}.*` ? Record<string, any> : ExtractRawColumnName<S> extends never ? {} : {
|
|
4132
|
+
[K in ExtractRawColumnName<S>]: any;
|
|
4133
|
+
};
|
|
4134
|
+
/**
|
|
4135
|
+
* Checks if a column selection includes wildcards or is empty.
|
|
4136
|
+
* @internal
|
|
4137
|
+
*/
|
|
4138
|
+
type HasRawStarOrEmpty<Columns extends readonly string[]> = Columns["length"] extends 0 ? true : "*" extends Columns[number] ? true : false;
|
|
4139
|
+
/**
|
|
4140
|
+
* Builds the combined TypeScript type for multiple selected columns in a raw query.
|
|
4141
|
+
*
|
|
4142
|
+
* ## Rules
|
|
4143
|
+
*
|
|
4144
|
+
* 1. **Empty selection or `*`**: Returns `Record<string, any>`
|
|
4145
|
+
* 2. **Specific columns**: Returns intersection of all selected column types (all `any`)
|
|
4146
|
+
* 3. **With `table.*`**: Adds `Record<string, any>` to allow unknown properties
|
|
4147
|
+
*
|
|
4148
|
+
* @example
|
|
4149
|
+
* // .select("name", "age as userAge")
|
|
4150
|
+
* BuildRawSelectType<["name", "age as userAge"]>
|
|
4151
|
+
* // Result: { name: any; userAge: any } & RawSelectBrand
|
|
4152
|
+
*
|
|
4153
|
+
* @example
|
|
4154
|
+
* // .select("*")
|
|
4155
|
+
* BuildRawSelectType<["*"]>
|
|
4156
|
+
* // Result: Record<string, any>
|
|
4157
|
+
*/
|
|
4158
|
+
type BuildRawSelectType<Columns extends readonly string[]> = HasRawStarOrEmpty<Columns> extends true ? Record<string, any> : UnionToIntersection$1<{
|
|
4159
|
+
[K in keyof Columns]: Columns[K] extends string ? BuildRawSingleSelectType<Columns[K]> : {};
|
|
4160
|
+
}[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
|
+
/**
|
|
4162
|
+
* Composes a new selection with the existing selection state for raw queries.
|
|
4163
|
+
*
|
|
4164
|
+
* - If S is the default Record<string, any> (no previous select), returns just the new selection
|
|
4165
|
+
* - If S already has RawSelectBrand (from a previous select), composes with new selection
|
|
4166
|
+
*
|
|
4167
|
+
* @typeParam S - Current selection state
|
|
4168
|
+
* @typeParam Added - New fields being added by the select
|
|
4169
|
+
*
|
|
4170
|
+
* @example
|
|
4171
|
+
* // First selectRaw - creates new selection
|
|
4172
|
+
* ComposeRawSelect<Record<string, any>, { count: number }>
|
|
4173
|
+
* // Result: RawSelectBrand & { count: number }
|
|
4174
|
+
*
|
|
4175
|
+
* @example
|
|
4176
|
+
* // Chained selectRaw - composes with previous
|
|
4177
|
+
* ComposeRawSelect<{ count: number } & RawSelectBrand, { userName: string }>
|
|
4178
|
+
* // Result: { count: number } & RawSelectBrand & { userName: string }
|
|
4179
|
+
*/
|
|
4180
|
+
type ComposeRawSelect<S extends Record<string, any>, Added extends Record<string, any>> = (typeof RAW_SELECT_BRAND extends keyof S ? S : RawSelectBrand) & Added;
|
|
4181
|
+
/**
|
|
4182
|
+
* Composes a BuildRawSelectType result with the existing selection state.
|
|
4183
|
+
*
|
|
4184
|
+
* Similar to ComposeRawSelect but designed for use with BuildRawSelectType.
|
|
4185
|
+
*
|
|
4186
|
+
* @typeParam S - Current selection state
|
|
4187
|
+
* @typeParam Columns - The columns being selected
|
|
4188
|
+
*/
|
|
4189
|
+
type ComposeBuildRawSelect<S extends Record<string, any>, Columns extends readonly string[]> = (typeof RAW_SELECT_BRAND extends keyof S ? S : {}) & BuildRawSelectType<Columns>;
|
|
4029
4190
|
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">;
|
|
4030
4191
|
type RelationRetrieveMethod<P extends any> = P extends any[] ? "many" : "one";
|
|
4031
4192
|
type SelectableColumn$1<T extends string = string> = T extends `${infer Table}.${infer Column}.${string}` ? never : T extends `${string}(${string})` ? T : T extends `${string} as ${string}` ? T : T extends `${string} ${string}` ? never : T extends `.${string}` | `${string}.` ? never : T extends `${string}-${string}` ? never : T extends `${string}.${string}` ? T : T;
|
|
@@ -4061,9 +4222,37 @@ type UpsertOptionsRawBuilder = {
|
|
|
4061
4222
|
updateOnConflict?: boolean;
|
|
4062
4223
|
returning?: string[];
|
|
4063
4224
|
};
|
|
4064
|
-
type DryQueryBuilderWithoutReadOperations = Omit<DryQueryBuilder, "many" | "one" | "oneOrFail" | "
|
|
4065
|
-
type DryModelQueryBuilderWithoutReadOperations<T extends Model, A extends Record<string, any> = {}, R extends Record<string, any> = {}> = Omit<DryModelQueryBuilder<T, A, R>, "many" | "one" | "oneOrFail" | "
|
|
4225
|
+
type DryQueryBuilderWithoutReadOperations = Omit<DryQueryBuilder, "many" | "one" | "oneOrFail" | "paginate" | "paginateWithCursor" | "exists" | "pluck" | "increment" | "decrement" | "getSum" | "getAvg" | "getMin" | "getMax" | "getCount" | "stream" | "chunk" | "paginate" | "paginateWithCursor" | "exists">;
|
|
4226
|
+
type DryModelQueryBuilderWithoutReadOperations<T extends Model, A extends Record<string, any> = {}, R extends Record<string, any> = {}> = Omit<DryModelQueryBuilder<T, A, R>, "many" | "one" | "oneOrFail" | "paginate" | "paginateWithCursor" | "exists" | "pluck" | "upsert" | "upsertMany" | "increment" | "decrement" | "getSum" | "getAvg" | "getMin" | "getMax" | "getCount" | "stream" | "chunk" | "paginate" | "paginateWithCursor" | "exists">;
|
|
4066
4227
|
type WriteQueryParam$1 = string | number | boolean | Date | RawNode | object | null | undefined;
|
|
4228
|
+
/**
|
|
4229
|
+
* Simple paginated data type for raw query builders (without Model constraint)
|
|
4230
|
+
*/
|
|
4231
|
+
type RawPaginatedData<S extends Record<string, any>> = {
|
|
4232
|
+
paginationMetadata: {
|
|
4233
|
+
perPage: number;
|
|
4234
|
+
currentPage: number;
|
|
4235
|
+
firstPage: number;
|
|
4236
|
+
isEmpty: boolean;
|
|
4237
|
+
total: number;
|
|
4238
|
+
lastPage: number;
|
|
4239
|
+
hasMorePages: boolean;
|
|
4240
|
+
hasPages: boolean;
|
|
4241
|
+
};
|
|
4242
|
+
data: S[];
|
|
4243
|
+
};
|
|
4244
|
+
/**
|
|
4245
|
+
* Simple cursor paginated data type for raw query builders (without Model constraint)
|
|
4246
|
+
*/
|
|
4247
|
+
type RawCursorPaginatedData<S extends Record<string, any>> = {
|
|
4248
|
+
paginationMetadata: {
|
|
4249
|
+
perPage: number;
|
|
4250
|
+
firstPage: number;
|
|
4251
|
+
isEmpty: boolean;
|
|
4252
|
+
total: number;
|
|
4253
|
+
};
|
|
4254
|
+
data: S[];
|
|
4255
|
+
};
|
|
4067
4256
|
|
|
4068
4257
|
declare class SqlModelManagerUtils<T extends Model> {
|
|
4069
4258
|
protected dbType: SqlDataSourceType;
|
|
@@ -4074,6 +4263,31 @@ declare class SqlModelManagerUtils<T extends Model> {
|
|
|
4074
4263
|
getRelationFromModel(relation: ModelRelation<T>): Relation;
|
|
4075
4264
|
}
|
|
4076
4265
|
|
|
4266
|
+
type PaginationMetadata = {
|
|
4267
|
+
perPage: number;
|
|
4268
|
+
currentPage: number;
|
|
4269
|
+
firstPage: number;
|
|
4270
|
+
isEmpty: boolean;
|
|
4271
|
+
total: number;
|
|
4272
|
+
lastPage: number;
|
|
4273
|
+
hasMorePages: boolean;
|
|
4274
|
+
hasPages: boolean;
|
|
4275
|
+
};
|
|
4276
|
+
type CursorPaginationMetadata = {
|
|
4277
|
+
perPage: number;
|
|
4278
|
+
firstPage: number;
|
|
4279
|
+
isEmpty: boolean;
|
|
4280
|
+
total: number;
|
|
4281
|
+
};
|
|
4282
|
+
type PaginatedData<T extends Model, S extends Record<string, any> = {}, R extends Record<string, any> = {}> = {
|
|
4283
|
+
paginationMetadata: PaginationMetadata;
|
|
4284
|
+
data: ([keyof S] extends [never] ? T & R : SelectedModel<T, S, R>)[];
|
|
4285
|
+
};
|
|
4286
|
+
type CursorPaginatedData<T extends Model, S extends Record<string, any> = {}, R extends Record<string, any> = {}> = {
|
|
4287
|
+
paginationMetadata: CursorPaginationMetadata;
|
|
4288
|
+
data: ([keyof S] extends [never] ? T & R : SelectedModel<T, S, R>)[];
|
|
4289
|
+
};
|
|
4290
|
+
|
|
4077
4291
|
type UpdateOptions = {
|
|
4078
4292
|
ignoreBeforeUpdateHook?: boolean;
|
|
4079
4293
|
};
|
|
@@ -4081,7 +4295,7 @@ type UpdateOptions = {
|
|
|
4081
4295
|
/**
|
|
4082
4296
|
* @description Due to query limitations some query builder methods may not be available in a RelationQueryBuilder
|
|
4083
4297
|
*/
|
|
4084
|
-
type RelationQueryBuilderType<T extends Model, A extends Record<string, any> = {}, R extends Record<string, any> = {}> = Omit<ModelQueryBuilder<T, A, R>, "increment" | "decrement" | "
|
|
4298
|
+
type RelationQueryBuilderType<T extends Model, A extends Record<string, any> = {}, R extends Record<string, any> = {}> = Omit<ModelQueryBuilder<T, A, R>, "increment" | "decrement" | "paginate" | "pluck" | "truncate" | "many" | "one" | "oneOrFail" | "insert" | "insertMany" | "update" | "delete" | "softDelete" | "getSum" | "getAvg" | "getMin" | "getMax" | "getCount" | "getMin" | "getMax" | "getCount">;
|
|
4085
4299
|
|
|
4086
4300
|
declare class ModelQueryBuilder<T extends Model, S extends Record<string, any> = ModelWithoutRelations<T>, R extends Record<string, any> = {}> extends QueryBuilder<T> {
|
|
4087
4301
|
relation: Relation;
|
|
@@ -4094,15 +4308,15 @@ declare class ModelQueryBuilder<T extends Model, S extends Record<string, any> =
|
|
|
4094
4308
|
protected offsetValue?: number;
|
|
4095
4309
|
performance: {
|
|
4096
4310
|
many: (options?: ManyOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
4097
|
-
data: SelectedModel<S, R>[];
|
|
4311
|
+
data: SelectedModel<T, S, R>[];
|
|
4098
4312
|
time: number;
|
|
4099
4313
|
}>;
|
|
4100
4314
|
one: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
4101
|
-
data: SelectedModel<S, R> | null;
|
|
4315
|
+
data: SelectedModel<T, S, R> | null;
|
|
4102
4316
|
time: number;
|
|
4103
4317
|
}>;
|
|
4104
4318
|
oneOrFail: (options?: OneOptions, returnType?: "millis" | "seconds") => Promise<{
|
|
4105
|
-
data: SelectedModel<S, R>;
|
|
4319
|
+
data: SelectedModel<T, S, R>;
|
|
4106
4320
|
time: number;
|
|
4107
4321
|
}>;
|
|
4108
4322
|
paginate: (page: number, perPage: number, options?: {
|
|
@@ -4150,20 +4364,15 @@ declare class ModelQueryBuilder<T extends Model, S extends Record<string, any> =
|
|
|
4150
4364
|
* @description Creates a new ModelQueryBuilder instance from a model. Will use the main connection to the database by default.
|
|
4151
4365
|
*/
|
|
4152
4366
|
static from(model: typeof Model, options?: BaseModelMethodOptions): ModelQueryBuilder<InstanceType<typeof model>>;
|
|
4153
|
-
one(options?: OneOptions): Promise<SelectedModel<S, R> | null>;
|
|
4367
|
+
one(options?: OneOptions): Promise<SelectedModel<T, S, R> | null>;
|
|
4154
4368
|
oneOrFail(options?: {
|
|
4155
4369
|
ignoreHooks?: OneOptions["ignoreHooks"] & {
|
|
4156
4370
|
customError?: Error;
|
|
4157
4371
|
};
|
|
4158
|
-
}): Promise<SelectedModel<S, R>>;
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
};
|
|
4163
|
-
}): Promise<SelectedModel<S, R>>;
|
|
4164
|
-
many(options?: ManyOptions): Promise<SelectedModel<S, R>[]>;
|
|
4165
|
-
chunk(chunkSize: number, options?: ManyOptions): AsyncGenerator<SelectedModel<S, R>[]>;
|
|
4166
|
-
stream(options?: ManyOptions & StreamOptions): Promise<PassThrough & AsyncGenerator<SelectedModel<S, R>>>;
|
|
4372
|
+
}): Promise<SelectedModel<T, S, R>>;
|
|
4373
|
+
many(options?: ManyOptions): Promise<SelectedModel<T, S, R>[]>;
|
|
4374
|
+
chunk(chunkSize: number, options?: ManyOptions): AsyncGenerator<SelectedModel<T, S, R>[] | T[]>;
|
|
4375
|
+
stream(options?: ManyOptions & StreamOptions): Promise<PassThrough & AsyncGenerator<SelectedModel<T, S, R> | T>>;
|
|
4167
4376
|
paginateWithCursor<K extends ModelKey<T>>(page: number, options?: PaginateWithCursorOptions<T, K>, cursor?: Cursor<T, K>): Promise<[CursorPaginatedData<T, S, R>, Cursor<T, K>]>;
|
|
4168
4377
|
/**
|
|
4169
4378
|
* @description Inserts a new record into the database, it is not advised to use this method directly from the query builder if using a ModelQueryBuilder (`Model.query()`), use the `Model.insert` method instead.
|
|
@@ -4198,6 +4407,7 @@ declare class ModelQueryBuilder<T extends Model, S extends Record<string, any> =
|
|
|
4198
4407
|
* @description Adds columns to the SELECT clause with full type safety.
|
|
4199
4408
|
* @description Supports formats: "column", "table.column", "column as alias", "*", "table.*"
|
|
4200
4409
|
* @description When columns are selected, the return type reflects only those columns
|
|
4410
|
+
* @warning This only allows selecting columns that are part of the model. For other columns, use `selectRaw`.
|
|
4201
4411
|
* @example
|
|
4202
4412
|
* ```ts
|
|
4203
4413
|
* // Select specific columns - return type is { id: number, name: string }
|
|
@@ -4540,6 +4750,157 @@ declare class ModelQueryBuilder<T extends Model, S extends Record<string, any> =
|
|
|
4540
4750
|
selectMax<Alias extends string>(column: ModelKey<T> | string, alias: Alias): ModelQueryBuilder<T, ComposeSelect<S, {
|
|
4541
4751
|
[K in Alias]: number;
|
|
4542
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>;
|
|
4543
4904
|
/**
|
|
4544
4905
|
* @description Fills the relations in the model in the serialized response. Relation must be defined in the model.
|
|
4545
4906
|
* @warning Many to many relations have special behavior, since they require a join, a join clause will always be added to the query.
|
|
@@ -4602,8 +4963,8 @@ declare class ModelQueryBuilder<T extends Model, S extends Record<string, any> =
|
|
|
4602
4963
|
* @description Recursively processes all relations, including nested ones
|
|
4603
4964
|
*/
|
|
4604
4965
|
protected processRelationsRecursively(models: T[]): Promise<void>;
|
|
4605
|
-
protected mapRelatedModelsToModels<R extends ModelWithoutRelations<T
|
|
4606
|
-
protected getRelatedModelsForRelation(relationQueryBuilder: ModelQueryBuilder<any>, relation: Relation, models: T[]): Promise<ModelWithoutRelations<T>[]>;
|
|
4966
|
+
protected mapRelatedModelsToModels<R extends SelectedModel<T, ModelWithoutRelations<T>, Record<string, any>>>(relation: Relation, modelsToFillWithRelations: T[], relatedModels: R[]): void;
|
|
4967
|
+
protected getRelatedModelsForRelation(relationQueryBuilder: ModelQueryBuilder<any>, relation: Relation, models: T[]): Promise<SelectedModel<T, ModelWithoutRelations<T>, R>[]>;
|
|
4607
4968
|
protected getRelatedModelsQueryForRelation(relationQueryBuilder: ModelQueryBuilder<any>, relation: Relation, models: T[]): ModelQueryBuilder<any, any, any>;
|
|
4608
4969
|
protected getFilterValuesFromModelsForRelation(relation: Relation, models: T[]): any[];
|
|
4609
4970
|
protected applyHavingRelatedFilter(relationQueryBuilder: ModelQueryBuilder<any>, relation: Relation, operator?: BinaryOperatorType, value?: BaseValues): void;
|
|
@@ -5123,13 +5484,29 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
|
|
|
5123
5484
|
*/
|
|
5124
5485
|
dryQuery<S extends string>(table: TableFormat<S>, options?: RawModelOptions): DryQueryBuilderWithoutReadOperations;
|
|
5125
5486
|
/**
|
|
5126
|
-
* @description
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
*
|
|
5487
|
+
* @description Returns a SchemaBuilder instance for DDL operations
|
|
5488
|
+
* @description The builder will execute queries when awaited or when .execute() is called
|
|
5489
|
+
* @description Use .toQuery() or .toString() to get the SQL without executing
|
|
5490
|
+
* @example
|
|
5491
|
+
* ```ts
|
|
5492
|
+
* // Execute on await
|
|
5493
|
+
* await sql.schema().createTable("users", (table) => {
|
|
5494
|
+
* table.addColumn("id", "integer", { primaryKey: true });
|
|
5495
|
+
* });
|
|
5496
|
+
*
|
|
5497
|
+
* // Get SQL without executing
|
|
5498
|
+
* const sql = sql.schema().createTable("users", (table) => {
|
|
5499
|
+
* table.addColumn("id", "integer", { primaryKey: true });
|
|
5500
|
+
* }).toQuery();
|
|
5501
|
+
*
|
|
5502
|
+
* // Multiple operations
|
|
5503
|
+
* const builder = sql.schema();
|
|
5504
|
+
* builder.createTable("users", (table) => { ... });
|
|
5505
|
+
* builder.createTable("posts", (table) => { ... });
|
|
5506
|
+
* await builder; // Executes all
|
|
5507
|
+
* ```
|
|
5131
5508
|
*/
|
|
5132
|
-
|
|
5509
|
+
schema(): SchemaBuilder;
|
|
5133
5510
|
/**
|
|
5134
5511
|
* @description Starts a global transaction on the database
|
|
5135
5512
|
* @description Intended for testing purposes - wraps all operations in a transaction that can be rolled back
|
|
@@ -5290,7 +5667,20 @@ declare class SqlDataSource<D extends SqlDataSourceType = SqlDataSourceType, T e
|
|
|
5290
5667
|
private connectWithoutSettingPrimary;
|
|
5291
5668
|
}
|
|
5292
5669
|
|
|
5293
|
-
|
|
5670
|
+
/**
|
|
5671
|
+
* Extracts only non-method keys from a type.
|
|
5672
|
+
* Excludes any property that is a function.
|
|
5673
|
+
*/
|
|
5674
|
+
type ExcludeMethods<T> = {
|
|
5675
|
+
[K in keyof T]: T[K] extends (...args: any[]) => any ? never : K;
|
|
5676
|
+
}[keyof T];
|
|
5677
|
+
/**
|
|
5678
|
+
* Picks only non-method properties from the base Model class.
|
|
5679
|
+
* This ensures that when selecting specific columns, instance methods
|
|
5680
|
+
* like save(), delete(), refresh() are not incorrectly included.
|
|
5681
|
+
*/
|
|
5682
|
+
type ModelDataProperties = Pick<Model, ExcludeMethods<Model>>;
|
|
5683
|
+
type ModelWithoutRelations<T extends Model> = Pick<Omit<T, "*">, ExcludeRelations<Omit<T, "*">>> & ModelDataProperties;
|
|
5294
5684
|
type NumberModelKey<T extends Model> = {
|
|
5295
5685
|
[K in keyof T]: T[K] extends number | bigint ? K : never;
|
|
5296
5686
|
}[keyof T];
|
|
@@ -5409,7 +5799,7 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
|
5409
5799
|
* "*" // All columns
|
|
5410
5800
|
* );
|
|
5411
5801
|
*/
|
|
5412
|
-
type SelectableColumn<T extends Model> = ModelKey<T> | `${string}.${string}` | `${string} as ${string}` | `${string}(${string}) as ${string}` | "*";
|
|
5802
|
+
type SelectableColumn<T extends Model> = ModelKey<T> | `${string}.${string | "*"}` | `${ModelKey<T> & string} as ${string}` | `${string}(${string}) as ${string}` | "*";
|
|
5413
5803
|
/**
|
|
5414
5804
|
* Extracts the final property name from a column selection string.
|
|
5415
5805
|
*
|
|
@@ -5507,7 +5897,7 @@ type SelectBrand = {
|
|
|
5507
5897
|
*/
|
|
5508
5898
|
type BuildSelectType<T extends Model, Columns extends readonly string[]> = HasStarOrEmpty<Columns> extends true ? ModelWithoutRelations<T> : UnionToIntersection<{
|
|
5509
5899
|
[K in keyof Columns]: Columns[K] extends string ? BuildSingleSelectType<T, Columns[K]> : {};
|
|
5510
|
-
}[number]> extends infer Result ? Result extends Record<string, any> ? keyof Result extends never ? ModelWithoutRelations<T> : Result &
|
|
5900
|
+
}[number]> extends infer Result ? Result extends Record<string, any> ? keyof Result extends never ? ModelWithoutRelations<T> : Result & ModelDataProperties & SelectBrand : ModelWithoutRelations<T> : ModelWithoutRelations<T>;
|
|
5511
5901
|
/**
|
|
5512
5902
|
* Composes a new selection with the existing selection state.
|
|
5513
5903
|
*
|
|
@@ -5530,7 +5920,7 @@ type BuildSelectType<T extends Model, Columns extends readonly string[]> = HasSt
|
|
|
5530
5920
|
* ComposeSelect<{ count: number } & Pick<Model, keyof Model> & SelectBrand, { userName: string }>
|
|
5531
5921
|
* // Result: { count: number } & Pick<Model, keyof Model> & SelectBrand & { userName: string }
|
|
5532
5922
|
*/
|
|
5533
|
-
type ComposeSelect<S extends Record<string, any>, Added extends Record<string, any>> = (typeof SELECT_BRAND extends keyof S ? S :
|
|
5923
|
+
type ComposeSelect<S extends Record<string, any>, Added extends Record<string, any>> = (typeof SELECT_BRAND extends keyof S ? S : ModelDataProperties & SelectBrand) & Added;
|
|
5534
5924
|
/**
|
|
5535
5925
|
* Composes a BuildSelectType result with the existing selection state.
|
|
5536
5926
|
*
|
|
@@ -5569,7 +5959,7 @@ type ComposeBuildSelect<S extends Record<string, any>, T extends Model, Columns
|
|
|
5569
5959
|
* SelectedModel<{ name: string }, { posts: Post[] }>
|
|
5570
5960
|
* // Result: { name: string; posts: Post[] }
|
|
5571
5961
|
*/
|
|
5572
|
-
type SelectedModel<S extends Record<string, any> = {}, R extends Record<string, any> = {}> = S & R;
|
|
5962
|
+
type SelectedModel<M extends Model, S extends Record<string, any> = {}, R extends Record<string, any> = {}> = S & R;
|
|
5573
5963
|
|
|
5574
5964
|
type NullableAndUndefinable<T> = T | (T | null) | (T | undefined) | (T | null | undefined);
|
|
5575
5965
|
type UpsertOptions<T extends Model> = {
|
|
@@ -7194,6 +7584,111 @@ declare class RedisDataSource {
|
|
|
7194
7584
|
protected static getValue<T = RedisFetchable>(value: string | null): T | null;
|
|
7195
7585
|
}
|
|
7196
7586
|
|
|
7587
|
+
declare class Schema {
|
|
7588
|
+
queryStatements: string[];
|
|
7589
|
+
sqlType: SqlDataSourceType;
|
|
7590
|
+
constructor(sqlType?: SqlDataSourceType);
|
|
7591
|
+
/**
|
|
7592
|
+
* @description Adds a raw statement to define a default value as is
|
|
7593
|
+
* @example
|
|
7594
|
+
* ```ts
|
|
7595
|
+
* schema.rawStatement("CURRENT_TIMESTAMP");
|
|
7596
|
+
* schema.alterTable("users", (table) => {
|
|
7597
|
+
* table.timestamp("created_at").default(this.schema.rawStatement("CURRENT_TIMESTAMP"));
|
|
7598
|
+
* });
|
|
7599
|
+
* ```
|
|
7600
|
+
*/
|
|
7601
|
+
rawStatement(value: string): RawNode;
|
|
7602
|
+
/**
|
|
7603
|
+
* @description Add raw query to the migration
|
|
7604
|
+
*/
|
|
7605
|
+
rawQuery(query: string): void;
|
|
7606
|
+
/**
|
|
7607
|
+
* @description Executes the queries built by the schema
|
|
7608
|
+
*/
|
|
7609
|
+
execute(): Promise<void>;
|
|
7610
|
+
/**
|
|
7611
|
+
* @description Runs the sql in the given file, throws error if file does not exist or is not .sql or .txt
|
|
7612
|
+
* @description File is splitted by semicolons and each statement is executed separately and in order
|
|
7613
|
+
*/
|
|
7614
|
+
runFile(filePath: string): void;
|
|
7615
|
+
/**
|
|
7616
|
+
* @description Create table constructor
|
|
7617
|
+
* @mssql Does not support ifNotExists option
|
|
7618
|
+
*/
|
|
7619
|
+
createTable(table: string, cb: (table: CreateTableBuilder) => void, options?: {
|
|
7620
|
+
ifNotExists?: boolean;
|
|
7621
|
+
}): void;
|
|
7622
|
+
/**
|
|
7623
|
+
* @description Alter table constructor
|
|
7624
|
+
* @mssql Limited support - cannot modify columns with constraints; see AlterTableBuilder methods for details
|
|
7625
|
+
*/
|
|
7626
|
+
alterTable(table: string, cb: (t: AlterTableBuilder) => void): void;
|
|
7627
|
+
/**
|
|
7628
|
+
* @description Drop table in the database
|
|
7629
|
+
*/
|
|
7630
|
+
dropTable(table: string, ifExists?: boolean): void;
|
|
7631
|
+
/**
|
|
7632
|
+
* @description Rename table in the database
|
|
7633
|
+
* @mssql Uses sp_rename procedure; does not update references in views/procedures/triggers
|
|
7634
|
+
*/
|
|
7635
|
+
renameTable(oldTable: string, newTable: string): void;
|
|
7636
|
+
/**
|
|
7637
|
+
* @description Truncate table
|
|
7638
|
+
*/
|
|
7639
|
+
truncateTable(table: string): void;
|
|
7640
|
+
/**
|
|
7641
|
+
* @description Create index on table
|
|
7642
|
+
*/
|
|
7643
|
+
createIndex(table: string, columns: string[] | string, options?: CommonConstraintOptions): void;
|
|
7644
|
+
/**
|
|
7645
|
+
* @description Drop index on table
|
|
7646
|
+
* @mysql requires table name for index drop
|
|
7647
|
+
*/
|
|
7648
|
+
dropIndex(indexName: string, table?: string): void;
|
|
7649
|
+
/**
|
|
7650
|
+
* @description Adds a primary key to a table
|
|
7651
|
+
*/
|
|
7652
|
+
addPrimaryKey(table: string, columns: string[]): void;
|
|
7653
|
+
/**
|
|
7654
|
+
* @description Adds a UNIQUE constraint to a table
|
|
7655
|
+
*/
|
|
7656
|
+
addUnique(table: string, columns: string[] | string, options?: CommonConstraintOptions): void;
|
|
7657
|
+
/**
|
|
7658
|
+
* @description Drops a foreign key from a table, uses a standard constraint name pattern: fk_${table}_${leftColumn}_${rightColumn}
|
|
7659
|
+
* @description If a custom constraint name was used to generate the foreign key, use `dropConstraint` instead
|
|
7660
|
+
*/
|
|
7661
|
+
dropForeignKey(table: string, leftColumn: string, rightColumn: string): void;
|
|
7662
|
+
/**
|
|
7663
|
+
* @description Drops a UNIQUE constraint from a table
|
|
7664
|
+
* @description If no constraintName is provided, it computes the default name using columns
|
|
7665
|
+
*/
|
|
7666
|
+
dropUnique(table: string, columnsOrConstraintName: string | string[], options?: CommonConstraintOptions): void;
|
|
7667
|
+
/**
|
|
7668
|
+
* @description Drops a primary key from a table
|
|
7669
|
+
*/
|
|
7670
|
+
dropPrimaryKey(table: string): void;
|
|
7671
|
+
/**
|
|
7672
|
+
* @description Adds a foreign key to a table
|
|
7673
|
+
*/
|
|
7674
|
+
addConstraint(table: string, ...options: ConstructorParameters<typeof ConstraintNode>): void;
|
|
7675
|
+
/**
|
|
7676
|
+
* @description Drops a constraint from a table
|
|
7677
|
+
*/
|
|
7678
|
+
dropConstraint(table: string, constraintName: string): void;
|
|
7679
|
+
/**
|
|
7680
|
+
* @description Create database extension, only supported for postgres
|
|
7681
|
+
* @postgres Supports extensions like PostGIS, uuid-ossp, hstore, etc.
|
|
7682
|
+
* @mysql Extensions are not supported - outputs a comment
|
|
7683
|
+
* @sqlite Extensions are loaded dynamically - outputs a comment
|
|
7684
|
+
* @mssql Extensions are not supported - outputs a comment
|
|
7685
|
+
* @oracledb Extensions are not supported - outputs a comment
|
|
7686
|
+
*/
|
|
7687
|
+
createExtension(extensionName: CommonPostgresExtensions, ifNotExists?: boolean): void;
|
|
7688
|
+
createExtension(extensionName: string, ifNotExists?: boolean): void;
|
|
7689
|
+
private generateAstInstance;
|
|
7690
|
+
}
|
|
7691
|
+
|
|
7197
7692
|
declare abstract class Migration {
|
|
7198
7693
|
dbType: SqlDataSourceType;
|
|
7199
7694
|
migrationName: string;
|
|
@@ -7303,4 +7798,4 @@ declare const generateOpenApiModelWithMetadata: <T extends new () => Model>(mode
|
|
|
7303
7798
|
$id?: string;
|
|
7304
7799
|
}>;
|
|
7305
7800
|
|
|
7306
|
-
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 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 ModelInstanceType, ModelQueryBuilder, type ModelWithoutRelations, MongoDataSource, type MongoDataSourceInput$1 as MongoDataSourceInput, type MssqlConnectionInstance, type MssqlDataSourceInput, type MssqlPoolInstance, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullableOracleDBDataSourceInput, type NotNullableOracleMssqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NumberModelKey, type OneOptions, type OracleDBDataSourceInput, type OracleDBPoolInstance, type PgPoolClientInstance, type PostgresSqlDataSourceInput, QueryBuilder, type RawModelOptions, RawNode, type RawQueryOptions, RedisCacheAdapter, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationQueryBuilderType, type ReplicationType, type SeederConfig, type 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 };
|
|
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 };
|