drizzle-kit 0.28.1-661b6f2 → 0.28.1-66f461a
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/api.js +85 -61
- package/api.mjs +85 -61
- package/bin.cjs +1 -1
- package/package.json +1 -1
package/api.js
CHANGED
@@ -24033,7 +24033,7 @@ function defineRelations(schema4, relations) {
|
|
24033
24033
|
);
|
24034
24034
|
}
|
24035
24035
|
function relationsFieldFilterToSQL(column4, filter2) {
|
24036
|
-
if (typeof filter2 !== "object")
|
24036
|
+
if (typeof filter2 !== "object" || is(filter2, Placeholder))
|
24037
24037
|
return eq(column4, filter2);
|
24038
24038
|
const entries = Object.entries(filter2);
|
24039
24039
|
if (!entries.length)
|
@@ -24043,14 +24043,14 @@ function relationsFieldFilterToSQL(column4, filter2) {
|
|
24043
24043
|
if (value === void 0)
|
24044
24044
|
continue;
|
24045
24045
|
switch (target) {
|
24046
|
-
case "
|
24046
|
+
case "NOT": {
|
24047
24047
|
const res = relationsFieldFilterToSQL(column4, value);
|
24048
24048
|
if (!res)
|
24049
24049
|
continue;
|
24050
24050
|
parts.push(not(res));
|
24051
24051
|
continue;
|
24052
24052
|
}
|
24053
|
-
case "
|
24053
|
+
case "OR": {
|
24054
24054
|
if (!value.length)
|
24055
24055
|
continue;
|
24056
24056
|
parts.push(
|
@@ -24075,7 +24075,7 @@ function relationsFieldFilterToSQL(column4, filter2) {
|
|
24075
24075
|
return void 0;
|
24076
24076
|
return and(...parts);
|
24077
24077
|
}
|
24078
|
-
function
|
24078
|
+
function relationsFilterToSQL(table4, filter2) {
|
24079
24079
|
const entries = Object.entries(filter2);
|
24080
24080
|
if (!entries.length)
|
24081
24081
|
return void 0;
|
@@ -24084,7 +24084,7 @@ function relationFilterToSQL(table4, filter2) {
|
|
24084
24084
|
if (value === void 0)
|
24085
24085
|
continue;
|
24086
24086
|
switch (target) {
|
24087
|
-
case "
|
24087
|
+
case "RAW": {
|
24088
24088
|
if (value) {
|
24089
24089
|
parts.push(
|
24090
24090
|
value(table4[Columns], operators)
|
@@ -24092,30 +24092,25 @@ function relationFilterToSQL(table4, filter2) {
|
|
24092
24092
|
}
|
24093
24093
|
continue;
|
24094
24094
|
}
|
24095
|
-
case "
|
24095
|
+
case "OR": {
|
24096
24096
|
if (!value?.length)
|
24097
24097
|
continue;
|
24098
24098
|
parts.push(
|
24099
24099
|
or(
|
24100
24100
|
...value.map(
|
24101
|
-
(subFilter) =>
|
24101
|
+
(subFilter) => relationsFilterToSQL(table4, subFilter)
|
24102
24102
|
)
|
24103
24103
|
)
|
24104
24104
|
);
|
24105
24105
|
continue;
|
24106
24106
|
}
|
24107
|
-
case "
|
24108
|
-
if (
|
24107
|
+
case "NOT": {
|
24108
|
+
if (value === void 0)
|
24109
24109
|
continue;
|
24110
|
-
|
24111
|
-
|
24112
|
-
|
24113
|
-
|
24114
|
-
(subFilter) => relationFilterToSQL(table4, subFilter)
|
24115
|
-
)
|
24116
|
-
)
|
24117
|
-
)
|
24118
|
-
);
|
24110
|
+
const built = relationsFilterToSQL(table4, value);
|
24111
|
+
if (!built)
|
24112
|
+
continue;
|
24113
|
+
parts.push(not(built));
|
24119
24114
|
continue;
|
24120
24115
|
}
|
24121
24116
|
default: {
|
@@ -24156,13 +24151,15 @@ function relationExtrasToSQL(table4, extras) {
|
|
24156
24151
|
selection
|
24157
24152
|
};
|
24158
24153
|
}
|
24159
|
-
function relationToSQL(relation) {
|
24160
|
-
const table4 = relation.sourceTable;
|
24154
|
+
function relationToSQL(relation, sourceTable, targetTable) {
|
24161
24155
|
const columnWhere = relation.sourceColumns.map((s, i) => {
|
24162
24156
|
const t = relation.targetColumns[i];
|
24163
|
-
return eq(
|
24157
|
+
return eq(
|
24158
|
+
sql`${sql`${sql`${sql.identifier(sourceTable[Schema] ?? "")}.`.if(sourceTable[Schema] && !sourceTable[IsAlias])}`}${sourceTable}.${sql.identifier(s.name)}`,
|
24159
|
+
sql`${sql`${sql`${sql.identifier(targetTable[Schema] ?? "")}.`.if(targetTable[Schema] && !targetTable[IsAlias])}`}${targetTable}.${sql.identifier(t.name)}`
|
24160
|
+
);
|
24164
24161
|
});
|
24165
|
-
const targetWhere = relation.where ? and(...columnWhere,
|
24162
|
+
const targetWhere = relation.where ? and(...columnWhere, relationsFilterToSQL(sourceTable, relation.where)) : and(...columnWhere);
|
24166
24163
|
return targetWhere;
|
24167
24164
|
}
|
24168
24165
|
var _a118, Relations, _a119, Relation, _a120, _b95, One, _a121, _b96, Many, _a122, AggregatedField, _a123, _b97, Count, operators, orderByOperators, _a124, RelationsBuilderTable, _a125, RelationsBuilderColumn, _a126, RelationsHelperStatic;
|
@@ -24187,6 +24184,8 @@ var init_relations = __esm({
|
|
24187
24184
|
this.tables = tables;
|
24188
24185
|
this.config = config;
|
24189
24186
|
for (const [tsName, table4] of Object.entries(tables)) {
|
24187
|
+
if (!is(table4, Table2))
|
24188
|
+
continue;
|
24190
24189
|
this.tableNamesMap[getTableUniqueName(table4)] = tsName;
|
24191
24190
|
const tableConfig = this.tablesConfig[tsName] = {
|
24192
24191
|
table: table4,
|
@@ -24686,8 +24685,8 @@ __export(dist_exports, {
|
|
24686
24685
|
param: () => param,
|
24687
24686
|
placeholder: () => placeholder,
|
24688
24687
|
relationExtrasToSQL: () => relationExtrasToSQL,
|
24689
|
-
relationFilterToSQL: () => relationFilterToSQL,
|
24690
24688
|
relationToSQL: () => relationToSQL,
|
24689
|
+
relationsFilterToSQL: () => relationsFilterToSQL,
|
24691
24690
|
relationsOrderToSQL: () => relationsOrderToSQL,
|
24692
24691
|
sql: () => sql,
|
24693
24692
|
sum: () => sum,
|
@@ -25223,11 +25222,8 @@ var init_dialect = __esm({
|
|
25223
25222
|
});
|
25224
25223
|
}
|
25225
25224
|
}
|
25226
|
-
return columnIdentifiers.length ? sql.join(columnIdentifiers, sql`, `) :
|
25227
|
-
})() : (
|
25228
|
-
const columnIdentifiers = [this.unwrapAllColumns(table4, selection)];
|
25229
|
-
return sql.join(columnIdentifiers, sql`, `);
|
25230
|
-
})());
|
25225
|
+
return columnIdentifiers.length ? sql.join(columnIdentifiers, sql`, `) : void 0;
|
25226
|
+
})() : this.unwrapAllColumns(table4, selection));
|
25231
25227
|
this.casing = new CasingCache(config?.casing);
|
25232
25228
|
}
|
25233
25229
|
async migrate(migrations, session, config) {
|
@@ -25842,20 +25838,24 @@ var init_dialect = __esm({
|
|
25842
25838
|
tableConfig,
|
25843
25839
|
queryConfig: config,
|
25844
25840
|
relationWhere,
|
25845
|
-
mode
|
25841
|
+
mode,
|
25842
|
+
errorPath,
|
25843
|
+
depth
|
25846
25844
|
}) {
|
25847
25845
|
const selection = [];
|
25848
25846
|
const isSingle = mode === "first";
|
25849
25847
|
const params = config === true ? void 0 : config;
|
25848
|
+
const currentPath = errorPath ?? "";
|
25849
|
+
const currentDepth = depth ?? 0;
|
25850
25850
|
const limit = isSingle ? 1 : params?.limit;
|
25851
25851
|
const offset = params?.offset;
|
25852
|
-
const where = params?.where && relationWhere ? and(
|
25852
|
+
const where = params?.where && relationWhere ? and(relationsFilterToSQL(table4, params.where), relationWhere) : params?.where ? relationsFilterToSQL(table4, params.where) : relationWhere;
|
25853
25853
|
const order = params?.orderBy ? relationsOrderToSQL(table4, params.orderBy) : void 0;
|
25854
25854
|
const columns = this.buildColumns(table4, tableConfig, selection, params);
|
25855
25855
|
const extras = params?.extras ? relationExtrasToSQL(table4, params.extras) : void 0;
|
25856
25856
|
if (extras)
|
25857
25857
|
selection.push(...extras.selection);
|
25858
|
-
const selectionArr = [columns];
|
25858
|
+
const selectionArr = columns ? [columns] : [];
|
25859
25859
|
const joins = params ? (() => {
|
25860
25860
|
const { with: joins2 } = params;
|
25861
25861
|
if (!joins2)
|
@@ -25878,8 +25878,8 @@ var init_dialect = __esm({
|
|
25878
25878
|
}
|
25879
25879
|
const relation = tableConfig.relations[k];
|
25880
25880
|
const isSingle2 = is(relation, One);
|
25881
|
-
const targetTable = relation.targetTable;
|
25882
|
-
const relationFilter = relationToSQL(relation);
|
25881
|
+
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
25882
|
+
const relationFilter = relationToSQL(relation, table4, targetTable);
|
25883
25883
|
selectionArr.push(
|
25884
25884
|
isSingle2 ? sql`${sql.identifier(k)}.${sql.identifier("r")} as ${sql.identifier(k)}` : sql`coalesce(${sql.identifier(k)}.${sql.identifier("r")}, '[]') as ${sql.identifier(k)}`
|
25885
25885
|
);
|
@@ -25888,10 +25888,12 @@ var init_dialect = __esm({
|
|
25888
25888
|
mode: isSingle2 ? "first" : "many",
|
25889
25889
|
schema: schema4,
|
25890
25890
|
queryConfig: join,
|
25891
|
-
tableConfig: schema4[tableNamesMap[getTableUniqueName(targetTable)]],
|
25891
|
+
tableConfig: schema4[tableNamesMap[getTableUniqueName(relation.targetTable)]],
|
25892
25892
|
tableNamesMap,
|
25893
25893
|
tables,
|
25894
|
-
relationWhere: relationFilter
|
25894
|
+
relationWhere: relationFilter,
|
25895
|
+
errorPath: `${currentPath.length ? `${currentPath}.` : ""}${k}`,
|
25896
|
+
depth: currentDepth + 1
|
25895
25897
|
});
|
25896
25898
|
selection.push({
|
25897
25899
|
field: targetTable,
|
@@ -25906,8 +25908,13 @@ var init_dialect = __esm({
|
|
25906
25908
|
})() : void 0;
|
25907
25909
|
if (extras?.sql)
|
25908
25910
|
selectionArr.push(extras.sql);
|
25911
|
+
if (!selectionArr.length) {
|
25912
|
+
throw new DrizzleError({
|
25913
|
+
message: `No fields selected for table "${tableConfig.tsName}"${currentPath ? ` ("${currentPath}")` : ""}`
|
25914
|
+
});
|
25915
|
+
}
|
25909
25916
|
const selectionSet = sql.join(selectionArr.filter((e) => e !== void 0), sql`, `);
|
25910
|
-
const query = sql`select ${selectionSet} from ${table4}${sql` ${joins}`.if(joins)}${sql` where ${where}`.if(where)}${sql` order by ${order}`.if(order)}${sql` limit ${limit}`.if(limit !== void 0)}${sql` offset ${offset}`.if(offset !== void 0)}`;
|
25917
|
+
const query = sql`select ${selectionSet} from ${table4[IsAlias] ? sql`${sql`${sql.identifier(table4[Schema] ?? "")}.`.if(table4[Schema])}${sql.identifier(table4[OriginalName])} as ${table4}` : table4}${sql` ${joins}`.if(joins)}${sql` where ${where}`.if(where)}${sql` order by ${order}`.if(order)}${sql` limit ${limit}`.if(limit !== void 0)}${sql` offset ${offset}`.if(offset !== void 0)}`;
|
25911
25918
|
return {
|
25912
25919
|
sql: query,
|
25913
25920
|
selection
|
@@ -31368,11 +31375,8 @@ var init_dialect2 = __esm({
|
|
31368
31375
|
field: column4.column
|
31369
31376
|
});
|
31370
31377
|
}
|
31371
|
-
return columnIdentifiers.length ? sql.join(columnIdentifiers, sql`, `) :
|
31372
|
-
})() : (
|
31373
|
-
const columnIdentifiers = [this.unwrapAllColumns(table4, selection)];
|
31374
|
-
return sql.join(columnIdentifiers, sql`, `);
|
31375
|
-
})());
|
31378
|
+
return columnIdentifiers.length ? sql.join(columnIdentifiers, sql`, `) : void 0;
|
31379
|
+
})() : this.unwrapAllColumns(table4, selection));
|
31376
31380
|
this.casing = new CasingCache(config?.casing);
|
31377
31381
|
}
|
31378
31382
|
escapeName(name2) {
|
@@ -31919,15 +31923,19 @@ var init_dialect2 = __esm({
|
|
31919
31923
|
queryConfig: config,
|
31920
31924
|
relationWhere,
|
31921
31925
|
mode,
|
31922
|
-
isNested
|
31926
|
+
isNested,
|
31927
|
+
errorPath,
|
31928
|
+
depth
|
31923
31929
|
}) {
|
31924
31930
|
const selection = [];
|
31925
31931
|
const isSingle = mode === "first";
|
31926
31932
|
const params = config === true ? void 0 : config;
|
31933
|
+
const currentPath = errorPath ?? "";
|
31934
|
+
const currentDepth = depth ?? 0;
|
31927
31935
|
const limit = isSingle ? 1 : params?.limit;
|
31928
31936
|
const offset = params?.offset;
|
31929
31937
|
const columns = this.buildColumns(table4, selection, params);
|
31930
|
-
const where = params?.where && relationWhere ? and(
|
31938
|
+
const where = params?.where && relationWhere ? and(relationsFilterToSQL(table4, params.where), relationWhere) : params?.where ? relationsFilterToSQL(table4, params.where) : relationWhere;
|
31931
31939
|
const order = params?.orderBy ? relationsOrderToSQL(table4, params.orderBy) : void 0;
|
31932
31940
|
const extras = params?.extras ? relationExtrasToSQL(table4, params.extras) : void 0;
|
31933
31941
|
if (extras)
|
@@ -31954,17 +31962,19 @@ var init_dialect2 = __esm({
|
|
31954
31962
|
const relation = tableConfig.relations[k];
|
31955
31963
|
const isSingle2 = is(relation, One);
|
31956
31964
|
const targetTable = relation.targetTable;
|
31957
|
-
const relationFilter = relationToSQL(relation);
|
31965
|
+
const relationFilter = relationToSQL(relation, table4, targetTable);
|
31958
31966
|
const innerQuery = this.buildRelationalQuery({
|
31959
31967
|
table: targetTable,
|
31960
31968
|
mode: isSingle2 ? "first" : "many",
|
31961
31969
|
schema: schema4,
|
31962
31970
|
queryConfig: join,
|
31963
|
-
tableConfig: schema4[tableNamesMap[getTableUniqueName(targetTable)]],
|
31971
|
+
tableConfig: schema4[tableNamesMap[getTableUniqueName(relation.targetTable)]],
|
31964
31972
|
tableNamesMap,
|
31965
31973
|
tables,
|
31966
31974
|
relationWhere: relationFilter,
|
31967
|
-
isNested: true
|
31975
|
+
isNested: true,
|
31976
|
+
errorPath: `${currentPath.length ? `${currentPath}.` : ""}${k}`,
|
31977
|
+
depth: currentDepth + 1
|
31968
31978
|
});
|
31969
31979
|
selection.push({
|
31970
31980
|
field: targetTable,
|
@@ -31983,8 +31993,14 @@ var init_dialect2 = __esm({
|
|
31983
31993
|
sql`, `
|
31984
31994
|
);
|
31985
31995
|
})() : void 0;
|
31986
|
-
const
|
31987
|
-
|
31996
|
+
const selectionArr = [columns, extras?.sql, joins].filter((e) => e !== void 0);
|
31997
|
+
if (!selectionArr.length) {
|
31998
|
+
throw new DrizzleError({
|
31999
|
+
message: `No fields selected for table "${tableConfig.tsName}"${currentPath ? ` ("${currentPath}")` : ""}`
|
32000
|
+
});
|
32001
|
+
}
|
32002
|
+
const selectionSet = sql.join(selectionArr, sql`, `);
|
32003
|
+
const query = sql`select ${selectionSet} from ${table4[IsAlias] ? sql`${sql`${sql.identifier(table4[Schema] ?? "")}.`.if(table4[Schema])}${sql.identifier(table4[OriginalName])} as ${table4}` : table4}${sql` where ${where}`.if(where)}${sql` order by ${order}`.if(order)}${sql` limit ${limit}`.if(limit !== void 0)}${sql` offset ${offset}`.if(offset !== void 0)}`;
|
31988
32004
|
return {
|
31989
32005
|
sql: query,
|
31990
32006
|
selection
|
@@ -36843,11 +36859,8 @@ var init_dialect3 = __esm({
|
|
36843
36859
|
sql`${table4[column4.tsName]} as ${sql.identifier(column4.tsName)}`
|
36844
36860
|
);
|
36845
36861
|
}
|
36846
|
-
return columnIdentifiers.length ? sql.join(columnIdentifiers, sql`, `) :
|
36847
|
-
})() : (
|
36848
|
-
const columnIdentifiers = [this.unwrapAllColumns(table4, selection)];
|
36849
|
-
return sql.join(columnIdentifiers, sql`, `);
|
36850
|
-
})());
|
36862
|
+
return columnIdentifiers.length ? sql.join(columnIdentifiers, sql`, `) : void 0;
|
36863
|
+
})() : this.unwrapAllColumns(table4, selection));
|
36851
36864
|
this.casing = new CasingCache(config?.casing);
|
36852
36865
|
}
|
36853
36866
|
async migrate(migrations, session, config) {
|
@@ -37649,20 +37662,24 @@ var init_dialect3 = __esm({
|
|
37649
37662
|
tableConfig,
|
37650
37663
|
queryConfig: config,
|
37651
37664
|
relationWhere,
|
37652
|
-
mode
|
37665
|
+
mode,
|
37666
|
+
errorPath,
|
37667
|
+
depth
|
37653
37668
|
}) {
|
37654
37669
|
const selection = [];
|
37655
37670
|
const isSingle = mode === "first";
|
37656
37671
|
const params = config === true ? void 0 : config;
|
37672
|
+
const currentPath = errorPath ?? "";
|
37673
|
+
const currentDepth = depth ?? 0;
|
37657
37674
|
const limit = isSingle ? 1 : params?.limit;
|
37658
37675
|
const offset = params?.offset;
|
37659
37676
|
const columns = this.buildColumns(table4, selection, params);
|
37660
|
-
const where = params?.where && relationWhere ? and(
|
37677
|
+
const where = params?.where && relationWhere ? and(relationsFilterToSQL(table4, params.where), relationWhere) : params?.where ? relationsFilterToSQL(table4, params.where) : relationWhere;
|
37661
37678
|
const order = params?.orderBy ? relationsOrderToSQL(table4, params.orderBy) : void 0;
|
37662
37679
|
const extras = params?.extras ? relationExtrasToSQL(table4, params.extras) : void 0;
|
37663
37680
|
if (extras)
|
37664
37681
|
selection.push(...extras.selection);
|
37665
|
-
const selectionArr = [columns];
|
37682
|
+
const selectionArr = columns ? [columns] : [];
|
37666
37683
|
const joins = params ? (() => {
|
37667
37684
|
const { with: joins2 } = params;
|
37668
37685
|
if (!joins2)
|
@@ -37685,17 +37702,19 @@ var init_dialect3 = __esm({
|
|
37685
37702
|
}
|
37686
37703
|
const relation = tableConfig.relations[k];
|
37687
37704
|
const isSingle2 = is(relation, One);
|
37688
|
-
const targetTable = relation.targetTable;
|
37689
|
-
const relationFilter = relationToSQL(relation);
|
37705
|
+
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
37706
|
+
const relationFilter = relationToSQL(relation, table4, targetTable);
|
37690
37707
|
const innerQuery = this.buildRelationalQuery({
|
37691
37708
|
table: targetTable,
|
37692
37709
|
mode: isSingle2 ? "first" : "many",
|
37693
37710
|
schema: schema4,
|
37694
37711
|
queryConfig: join,
|
37695
|
-
tableConfig: schema4[tableNamesMap[getTableUniqueName(targetTable)]],
|
37712
|
+
tableConfig: schema4[tableNamesMap[getTableUniqueName(relation.targetTable)]],
|
37696
37713
|
tableNamesMap,
|
37697
37714
|
tables,
|
37698
|
-
relationWhere: relationFilter
|
37715
|
+
relationWhere: relationFilter,
|
37716
|
+
errorPath: `${currentPath.length ? `${currentPath}.` : ""}${k}`,
|
37717
|
+
depth: currentDepth + 1
|
37699
37718
|
});
|
37700
37719
|
selection.push({
|
37701
37720
|
field: targetTable,
|
@@ -37713,8 +37732,13 @@ var init_dialect3 = __esm({
|
|
37713
37732
|
})() : void 0;
|
37714
37733
|
if (extras?.sql)
|
37715
37734
|
selectionArr.push(extras.sql);
|
37735
|
+
if (!selectionArr.length) {
|
37736
|
+
throw new DrizzleError({
|
37737
|
+
message: `No fields selected for table "${tableConfig.tsName}"${currentPath ? ` ("${currentPath}")` : ""}`
|
37738
|
+
});
|
37739
|
+
}
|
37716
37740
|
const selectionSet = sql.join(selectionArr, sql`, `);
|
37717
|
-
const query = sql`select ${selectionSet} from ${table4}${sql`${joins}`.if(joins)}${sql` where ${where}`.if(where)}${sql` order by ${order}`.if(order)}${sql` limit ${limit}`.if(limit !== void 0)}${sql` offset ${offset}`.if(offset !== void 0)}`;
|
37741
|
+
const query = sql`select ${selectionSet} from ${table4[IsAlias] ? sql`${sql`${sql.identifier(table4[Schema] ?? "")}.`.if(table4[Schema])}${sql.identifier(table4[OriginalName])} as ${table4}` : table4}${sql`${joins}`.if(joins)}${sql` where ${where}`.if(where)}${sql` order by ${order}`.if(order)}${sql` limit ${limit}`.if(limit !== void 0)}${sql` offset ${offset}`.if(offset !== void 0)}`;
|
37718
37742
|
return {
|
37719
37743
|
sql: query,
|
37720
37744
|
selection
|
package/api.mjs
CHANGED
@@ -24038,7 +24038,7 @@ function defineRelations(schema4, relations) {
|
|
24038
24038
|
);
|
24039
24039
|
}
|
24040
24040
|
function relationsFieldFilterToSQL(column4, filter2) {
|
24041
|
-
if (typeof filter2 !== "object")
|
24041
|
+
if (typeof filter2 !== "object" || is(filter2, Placeholder))
|
24042
24042
|
return eq(column4, filter2);
|
24043
24043
|
const entries = Object.entries(filter2);
|
24044
24044
|
if (!entries.length)
|
@@ -24048,14 +24048,14 @@ function relationsFieldFilterToSQL(column4, filter2) {
|
|
24048
24048
|
if (value === void 0)
|
24049
24049
|
continue;
|
24050
24050
|
switch (target) {
|
24051
|
-
case "
|
24051
|
+
case "NOT": {
|
24052
24052
|
const res = relationsFieldFilterToSQL(column4, value);
|
24053
24053
|
if (!res)
|
24054
24054
|
continue;
|
24055
24055
|
parts.push(not(res));
|
24056
24056
|
continue;
|
24057
24057
|
}
|
24058
|
-
case "
|
24058
|
+
case "OR": {
|
24059
24059
|
if (!value.length)
|
24060
24060
|
continue;
|
24061
24061
|
parts.push(
|
@@ -24080,7 +24080,7 @@ function relationsFieldFilterToSQL(column4, filter2) {
|
|
24080
24080
|
return void 0;
|
24081
24081
|
return and(...parts);
|
24082
24082
|
}
|
24083
|
-
function
|
24083
|
+
function relationsFilterToSQL(table4, filter2) {
|
24084
24084
|
const entries = Object.entries(filter2);
|
24085
24085
|
if (!entries.length)
|
24086
24086
|
return void 0;
|
@@ -24089,7 +24089,7 @@ function relationFilterToSQL(table4, filter2) {
|
|
24089
24089
|
if (value === void 0)
|
24090
24090
|
continue;
|
24091
24091
|
switch (target) {
|
24092
|
-
case "
|
24092
|
+
case "RAW": {
|
24093
24093
|
if (value) {
|
24094
24094
|
parts.push(
|
24095
24095
|
value(table4[Columns], operators)
|
@@ -24097,30 +24097,25 @@ function relationFilterToSQL(table4, filter2) {
|
|
24097
24097
|
}
|
24098
24098
|
continue;
|
24099
24099
|
}
|
24100
|
-
case "
|
24100
|
+
case "OR": {
|
24101
24101
|
if (!value?.length)
|
24102
24102
|
continue;
|
24103
24103
|
parts.push(
|
24104
24104
|
or(
|
24105
24105
|
...value.map(
|
24106
|
-
(subFilter) =>
|
24106
|
+
(subFilter) => relationsFilterToSQL(table4, subFilter)
|
24107
24107
|
)
|
24108
24108
|
)
|
24109
24109
|
);
|
24110
24110
|
continue;
|
24111
24111
|
}
|
24112
|
-
case "
|
24113
|
-
if (
|
24112
|
+
case "NOT": {
|
24113
|
+
if (value === void 0)
|
24114
24114
|
continue;
|
24115
|
-
|
24116
|
-
|
24117
|
-
|
24118
|
-
|
24119
|
-
(subFilter) => relationFilterToSQL(table4, subFilter)
|
24120
|
-
)
|
24121
|
-
)
|
24122
|
-
)
|
24123
|
-
);
|
24115
|
+
const built = relationsFilterToSQL(table4, value);
|
24116
|
+
if (!built)
|
24117
|
+
continue;
|
24118
|
+
parts.push(not(built));
|
24124
24119
|
continue;
|
24125
24120
|
}
|
24126
24121
|
default: {
|
@@ -24161,13 +24156,15 @@ function relationExtrasToSQL(table4, extras) {
|
|
24161
24156
|
selection
|
24162
24157
|
};
|
24163
24158
|
}
|
24164
|
-
function relationToSQL(relation) {
|
24165
|
-
const table4 = relation.sourceTable;
|
24159
|
+
function relationToSQL(relation, sourceTable, targetTable) {
|
24166
24160
|
const columnWhere = relation.sourceColumns.map((s, i) => {
|
24167
24161
|
const t = relation.targetColumns[i];
|
24168
|
-
return eq(
|
24162
|
+
return eq(
|
24163
|
+
sql`${sql`${sql`${sql.identifier(sourceTable[Schema] ?? "")}.`.if(sourceTable[Schema] && !sourceTable[IsAlias])}`}${sourceTable}.${sql.identifier(s.name)}`,
|
24164
|
+
sql`${sql`${sql`${sql.identifier(targetTable[Schema] ?? "")}.`.if(targetTable[Schema] && !targetTable[IsAlias])}`}${targetTable}.${sql.identifier(t.name)}`
|
24165
|
+
);
|
24169
24166
|
});
|
24170
|
-
const targetWhere = relation.where ? and(...columnWhere,
|
24167
|
+
const targetWhere = relation.where ? and(...columnWhere, relationsFilterToSQL(sourceTable, relation.where)) : and(...columnWhere);
|
24171
24168
|
return targetWhere;
|
24172
24169
|
}
|
24173
24170
|
var _a118, Relations, _a119, Relation, _a120, _b95, One, _a121, _b96, Many, _a122, AggregatedField, _a123, _b97, Count, operators, orderByOperators, _a124, RelationsBuilderTable, _a125, RelationsBuilderColumn, _a126, RelationsHelperStatic;
|
@@ -24192,6 +24189,8 @@ var init_relations = __esm({
|
|
24192
24189
|
this.tables = tables;
|
24193
24190
|
this.config = config;
|
24194
24191
|
for (const [tsName, table4] of Object.entries(tables)) {
|
24192
|
+
if (!is(table4, Table2))
|
24193
|
+
continue;
|
24195
24194
|
this.tableNamesMap[getTableUniqueName(table4)] = tsName;
|
24196
24195
|
const tableConfig = this.tablesConfig[tsName] = {
|
24197
24196
|
table: table4,
|
@@ -24691,8 +24690,8 @@ __export(dist_exports, {
|
|
24691
24690
|
param: () => param,
|
24692
24691
|
placeholder: () => placeholder,
|
24693
24692
|
relationExtrasToSQL: () => relationExtrasToSQL,
|
24694
|
-
relationFilterToSQL: () => relationFilterToSQL,
|
24695
24693
|
relationToSQL: () => relationToSQL,
|
24694
|
+
relationsFilterToSQL: () => relationsFilterToSQL,
|
24696
24695
|
relationsOrderToSQL: () => relationsOrderToSQL,
|
24697
24696
|
sql: () => sql,
|
24698
24697
|
sum: () => sum,
|
@@ -25228,11 +25227,8 @@ var init_dialect = __esm({
|
|
25228
25227
|
});
|
25229
25228
|
}
|
25230
25229
|
}
|
25231
|
-
return columnIdentifiers.length ? sql.join(columnIdentifiers, sql`, `) :
|
25232
|
-
})() : (
|
25233
|
-
const columnIdentifiers = [this.unwrapAllColumns(table4, selection)];
|
25234
|
-
return sql.join(columnIdentifiers, sql`, `);
|
25235
|
-
})());
|
25230
|
+
return columnIdentifiers.length ? sql.join(columnIdentifiers, sql`, `) : void 0;
|
25231
|
+
})() : this.unwrapAllColumns(table4, selection));
|
25236
25232
|
this.casing = new CasingCache(config?.casing);
|
25237
25233
|
}
|
25238
25234
|
async migrate(migrations, session, config) {
|
@@ -25847,20 +25843,24 @@ var init_dialect = __esm({
|
|
25847
25843
|
tableConfig,
|
25848
25844
|
queryConfig: config,
|
25849
25845
|
relationWhere,
|
25850
|
-
mode
|
25846
|
+
mode,
|
25847
|
+
errorPath,
|
25848
|
+
depth
|
25851
25849
|
}) {
|
25852
25850
|
const selection = [];
|
25853
25851
|
const isSingle = mode === "first";
|
25854
25852
|
const params = config === true ? void 0 : config;
|
25853
|
+
const currentPath = errorPath ?? "";
|
25854
|
+
const currentDepth = depth ?? 0;
|
25855
25855
|
const limit = isSingle ? 1 : params?.limit;
|
25856
25856
|
const offset = params?.offset;
|
25857
|
-
const where = params?.where && relationWhere ? and(
|
25857
|
+
const where = params?.where && relationWhere ? and(relationsFilterToSQL(table4, params.where), relationWhere) : params?.where ? relationsFilterToSQL(table4, params.where) : relationWhere;
|
25858
25858
|
const order = params?.orderBy ? relationsOrderToSQL(table4, params.orderBy) : void 0;
|
25859
25859
|
const columns = this.buildColumns(table4, tableConfig, selection, params);
|
25860
25860
|
const extras = params?.extras ? relationExtrasToSQL(table4, params.extras) : void 0;
|
25861
25861
|
if (extras)
|
25862
25862
|
selection.push(...extras.selection);
|
25863
|
-
const selectionArr = [columns];
|
25863
|
+
const selectionArr = columns ? [columns] : [];
|
25864
25864
|
const joins = params ? (() => {
|
25865
25865
|
const { with: joins2 } = params;
|
25866
25866
|
if (!joins2)
|
@@ -25883,8 +25883,8 @@ var init_dialect = __esm({
|
|
25883
25883
|
}
|
25884
25884
|
const relation = tableConfig.relations[k];
|
25885
25885
|
const isSingle2 = is(relation, One);
|
25886
|
-
const targetTable = relation.targetTable;
|
25887
|
-
const relationFilter = relationToSQL(relation);
|
25886
|
+
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
25887
|
+
const relationFilter = relationToSQL(relation, table4, targetTable);
|
25888
25888
|
selectionArr.push(
|
25889
25889
|
isSingle2 ? sql`${sql.identifier(k)}.${sql.identifier("r")} as ${sql.identifier(k)}` : sql`coalesce(${sql.identifier(k)}.${sql.identifier("r")}, '[]') as ${sql.identifier(k)}`
|
25890
25890
|
);
|
@@ -25893,10 +25893,12 @@ var init_dialect = __esm({
|
|
25893
25893
|
mode: isSingle2 ? "first" : "many",
|
25894
25894
|
schema: schema4,
|
25895
25895
|
queryConfig: join,
|
25896
|
-
tableConfig: schema4[tableNamesMap[getTableUniqueName(targetTable)]],
|
25896
|
+
tableConfig: schema4[tableNamesMap[getTableUniqueName(relation.targetTable)]],
|
25897
25897
|
tableNamesMap,
|
25898
25898
|
tables,
|
25899
|
-
relationWhere: relationFilter
|
25899
|
+
relationWhere: relationFilter,
|
25900
|
+
errorPath: `${currentPath.length ? `${currentPath}.` : ""}${k}`,
|
25901
|
+
depth: currentDepth + 1
|
25900
25902
|
});
|
25901
25903
|
selection.push({
|
25902
25904
|
field: targetTable,
|
@@ -25911,8 +25913,13 @@ var init_dialect = __esm({
|
|
25911
25913
|
})() : void 0;
|
25912
25914
|
if (extras?.sql)
|
25913
25915
|
selectionArr.push(extras.sql);
|
25916
|
+
if (!selectionArr.length) {
|
25917
|
+
throw new DrizzleError({
|
25918
|
+
message: `No fields selected for table "${tableConfig.tsName}"${currentPath ? ` ("${currentPath}")` : ""}`
|
25919
|
+
});
|
25920
|
+
}
|
25914
25921
|
const selectionSet = sql.join(selectionArr.filter((e) => e !== void 0), sql`, `);
|
25915
|
-
const query = sql`select ${selectionSet} from ${table4}${sql` ${joins}`.if(joins)}${sql` where ${where}`.if(where)}${sql` order by ${order}`.if(order)}${sql` limit ${limit}`.if(limit !== void 0)}${sql` offset ${offset}`.if(offset !== void 0)}`;
|
25922
|
+
const query = sql`select ${selectionSet} from ${table4[IsAlias] ? sql`${sql`${sql.identifier(table4[Schema] ?? "")}.`.if(table4[Schema])}${sql.identifier(table4[OriginalName])} as ${table4}` : table4}${sql` ${joins}`.if(joins)}${sql` where ${where}`.if(where)}${sql` order by ${order}`.if(order)}${sql` limit ${limit}`.if(limit !== void 0)}${sql` offset ${offset}`.if(offset !== void 0)}`;
|
25916
25923
|
return {
|
25917
25924
|
sql: query,
|
25918
25925
|
selection
|
@@ -31373,11 +31380,8 @@ var init_dialect2 = __esm({
|
|
31373
31380
|
field: column4.column
|
31374
31381
|
});
|
31375
31382
|
}
|
31376
|
-
return columnIdentifiers.length ? sql.join(columnIdentifiers, sql`, `) :
|
31377
|
-
})() : (
|
31378
|
-
const columnIdentifiers = [this.unwrapAllColumns(table4, selection)];
|
31379
|
-
return sql.join(columnIdentifiers, sql`, `);
|
31380
|
-
})());
|
31383
|
+
return columnIdentifiers.length ? sql.join(columnIdentifiers, sql`, `) : void 0;
|
31384
|
+
})() : this.unwrapAllColumns(table4, selection));
|
31381
31385
|
this.casing = new CasingCache(config?.casing);
|
31382
31386
|
}
|
31383
31387
|
escapeName(name2) {
|
@@ -31924,15 +31928,19 @@ var init_dialect2 = __esm({
|
|
31924
31928
|
queryConfig: config,
|
31925
31929
|
relationWhere,
|
31926
31930
|
mode,
|
31927
|
-
isNested
|
31931
|
+
isNested,
|
31932
|
+
errorPath,
|
31933
|
+
depth
|
31928
31934
|
}) {
|
31929
31935
|
const selection = [];
|
31930
31936
|
const isSingle = mode === "first";
|
31931
31937
|
const params = config === true ? void 0 : config;
|
31938
|
+
const currentPath = errorPath ?? "";
|
31939
|
+
const currentDepth = depth ?? 0;
|
31932
31940
|
const limit = isSingle ? 1 : params?.limit;
|
31933
31941
|
const offset = params?.offset;
|
31934
31942
|
const columns = this.buildColumns(table4, selection, params);
|
31935
|
-
const where = params?.where && relationWhere ? and(
|
31943
|
+
const where = params?.where && relationWhere ? and(relationsFilterToSQL(table4, params.where), relationWhere) : params?.where ? relationsFilterToSQL(table4, params.where) : relationWhere;
|
31936
31944
|
const order = params?.orderBy ? relationsOrderToSQL(table4, params.orderBy) : void 0;
|
31937
31945
|
const extras = params?.extras ? relationExtrasToSQL(table4, params.extras) : void 0;
|
31938
31946
|
if (extras)
|
@@ -31959,17 +31967,19 @@ var init_dialect2 = __esm({
|
|
31959
31967
|
const relation = tableConfig.relations[k];
|
31960
31968
|
const isSingle2 = is(relation, One);
|
31961
31969
|
const targetTable = relation.targetTable;
|
31962
|
-
const relationFilter = relationToSQL(relation);
|
31970
|
+
const relationFilter = relationToSQL(relation, table4, targetTable);
|
31963
31971
|
const innerQuery = this.buildRelationalQuery({
|
31964
31972
|
table: targetTable,
|
31965
31973
|
mode: isSingle2 ? "first" : "many",
|
31966
31974
|
schema: schema4,
|
31967
31975
|
queryConfig: join,
|
31968
|
-
tableConfig: schema4[tableNamesMap[getTableUniqueName(targetTable)]],
|
31976
|
+
tableConfig: schema4[tableNamesMap[getTableUniqueName(relation.targetTable)]],
|
31969
31977
|
tableNamesMap,
|
31970
31978
|
tables,
|
31971
31979
|
relationWhere: relationFilter,
|
31972
|
-
isNested: true
|
31980
|
+
isNested: true,
|
31981
|
+
errorPath: `${currentPath.length ? `${currentPath}.` : ""}${k}`,
|
31982
|
+
depth: currentDepth + 1
|
31973
31983
|
});
|
31974
31984
|
selection.push({
|
31975
31985
|
field: targetTable,
|
@@ -31988,8 +31998,14 @@ var init_dialect2 = __esm({
|
|
31988
31998
|
sql`, `
|
31989
31999
|
);
|
31990
32000
|
})() : void 0;
|
31991
|
-
const
|
31992
|
-
|
32001
|
+
const selectionArr = [columns, extras?.sql, joins].filter((e) => e !== void 0);
|
32002
|
+
if (!selectionArr.length) {
|
32003
|
+
throw new DrizzleError({
|
32004
|
+
message: `No fields selected for table "${tableConfig.tsName}"${currentPath ? ` ("${currentPath}")` : ""}`
|
32005
|
+
});
|
32006
|
+
}
|
32007
|
+
const selectionSet = sql.join(selectionArr, sql`, `);
|
32008
|
+
const query = sql`select ${selectionSet} from ${table4[IsAlias] ? sql`${sql`${sql.identifier(table4[Schema] ?? "")}.`.if(table4[Schema])}${sql.identifier(table4[OriginalName])} as ${table4}` : table4}${sql` where ${where}`.if(where)}${sql` order by ${order}`.if(order)}${sql` limit ${limit}`.if(limit !== void 0)}${sql` offset ${offset}`.if(offset !== void 0)}`;
|
31993
32009
|
return {
|
31994
32010
|
sql: query,
|
31995
32011
|
selection
|
@@ -36848,11 +36864,8 @@ var init_dialect3 = __esm({
|
|
36848
36864
|
sql`${table4[column4.tsName]} as ${sql.identifier(column4.tsName)}`
|
36849
36865
|
);
|
36850
36866
|
}
|
36851
|
-
return columnIdentifiers.length ? sql.join(columnIdentifiers, sql`, `) :
|
36852
|
-
})() : (
|
36853
|
-
const columnIdentifiers = [this.unwrapAllColumns(table4, selection)];
|
36854
|
-
return sql.join(columnIdentifiers, sql`, `);
|
36855
|
-
})());
|
36867
|
+
return columnIdentifiers.length ? sql.join(columnIdentifiers, sql`, `) : void 0;
|
36868
|
+
})() : this.unwrapAllColumns(table4, selection));
|
36856
36869
|
this.casing = new CasingCache(config?.casing);
|
36857
36870
|
}
|
36858
36871
|
async migrate(migrations, session, config) {
|
@@ -37654,20 +37667,24 @@ var init_dialect3 = __esm({
|
|
37654
37667
|
tableConfig,
|
37655
37668
|
queryConfig: config,
|
37656
37669
|
relationWhere,
|
37657
|
-
mode
|
37670
|
+
mode,
|
37671
|
+
errorPath,
|
37672
|
+
depth
|
37658
37673
|
}) {
|
37659
37674
|
const selection = [];
|
37660
37675
|
const isSingle = mode === "first";
|
37661
37676
|
const params = config === true ? void 0 : config;
|
37677
|
+
const currentPath = errorPath ?? "";
|
37678
|
+
const currentDepth = depth ?? 0;
|
37662
37679
|
const limit = isSingle ? 1 : params?.limit;
|
37663
37680
|
const offset = params?.offset;
|
37664
37681
|
const columns = this.buildColumns(table4, selection, params);
|
37665
|
-
const where = params?.where && relationWhere ? and(
|
37682
|
+
const where = params?.where && relationWhere ? and(relationsFilterToSQL(table4, params.where), relationWhere) : params?.where ? relationsFilterToSQL(table4, params.where) : relationWhere;
|
37666
37683
|
const order = params?.orderBy ? relationsOrderToSQL(table4, params.orderBy) : void 0;
|
37667
37684
|
const extras = params?.extras ? relationExtrasToSQL(table4, params.extras) : void 0;
|
37668
37685
|
if (extras)
|
37669
37686
|
selection.push(...extras.selection);
|
37670
|
-
const selectionArr = [columns];
|
37687
|
+
const selectionArr = columns ? [columns] : [];
|
37671
37688
|
const joins = params ? (() => {
|
37672
37689
|
const { with: joins2 } = params;
|
37673
37690
|
if (!joins2)
|
@@ -37690,17 +37707,19 @@ var init_dialect3 = __esm({
|
|
37690
37707
|
}
|
37691
37708
|
const relation = tableConfig.relations[k];
|
37692
37709
|
const isSingle2 = is(relation, One);
|
37693
|
-
const targetTable = relation.targetTable;
|
37694
|
-
const relationFilter = relationToSQL(relation);
|
37710
|
+
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
37711
|
+
const relationFilter = relationToSQL(relation, table4, targetTable);
|
37695
37712
|
const innerQuery = this.buildRelationalQuery({
|
37696
37713
|
table: targetTable,
|
37697
37714
|
mode: isSingle2 ? "first" : "many",
|
37698
37715
|
schema: schema4,
|
37699
37716
|
queryConfig: join,
|
37700
|
-
tableConfig: schema4[tableNamesMap[getTableUniqueName(targetTable)]],
|
37717
|
+
tableConfig: schema4[tableNamesMap[getTableUniqueName(relation.targetTable)]],
|
37701
37718
|
tableNamesMap,
|
37702
37719
|
tables,
|
37703
|
-
relationWhere: relationFilter
|
37720
|
+
relationWhere: relationFilter,
|
37721
|
+
errorPath: `${currentPath.length ? `${currentPath}.` : ""}${k}`,
|
37722
|
+
depth: currentDepth + 1
|
37704
37723
|
});
|
37705
37724
|
selection.push({
|
37706
37725
|
field: targetTable,
|
@@ -37718,8 +37737,13 @@ var init_dialect3 = __esm({
|
|
37718
37737
|
})() : void 0;
|
37719
37738
|
if (extras?.sql)
|
37720
37739
|
selectionArr.push(extras.sql);
|
37740
|
+
if (!selectionArr.length) {
|
37741
|
+
throw new DrizzleError({
|
37742
|
+
message: `No fields selected for table "${tableConfig.tsName}"${currentPath ? ` ("${currentPath}")` : ""}`
|
37743
|
+
});
|
37744
|
+
}
|
37721
37745
|
const selectionSet = sql.join(selectionArr, sql`, `);
|
37722
|
-
const query = sql`select ${selectionSet} from ${table4}${sql`${joins}`.if(joins)}${sql` where ${where}`.if(where)}${sql` order by ${order}`.if(order)}${sql` limit ${limit}`.if(limit !== void 0)}${sql` offset ${offset}`.if(offset !== void 0)}`;
|
37746
|
+
const query = sql`select ${selectionSet} from ${table4[IsAlias] ? sql`${sql`${sql.identifier(table4[Schema] ?? "")}.`.if(table4[Schema])}${sql.identifier(table4[OriginalName])} as ${table4}` : table4}${sql`${joins}`.if(joins)}${sql` where ${where}`.if(where)}${sql` order by ${order}`.if(order)}${sql` limit ${limit}`.if(limit !== void 0)}${sql` offset ${offset}`.if(offset !== void 0)}`;
|
37723
37747
|
return {
|
37724
37748
|
sql: query,
|
37725
37749
|
selection
|
package/bin.cjs
CHANGED
@@ -89646,7 +89646,7 @@ init_utils2();
|
|
89646
89646
|
var version2 = async () => {
|
89647
89647
|
const { npmVersion } = await ormCoreVersions();
|
89648
89648
|
const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
|
89649
|
-
const envVersion = "0.28.1-
|
89649
|
+
const envVersion = "0.28.1-66f461a";
|
89650
89650
|
const kitVersion = envVersion ? `v${envVersion}` : "--";
|
89651
89651
|
const versions = `drizzle-kit: ${kitVersion}
|
89652
89652
|
${ormVersion}`;
|