drizzle-kit 0.30.4-c417a27 → 0.30.4-d004082
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 +105 -64
- package/api.mjs +105 -64
- package/bin.cjs +132 -82
- package/package.json +1 -1
package/api.js
CHANGED
@@ -23202,6 +23202,16 @@ function relationsFieldFilterToSQL(column5, filter2) {
|
|
23202
23202
|
);
|
23203
23203
|
continue;
|
23204
23204
|
}
|
23205
|
+
case "AND": {
|
23206
|
+
if (!value.length)
|
23207
|
+
continue;
|
23208
|
+
parts.push(
|
23209
|
+
and(
|
23210
|
+
...value.map((subFilter) => relationsFieldFilterToSQL(column5, subFilter))
|
23211
|
+
)
|
23212
|
+
);
|
23213
|
+
continue;
|
23214
|
+
}
|
23205
23215
|
case "isNotNull":
|
23206
23216
|
case "isNull": {
|
23207
23217
|
if (!value)
|
@@ -23232,7 +23242,7 @@ function relationsFieldFilterToSQL(column5, filter2) {
|
|
23232
23242
|
return void 0;
|
23233
23243
|
return and(...parts);
|
23234
23244
|
}
|
23235
|
-
function relationsFilterToSQL(table5, filter2) {
|
23245
|
+
function relationsFilterToSQL(table5, filter2, tableRelations = {}, tablesRelations = {}, tableNamesMap = {}, casing2, depth = 0) {
|
23236
23246
|
const entries = Object.entries(filter2);
|
23237
23247
|
if (!entries.length)
|
23238
23248
|
return void 0;
|
@@ -23242,11 +23252,8 @@ function relationsFilterToSQL(table5, filter2) {
|
|
23242
23252
|
continue;
|
23243
23253
|
switch (target) {
|
23244
23254
|
case "RAW": {
|
23245
|
-
|
23246
|
-
|
23247
|
-
value(table5, operators)
|
23248
|
-
);
|
23249
|
-
}
|
23255
|
+
const processed = typeof value === "function" ? value(table5, operators) : value.getSQL();
|
23256
|
+
parts.push(processed);
|
23250
23257
|
continue;
|
23251
23258
|
}
|
23252
23259
|
case "OR": {
|
@@ -23254,7 +23261,21 @@ function relationsFilterToSQL(table5, filter2) {
|
|
23254
23261
|
continue;
|
23255
23262
|
parts.push(
|
23256
23263
|
or(
|
23257
|
-
...value.map(
|
23264
|
+
...value.map(
|
23265
|
+
(subFilter) => relationsFilterToSQL(table5, subFilter, tableRelations, tablesRelations, tableNamesMap, casing2, depth)
|
23266
|
+
)
|
23267
|
+
)
|
23268
|
+
);
|
23269
|
+
continue;
|
23270
|
+
}
|
23271
|
+
case "AND": {
|
23272
|
+
if (!value?.length)
|
23273
|
+
continue;
|
23274
|
+
parts.push(
|
23275
|
+
and(
|
23276
|
+
...value.map(
|
23277
|
+
(subFilter) => relationsFilterToSQL(table5, subFilter, tableRelations, tablesRelations, tableNamesMap, casing2, depth)
|
23278
|
+
)
|
23258
23279
|
)
|
23259
23280
|
);
|
23260
23281
|
continue;
|
@@ -23262,21 +23283,60 @@ function relationsFilterToSQL(table5, filter2) {
|
|
23262
23283
|
case "NOT": {
|
23263
23284
|
if (value === void 0)
|
23264
23285
|
continue;
|
23265
|
-
const built = relationsFilterToSQL(
|
23286
|
+
const built = relationsFilterToSQL(
|
23287
|
+
table5,
|
23288
|
+
value,
|
23289
|
+
tableRelations,
|
23290
|
+
tablesRelations,
|
23291
|
+
tableNamesMap,
|
23292
|
+
casing2,
|
23293
|
+
depth
|
23294
|
+
);
|
23266
23295
|
if (!built)
|
23267
23296
|
continue;
|
23268
23297
|
parts.push(not(built));
|
23269
23298
|
continue;
|
23270
23299
|
}
|
23271
23300
|
default: {
|
23272
|
-
|
23273
|
-
|
23274
|
-
|
23275
|
-
|
23301
|
+
if (table5[Columns][target]) {
|
23302
|
+
const column5 = fieldSelectionToSQL(table5, target);
|
23303
|
+
const colFilter = relationsFieldFilterToSQL(
|
23304
|
+
column5,
|
23305
|
+
value
|
23306
|
+
);
|
23307
|
+
if (colFilter)
|
23308
|
+
parts.push(colFilter);
|
23309
|
+
continue;
|
23310
|
+
}
|
23311
|
+
const relation = tableRelations[target];
|
23312
|
+
if (!relation) {
|
23313
|
+
throw new DrizzleError({
|
23314
|
+
message: `Unknown relational filter field: "${target}"`
|
23315
|
+
});
|
23316
|
+
}
|
23317
|
+
const targetTable = aliasedTable(relation.targetTable, `f${depth}`);
|
23318
|
+
const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `ft${depth}`) : void 0;
|
23319
|
+
const targetConfig = tablesRelations[tableNamesMap[getTableUniqueName(relation.targetTable)]];
|
23320
|
+
const {
|
23321
|
+
filter: relationFilter,
|
23322
|
+
joinCondition
|
23323
|
+
} = relationToSQL(casing2, relation, table5, targetTable, throughTable);
|
23324
|
+
const subfilter = typeof value === "boolean" ? void 0 : relationsFilterToSQL(
|
23325
|
+
targetTable,
|
23326
|
+
value,
|
23327
|
+
targetConfig.relations,
|
23328
|
+
tablesRelations,
|
23329
|
+
tableNamesMap,
|
23330
|
+
casing2,
|
23331
|
+
depth + 1
|
23276
23332
|
);
|
23277
|
-
|
23278
|
-
|
23279
|
-
|
23333
|
+
const filter22 = and(
|
23334
|
+
relationFilter,
|
23335
|
+
subfilter
|
23336
|
+
);
|
23337
|
+
const subquery = throughTable ? sql`(select * from ${getTableAsAliasSQL(targetTable)} inner join ${getTableAsAliasSQL(throughTable)} on ${joinCondition}${sql` where ${filter22}`.if(filter22)} limit 1)` : sql`(select * from ${getTableAsAliasSQL(targetTable)}${sql` where ${filter22}`.if(filter22)} limit 1)`;
|
23338
|
+
if (filter22)
|
23339
|
+
parts.push((value ? exists : notExists)(subquery));
|
23280
23340
|
}
|
23281
23341
|
}
|
23282
23342
|
}
|
@@ -23316,37 +23376,35 @@ function relationExtrasToSQL(table5, extras) {
|
|
23316
23376
|
selection
|
23317
23377
|
};
|
23318
23378
|
}
|
23319
|
-
function relationToSQL(relation, sourceTable, targetTable, throughTable) {
|
23379
|
+
function relationToSQL(casing2, relation, sourceTable, targetTable, throughTable) {
|
23320
23380
|
if (relation.through) {
|
23321
23381
|
const outerColumnWhere = relation.sourceColumns.map((s, i) => {
|
23322
23382
|
const t = relation.through.source[i];
|
23323
23383
|
return eq(
|
23324
|
-
sql`${sourceTable}.${sql.identifier(s
|
23325
|
-
sql`${throughTable}.${sql.identifier(is(t._.column, Column2) ? t._.column
|
23384
|
+
sql`${sourceTable}.${sql.identifier(casing2.getColumnCasing(s))}`,
|
23385
|
+
sql`${throughTable}.${sql.identifier(is(t._.column, Column2) ? casing2.getColumnCasing(t._.column) : t._.key)}`
|
23326
23386
|
);
|
23327
23387
|
});
|
23328
23388
|
const innerColumnWhere = relation.targetColumns.map((s, i) => {
|
23329
23389
|
const t = relation.through.target[i];
|
23330
23390
|
return eq(
|
23331
|
-
sql`${throughTable}.${sql.identifier(is(t._.column, Column2) ? t._.column
|
23332
|
-
sql`${targetTable}.${sql.identifier(s
|
23391
|
+
sql`${throughTable}.${sql.identifier(is(t._.column, Column2) ? casing2.getColumnCasing(t._.column) : t._.key)}`,
|
23392
|
+
sql`${targetTable}.${sql.identifier(casing2.getColumnCasing(s))}`
|
23333
23393
|
);
|
23334
23394
|
});
|
23335
23395
|
return {
|
23336
23396
|
filter: and(
|
23337
|
-
relation.where ? relationsFilterToSQL(relation.isReversed ? targetTable : sourceTable, relation.where) : void 0
|
23397
|
+
relation.where ? relationsFilterToSQL(relation.isReversed ? targetTable : sourceTable, relation.where) : void 0,
|
23398
|
+
...outerColumnWhere
|
23338
23399
|
),
|
23339
|
-
joinCondition: and(
|
23340
|
-
...outerColumnWhere,
|
23341
|
-
...innerColumnWhere
|
23342
|
-
)
|
23400
|
+
joinCondition: and(...innerColumnWhere)
|
23343
23401
|
};
|
23344
23402
|
}
|
23345
23403
|
const columnWhere = relation.sourceColumns.map((s, i) => {
|
23346
23404
|
const t = relation.targetColumns[i];
|
23347
23405
|
return eq(
|
23348
|
-
sql`${sourceTable}.${sql.identifier(s
|
23349
|
-
sql`${targetTable}.${sql.identifier(t
|
23406
|
+
sql`${sourceTable}.${sql.identifier(casing2.getColumnCasing(s))}`,
|
23407
|
+
sql`${targetTable}.${sql.identifier(casing2.getColumnCasing(t))}`
|
23350
23408
|
);
|
23351
23409
|
});
|
23352
23410
|
const fullWhere = and(
|
@@ -23364,8 +23422,10 @@ var init_relations = __esm({
|
|
23364
23422
|
"use strict";
|
23365
23423
|
init_table();
|
23366
23424
|
init_table();
|
23425
|
+
init_alias();
|
23367
23426
|
init_column();
|
23368
23427
|
init_entity();
|
23428
|
+
init_errors();
|
23369
23429
|
init_expressions();
|
23370
23430
|
init_sql();
|
23371
23431
|
_a35 = entityKind;
|
@@ -27094,7 +27154,7 @@ var init_dialect = __esm({
|
|
27094
27154
|
});
|
27095
27155
|
}
|
27096
27156
|
buildRqbColumn(column5, key) {
|
27097
|
-
return sql`${is(column5, Column2) ? sql.identifier(column5
|
27157
|
+
return sql`${is(column5, Column2) ? sql.identifier(this.casing.getColumnCasing(column5)) : is(column5, SQL.Aliased) ? sql.identifier(column5.fieldAlias) : isSQLWrapper(column5) ? sql.identifier(key) : this.nestedSelectionerror()} as ${sql.identifier(key)}`;
|
27098
27158
|
}
|
27099
27159
|
buildRelationalQuery({
|
27100
27160
|
tables,
|
@@ -27118,7 +27178,10 @@ var init_dialect = __esm({
|
|
27118
27178
|
table5 = aliasedTable(table5, `d${currentDepth}`);
|
27119
27179
|
const limit = isSingle ? 1 : params?.limit;
|
27120
27180
|
const offset = params?.offset;
|
27121
|
-
const where = params?.where && relationWhere ? and(
|
27181
|
+
const where = params?.where && relationWhere ? and(
|
27182
|
+
relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap, this.casing),
|
27183
|
+
relationWhere
|
27184
|
+
) : params?.where ? relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap, this.casing) : relationWhere;
|
27122
27185
|
const order = params?.orderBy ? relationsOrderToSQL(table5, params.orderBy) : void 0;
|
27123
27186
|
const columns = this.buildColumns(table5, selection, params);
|
27124
27187
|
const extras = params?.extras ? relationExtrasToSQL(table5, params.extras) : void 0;
|
@@ -27134,22 +27197,12 @@ var init_dialect = __esm({
|
|
27134
27197
|
return;
|
27135
27198
|
return sql.join(
|
27136
27199
|
withEntries.map(([k, join]) => {
|
27137
|
-
if (is(tableConfig.relations[k], AggregatedField)) {
|
27138
|
-
const relation2 = tableConfig.relations[k];
|
27139
|
-
relation2.onTable(table5);
|
27140
|
-
const query2 = relation2.getSQL();
|
27141
|
-
selection.push({
|
27142
|
-
key: k,
|
27143
|
-
field: relation2
|
27144
|
-
});
|
27145
|
-
selectionArr.push(sql`${sql.identifier(k)}.${sql.identifier("r")} as ${sql.identifier(k)}`);
|
27146
|
-
return sql`left join lateral(${query2}) as ${sql.identifier(k)} on true`;
|
27147
|
-
}
|
27148
27200
|
const relation = tableConfig.relations[k];
|
27149
27201
|
const isSingle2 = is(relation, One);
|
27150
27202
|
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
27151
27203
|
const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `tr${currentDepth}`) : void 0;
|
27152
27204
|
const { filter: filter2, joinCondition } = relationToSQL(
|
27205
|
+
this.casing,
|
27153
27206
|
relation,
|
27154
27207
|
table5,
|
27155
27208
|
targetTable,
|
@@ -33137,7 +33190,7 @@ var init_dialect2 = __esm({
|
|
33137
33190
|
});
|
33138
33191
|
}
|
33139
33192
|
buildRqbColumn(column5, key) {
|
33140
|
-
return sql`${is(column5, Column2) ? sql.identifier(column5
|
33193
|
+
return sql`${is(column5, Column2) ? sql.identifier(this.casing.getColumnCasing(column5)) : is(column5, SQL.Aliased) ? sql.identifier(column5.fieldAlias) : isSQLWrapper(column5) ? sql.identifier(key) : this.nestedSelectionerror()} as ${sql.identifier(key)}`;
|
33141
33194
|
}
|
33142
33195
|
buildRelationalQuery({
|
33143
33196
|
tables,
|
@@ -33163,7 +33216,10 @@ var init_dialect2 = __esm({
|
|
33163
33216
|
const limit = isSingle ? 1 : params?.limit;
|
33164
33217
|
const offset = params?.offset;
|
33165
33218
|
const columns = this.buildColumns(table5, selection, params);
|
33166
|
-
const where = params?.where && relationWhere ? and(
|
33219
|
+
const where = params?.where && relationWhere ? and(
|
33220
|
+
relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap, this.casing),
|
33221
|
+
relationWhere
|
33222
|
+
) : params?.where ? relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap, this.casing) : relationWhere;
|
33167
33223
|
const order = params?.orderBy ? relationsOrderToSQL(table5, params.orderBy) : void 0;
|
33168
33224
|
const extras = params?.extras ? relationExtrasToSQL(table5, params.extras) : void 0;
|
33169
33225
|
if (extras)
|
@@ -33177,21 +33233,12 @@ var init_dialect2 = __esm({
|
|
33177
33233
|
return;
|
33178
33234
|
return sql.join(
|
33179
33235
|
withEntries.map(([k, join]) => {
|
33180
|
-
if (is(tableConfig.relations[k], AggregatedField)) {
|
33181
|
-
const relation2 = tableConfig.relations[k];
|
33182
|
-
relation2.onTable(table5);
|
33183
|
-
const query2 = relation2.getSQL();
|
33184
|
-
selection.push({
|
33185
|
-
key: k,
|
33186
|
-
field: relation2
|
33187
|
-
});
|
33188
|
-
return sql`(${query2}) as ${sql.identifier(k)}`;
|
33189
|
-
}
|
33190
33236
|
const relation = tableConfig.relations[k];
|
33191
33237
|
const isSingle2 = is(relation, One);
|
33192
33238
|
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
33193
33239
|
const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `tr${currentDepth}`) : void 0;
|
33194
33240
|
const { filter: filter2, joinCondition } = relationToSQL(
|
33241
|
+
this.casing,
|
33195
33242
|
relation,
|
33196
33243
|
table5,
|
33197
33244
|
targetTable,
|
@@ -38957,7 +39004,7 @@ var init_dialect3 = __esm({
|
|
38957
39004
|
});
|
38958
39005
|
}
|
38959
39006
|
buildRqbColumn(column5, key) {
|
38960
|
-
return sql`${is(column5, Column2) ? sql.identifier(column5
|
39007
|
+
return sql`${is(column5, Column2) ? sql.identifier(this.casing.getColumnCasing(column5)) : is(column5, SQL.Aliased) ? sql.identifier(column5.fieldAlias) : isSQLWrapper(column5) ? sql.identifier(key) : this.nestedSelectionerror()} as ${sql.identifier(key)}`;
|
38961
39008
|
}
|
38962
39009
|
buildRelationalQuery({
|
38963
39010
|
tables,
|
@@ -38983,7 +39030,10 @@ var init_dialect3 = __esm({
|
|
38983
39030
|
const limit = isSingle ? 1 : params?.limit;
|
38984
39031
|
const offset = params?.offset;
|
38985
39032
|
const columns = this.buildColumns(table5, selection, params);
|
38986
|
-
const where = params?.where && relationWhere ? and(
|
39033
|
+
const where = params?.where && relationWhere ? and(
|
39034
|
+
relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap, this.casing),
|
39035
|
+
relationWhere
|
39036
|
+
) : params?.where ? relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap, this.casing) : relationWhere;
|
38987
39037
|
const order = params?.orderBy ? relationsOrderToSQL(table5, params.orderBy) : void 0;
|
38988
39038
|
const extras = params?.extras ? relationExtrasToSQL(table5, params.extras) : void 0;
|
38989
39039
|
if (extras)
|
@@ -38999,21 +39049,12 @@ var init_dialect3 = __esm({
|
|
38999
39049
|
return sql.join(
|
39000
39050
|
withEntries.map(([k, join]) => {
|
39001
39051
|
selectionArr.push(sql`${sql.identifier(k)}.${sql.identifier("r")} as ${sql.identifier(k)}`);
|
39002
|
-
if (is(tableConfig.relations[k], AggregatedField)) {
|
39003
|
-
const relation2 = tableConfig.relations[k];
|
39004
|
-
relation2.onTable(table5);
|
39005
|
-
const query2 = relation2.getSQL();
|
39006
|
-
selection.push({
|
39007
|
-
key: k,
|
39008
|
-
field: relation2
|
39009
|
-
});
|
39010
|
-
return sql` left join lateral (${query2}) as ${sql.identifier(k)} on true`;
|
39011
|
-
}
|
39012
39052
|
const relation = tableConfig.relations[k];
|
39013
39053
|
const isSingle2 = is(relation, One);
|
39014
39054
|
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
39015
39055
|
const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `tr${currentDepth}`) : void 0;
|
39016
39056
|
const { filter: filter2, joinCondition } = relationToSQL(
|
39057
|
+
this.casing,
|
39017
39058
|
relation,
|
39018
39059
|
table5,
|
39019
39060
|
targetTable,
|
package/api.mjs
CHANGED
@@ -23207,6 +23207,16 @@ function relationsFieldFilterToSQL(column5, filter2) {
|
|
23207
23207
|
);
|
23208
23208
|
continue;
|
23209
23209
|
}
|
23210
|
+
case "AND": {
|
23211
|
+
if (!value.length)
|
23212
|
+
continue;
|
23213
|
+
parts.push(
|
23214
|
+
and(
|
23215
|
+
...value.map((subFilter) => relationsFieldFilterToSQL(column5, subFilter))
|
23216
|
+
)
|
23217
|
+
);
|
23218
|
+
continue;
|
23219
|
+
}
|
23210
23220
|
case "isNotNull":
|
23211
23221
|
case "isNull": {
|
23212
23222
|
if (!value)
|
@@ -23237,7 +23247,7 @@ function relationsFieldFilterToSQL(column5, filter2) {
|
|
23237
23247
|
return void 0;
|
23238
23248
|
return and(...parts);
|
23239
23249
|
}
|
23240
|
-
function relationsFilterToSQL(table5, filter2) {
|
23250
|
+
function relationsFilterToSQL(table5, filter2, tableRelations = {}, tablesRelations = {}, tableNamesMap = {}, casing2, depth = 0) {
|
23241
23251
|
const entries = Object.entries(filter2);
|
23242
23252
|
if (!entries.length)
|
23243
23253
|
return void 0;
|
@@ -23247,11 +23257,8 @@ function relationsFilterToSQL(table5, filter2) {
|
|
23247
23257
|
continue;
|
23248
23258
|
switch (target) {
|
23249
23259
|
case "RAW": {
|
23250
|
-
|
23251
|
-
|
23252
|
-
value(table5, operators)
|
23253
|
-
);
|
23254
|
-
}
|
23260
|
+
const processed = typeof value === "function" ? value(table5, operators) : value.getSQL();
|
23261
|
+
parts.push(processed);
|
23255
23262
|
continue;
|
23256
23263
|
}
|
23257
23264
|
case "OR": {
|
@@ -23259,7 +23266,21 @@ function relationsFilterToSQL(table5, filter2) {
|
|
23259
23266
|
continue;
|
23260
23267
|
parts.push(
|
23261
23268
|
or(
|
23262
|
-
...value.map(
|
23269
|
+
...value.map(
|
23270
|
+
(subFilter) => relationsFilterToSQL(table5, subFilter, tableRelations, tablesRelations, tableNamesMap, casing2, depth)
|
23271
|
+
)
|
23272
|
+
)
|
23273
|
+
);
|
23274
|
+
continue;
|
23275
|
+
}
|
23276
|
+
case "AND": {
|
23277
|
+
if (!value?.length)
|
23278
|
+
continue;
|
23279
|
+
parts.push(
|
23280
|
+
and(
|
23281
|
+
...value.map(
|
23282
|
+
(subFilter) => relationsFilterToSQL(table5, subFilter, tableRelations, tablesRelations, tableNamesMap, casing2, depth)
|
23283
|
+
)
|
23263
23284
|
)
|
23264
23285
|
);
|
23265
23286
|
continue;
|
@@ -23267,21 +23288,60 @@ function relationsFilterToSQL(table5, filter2) {
|
|
23267
23288
|
case "NOT": {
|
23268
23289
|
if (value === void 0)
|
23269
23290
|
continue;
|
23270
|
-
const built = relationsFilterToSQL(
|
23291
|
+
const built = relationsFilterToSQL(
|
23292
|
+
table5,
|
23293
|
+
value,
|
23294
|
+
tableRelations,
|
23295
|
+
tablesRelations,
|
23296
|
+
tableNamesMap,
|
23297
|
+
casing2,
|
23298
|
+
depth
|
23299
|
+
);
|
23271
23300
|
if (!built)
|
23272
23301
|
continue;
|
23273
23302
|
parts.push(not(built));
|
23274
23303
|
continue;
|
23275
23304
|
}
|
23276
23305
|
default: {
|
23277
|
-
|
23278
|
-
|
23279
|
-
|
23280
|
-
|
23306
|
+
if (table5[Columns][target]) {
|
23307
|
+
const column5 = fieldSelectionToSQL(table5, target);
|
23308
|
+
const colFilter = relationsFieldFilterToSQL(
|
23309
|
+
column5,
|
23310
|
+
value
|
23311
|
+
);
|
23312
|
+
if (colFilter)
|
23313
|
+
parts.push(colFilter);
|
23314
|
+
continue;
|
23315
|
+
}
|
23316
|
+
const relation = tableRelations[target];
|
23317
|
+
if (!relation) {
|
23318
|
+
throw new DrizzleError({
|
23319
|
+
message: `Unknown relational filter field: "${target}"`
|
23320
|
+
});
|
23321
|
+
}
|
23322
|
+
const targetTable = aliasedTable(relation.targetTable, `f${depth}`);
|
23323
|
+
const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `ft${depth}`) : void 0;
|
23324
|
+
const targetConfig = tablesRelations[tableNamesMap[getTableUniqueName(relation.targetTable)]];
|
23325
|
+
const {
|
23326
|
+
filter: relationFilter,
|
23327
|
+
joinCondition
|
23328
|
+
} = relationToSQL(casing2, relation, table5, targetTable, throughTable);
|
23329
|
+
const subfilter = typeof value === "boolean" ? void 0 : relationsFilterToSQL(
|
23330
|
+
targetTable,
|
23331
|
+
value,
|
23332
|
+
targetConfig.relations,
|
23333
|
+
tablesRelations,
|
23334
|
+
tableNamesMap,
|
23335
|
+
casing2,
|
23336
|
+
depth + 1
|
23281
23337
|
);
|
23282
|
-
|
23283
|
-
|
23284
|
-
|
23338
|
+
const filter22 = and(
|
23339
|
+
relationFilter,
|
23340
|
+
subfilter
|
23341
|
+
);
|
23342
|
+
const subquery = throughTable ? sql`(select * from ${getTableAsAliasSQL(targetTable)} inner join ${getTableAsAliasSQL(throughTable)} on ${joinCondition}${sql` where ${filter22}`.if(filter22)} limit 1)` : sql`(select * from ${getTableAsAliasSQL(targetTable)}${sql` where ${filter22}`.if(filter22)} limit 1)`;
|
23343
|
+
if (filter22)
|
23344
|
+
parts.push((value ? exists : notExists)(subquery));
|
23285
23345
|
}
|
23286
23346
|
}
|
23287
23347
|
}
|
@@ -23321,37 +23381,35 @@ function relationExtrasToSQL(table5, extras) {
|
|
23321
23381
|
selection
|
23322
23382
|
};
|
23323
23383
|
}
|
23324
|
-
function relationToSQL(relation, sourceTable, targetTable, throughTable) {
|
23384
|
+
function relationToSQL(casing2, relation, sourceTable, targetTable, throughTable) {
|
23325
23385
|
if (relation.through) {
|
23326
23386
|
const outerColumnWhere = relation.sourceColumns.map((s, i) => {
|
23327
23387
|
const t = relation.through.source[i];
|
23328
23388
|
return eq(
|
23329
|
-
sql`${sourceTable}.${sql.identifier(s
|
23330
|
-
sql`${throughTable}.${sql.identifier(is(t._.column, Column2) ? t._.column
|
23389
|
+
sql`${sourceTable}.${sql.identifier(casing2.getColumnCasing(s))}`,
|
23390
|
+
sql`${throughTable}.${sql.identifier(is(t._.column, Column2) ? casing2.getColumnCasing(t._.column) : t._.key)}`
|
23331
23391
|
);
|
23332
23392
|
});
|
23333
23393
|
const innerColumnWhere = relation.targetColumns.map((s, i) => {
|
23334
23394
|
const t = relation.through.target[i];
|
23335
23395
|
return eq(
|
23336
|
-
sql`${throughTable}.${sql.identifier(is(t._.column, Column2) ? t._.column
|
23337
|
-
sql`${targetTable}.${sql.identifier(s
|
23396
|
+
sql`${throughTable}.${sql.identifier(is(t._.column, Column2) ? casing2.getColumnCasing(t._.column) : t._.key)}`,
|
23397
|
+
sql`${targetTable}.${sql.identifier(casing2.getColumnCasing(s))}`
|
23338
23398
|
);
|
23339
23399
|
});
|
23340
23400
|
return {
|
23341
23401
|
filter: and(
|
23342
|
-
relation.where ? relationsFilterToSQL(relation.isReversed ? targetTable : sourceTable, relation.where) : void 0
|
23402
|
+
relation.where ? relationsFilterToSQL(relation.isReversed ? targetTable : sourceTable, relation.where) : void 0,
|
23403
|
+
...outerColumnWhere
|
23343
23404
|
),
|
23344
|
-
joinCondition: and(
|
23345
|
-
...outerColumnWhere,
|
23346
|
-
...innerColumnWhere
|
23347
|
-
)
|
23405
|
+
joinCondition: and(...innerColumnWhere)
|
23348
23406
|
};
|
23349
23407
|
}
|
23350
23408
|
const columnWhere = relation.sourceColumns.map((s, i) => {
|
23351
23409
|
const t = relation.targetColumns[i];
|
23352
23410
|
return eq(
|
23353
|
-
sql`${sourceTable}.${sql.identifier(s
|
23354
|
-
sql`${targetTable}.${sql.identifier(t
|
23411
|
+
sql`${sourceTable}.${sql.identifier(casing2.getColumnCasing(s))}`,
|
23412
|
+
sql`${targetTable}.${sql.identifier(casing2.getColumnCasing(t))}`
|
23355
23413
|
);
|
23356
23414
|
});
|
23357
23415
|
const fullWhere = and(
|
@@ -23369,8 +23427,10 @@ var init_relations = __esm({
|
|
23369
23427
|
"use strict";
|
23370
23428
|
init_table();
|
23371
23429
|
init_table();
|
23430
|
+
init_alias();
|
23372
23431
|
init_column();
|
23373
23432
|
init_entity();
|
23433
|
+
init_errors();
|
23374
23434
|
init_expressions();
|
23375
23435
|
init_sql();
|
23376
23436
|
_a35 = entityKind;
|
@@ -27099,7 +27159,7 @@ var init_dialect = __esm({
|
|
27099
27159
|
});
|
27100
27160
|
}
|
27101
27161
|
buildRqbColumn(column5, key) {
|
27102
|
-
return sql`${is(column5, Column2) ? sql.identifier(column5
|
27162
|
+
return sql`${is(column5, Column2) ? sql.identifier(this.casing.getColumnCasing(column5)) : is(column5, SQL.Aliased) ? sql.identifier(column5.fieldAlias) : isSQLWrapper(column5) ? sql.identifier(key) : this.nestedSelectionerror()} as ${sql.identifier(key)}`;
|
27103
27163
|
}
|
27104
27164
|
buildRelationalQuery({
|
27105
27165
|
tables,
|
@@ -27123,7 +27183,10 @@ var init_dialect = __esm({
|
|
27123
27183
|
table5 = aliasedTable(table5, `d${currentDepth}`);
|
27124
27184
|
const limit = isSingle ? 1 : params?.limit;
|
27125
27185
|
const offset = params?.offset;
|
27126
|
-
const where = params?.where && relationWhere ? and(
|
27186
|
+
const where = params?.where && relationWhere ? and(
|
27187
|
+
relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap, this.casing),
|
27188
|
+
relationWhere
|
27189
|
+
) : params?.where ? relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap, this.casing) : relationWhere;
|
27127
27190
|
const order = params?.orderBy ? relationsOrderToSQL(table5, params.orderBy) : void 0;
|
27128
27191
|
const columns = this.buildColumns(table5, selection, params);
|
27129
27192
|
const extras = params?.extras ? relationExtrasToSQL(table5, params.extras) : void 0;
|
@@ -27139,22 +27202,12 @@ var init_dialect = __esm({
|
|
27139
27202
|
return;
|
27140
27203
|
return sql.join(
|
27141
27204
|
withEntries.map(([k, join]) => {
|
27142
|
-
if (is(tableConfig.relations[k], AggregatedField)) {
|
27143
|
-
const relation2 = tableConfig.relations[k];
|
27144
|
-
relation2.onTable(table5);
|
27145
|
-
const query2 = relation2.getSQL();
|
27146
|
-
selection.push({
|
27147
|
-
key: k,
|
27148
|
-
field: relation2
|
27149
|
-
});
|
27150
|
-
selectionArr.push(sql`${sql.identifier(k)}.${sql.identifier("r")} as ${sql.identifier(k)}`);
|
27151
|
-
return sql`left join lateral(${query2}) as ${sql.identifier(k)} on true`;
|
27152
|
-
}
|
27153
27205
|
const relation = tableConfig.relations[k];
|
27154
27206
|
const isSingle2 = is(relation, One);
|
27155
27207
|
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
27156
27208
|
const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `tr${currentDepth}`) : void 0;
|
27157
27209
|
const { filter: filter2, joinCondition } = relationToSQL(
|
27210
|
+
this.casing,
|
27158
27211
|
relation,
|
27159
27212
|
table5,
|
27160
27213
|
targetTable,
|
@@ -33142,7 +33195,7 @@ var init_dialect2 = __esm({
|
|
33142
33195
|
});
|
33143
33196
|
}
|
33144
33197
|
buildRqbColumn(column5, key) {
|
33145
|
-
return sql`${is(column5, Column2) ? sql.identifier(column5
|
33198
|
+
return sql`${is(column5, Column2) ? sql.identifier(this.casing.getColumnCasing(column5)) : is(column5, SQL.Aliased) ? sql.identifier(column5.fieldAlias) : isSQLWrapper(column5) ? sql.identifier(key) : this.nestedSelectionerror()} as ${sql.identifier(key)}`;
|
33146
33199
|
}
|
33147
33200
|
buildRelationalQuery({
|
33148
33201
|
tables,
|
@@ -33168,7 +33221,10 @@ var init_dialect2 = __esm({
|
|
33168
33221
|
const limit = isSingle ? 1 : params?.limit;
|
33169
33222
|
const offset = params?.offset;
|
33170
33223
|
const columns = this.buildColumns(table5, selection, params);
|
33171
|
-
const where = params?.where && relationWhere ? and(
|
33224
|
+
const where = params?.where && relationWhere ? and(
|
33225
|
+
relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap, this.casing),
|
33226
|
+
relationWhere
|
33227
|
+
) : params?.where ? relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap, this.casing) : relationWhere;
|
33172
33228
|
const order = params?.orderBy ? relationsOrderToSQL(table5, params.orderBy) : void 0;
|
33173
33229
|
const extras = params?.extras ? relationExtrasToSQL(table5, params.extras) : void 0;
|
33174
33230
|
if (extras)
|
@@ -33182,21 +33238,12 @@ var init_dialect2 = __esm({
|
|
33182
33238
|
return;
|
33183
33239
|
return sql.join(
|
33184
33240
|
withEntries.map(([k, join]) => {
|
33185
|
-
if (is(tableConfig.relations[k], AggregatedField)) {
|
33186
|
-
const relation2 = tableConfig.relations[k];
|
33187
|
-
relation2.onTable(table5);
|
33188
|
-
const query2 = relation2.getSQL();
|
33189
|
-
selection.push({
|
33190
|
-
key: k,
|
33191
|
-
field: relation2
|
33192
|
-
});
|
33193
|
-
return sql`(${query2}) as ${sql.identifier(k)}`;
|
33194
|
-
}
|
33195
33241
|
const relation = tableConfig.relations[k];
|
33196
33242
|
const isSingle2 = is(relation, One);
|
33197
33243
|
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
33198
33244
|
const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `tr${currentDepth}`) : void 0;
|
33199
33245
|
const { filter: filter2, joinCondition } = relationToSQL(
|
33246
|
+
this.casing,
|
33200
33247
|
relation,
|
33201
33248
|
table5,
|
33202
33249
|
targetTable,
|
@@ -38962,7 +39009,7 @@ var init_dialect3 = __esm({
|
|
38962
39009
|
});
|
38963
39010
|
}
|
38964
39011
|
buildRqbColumn(column5, key) {
|
38965
|
-
return sql`${is(column5, Column2) ? sql.identifier(column5
|
39012
|
+
return sql`${is(column5, Column2) ? sql.identifier(this.casing.getColumnCasing(column5)) : is(column5, SQL.Aliased) ? sql.identifier(column5.fieldAlias) : isSQLWrapper(column5) ? sql.identifier(key) : this.nestedSelectionerror()} as ${sql.identifier(key)}`;
|
38966
39013
|
}
|
38967
39014
|
buildRelationalQuery({
|
38968
39015
|
tables,
|
@@ -38988,7 +39035,10 @@ var init_dialect3 = __esm({
|
|
38988
39035
|
const limit = isSingle ? 1 : params?.limit;
|
38989
39036
|
const offset = params?.offset;
|
38990
39037
|
const columns = this.buildColumns(table5, selection, params);
|
38991
|
-
const where = params?.where && relationWhere ? and(
|
39038
|
+
const where = params?.where && relationWhere ? and(
|
39039
|
+
relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap, this.casing),
|
39040
|
+
relationWhere
|
39041
|
+
) : params?.where ? relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap, this.casing) : relationWhere;
|
38992
39042
|
const order = params?.orderBy ? relationsOrderToSQL(table5, params.orderBy) : void 0;
|
38993
39043
|
const extras = params?.extras ? relationExtrasToSQL(table5, params.extras) : void 0;
|
38994
39044
|
if (extras)
|
@@ -39004,21 +39054,12 @@ var init_dialect3 = __esm({
|
|
39004
39054
|
return sql.join(
|
39005
39055
|
withEntries.map(([k, join]) => {
|
39006
39056
|
selectionArr.push(sql`${sql.identifier(k)}.${sql.identifier("r")} as ${sql.identifier(k)}`);
|
39007
|
-
if (is(tableConfig.relations[k], AggregatedField)) {
|
39008
|
-
const relation2 = tableConfig.relations[k];
|
39009
|
-
relation2.onTable(table5);
|
39010
|
-
const query2 = relation2.getSQL();
|
39011
|
-
selection.push({
|
39012
|
-
key: k,
|
39013
|
-
field: relation2
|
39014
|
-
});
|
39015
|
-
return sql` left join lateral (${query2}) as ${sql.identifier(k)} on true`;
|
39016
|
-
}
|
39017
39057
|
const relation = tableConfig.relations[k];
|
39018
39058
|
const isSingle2 = is(relation, One);
|
39019
39059
|
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
39020
39060
|
const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `tr${currentDepth}`) : void 0;
|
39021
39061
|
const { filter: filter2, joinCondition } = relationToSQL(
|
39062
|
+
this.casing,
|
39022
39063
|
relation,
|
39023
39064
|
table5,
|
39024
39065
|
targetTable,
|
package/bin.cjs
CHANGED
@@ -71197,94 +71197,144 @@ var init_introspect = __esm({
|
|
71197
71197
|
const imports = [];
|
71198
71198
|
const tableRelations = {};
|
71199
71199
|
Object.values(schema6.tables).forEach((table5) => {
|
71200
|
-
Object.values(table5.foreignKeys)
|
71201
|
-
|
71202
|
-
const
|
71203
|
-
const
|
71204
|
-
const
|
71205
|
-
const
|
71206
|
-
const
|
71207
|
-
|
71208
|
-
const
|
71209
|
-
|
71210
|
-
|
71211
|
-
|
71212
|
-
|
71213
|
-
|
71214
|
-
|
71215
|
-
|
71216
|
-
|
71217
|
-
|
71218
|
-
|
71219
|
-
|
71220
|
-
|
71221
|
-
|
71222
|
-
|
71223
|
-
|
71224
|
-
|
71225
|
-
|
71226
|
-
|
71227
|
-
|
71228
|
-
|
71229
|
-
|
71230
|
-
|
71200
|
+
const fks = Object.values(table5.foreignKeys);
|
71201
|
+
if (fks.length === 2) {
|
71202
|
+
const [fk1, fk22] = fks;
|
71203
|
+
const toTable1 = withCasing3(paramNameFor(fk1.tableTo, fk1.schemaTo), casing2);
|
71204
|
+
const columnsTo1 = fk1.columnsTo.map((it) => withCasing3(it, casing2));
|
71205
|
+
const toTable2 = withCasing3(paramNameFor(fk22.tableTo, fk22.schemaTo), casing2);
|
71206
|
+
const columnsTo2 = fk22.columnsTo.map((it) => withCasing3(it, casing2));
|
71207
|
+
const tableThrough = withCasing3(paramNameFor(fk1.tableFrom, table5.schema), casing2);
|
71208
|
+
const tableFrom2 = withCasing3(paramNameFor(fk22.tableFrom, table5.schema), casing2);
|
71209
|
+
const columnsThroughFrom = fk1.columnsFrom.map((it) => withCasing3(it, casing2));
|
71210
|
+
const columnsThroughTo = fk22.columnsFrom.map((it) => withCasing3(it, casing2));
|
71211
|
+
if (toTable1 !== toTable2) {
|
71212
|
+
if (!tableRelations[toTable1]) {
|
71213
|
+
tableRelations[toTable1] = [];
|
71214
|
+
}
|
71215
|
+
tableRelations[toTable1].push({
|
71216
|
+
name: (0, import_pluralize.plural)(toTable2),
|
71217
|
+
type: "through",
|
71218
|
+
tableFrom: toTable1,
|
71219
|
+
columnsFrom: columnsTo1,
|
71220
|
+
tableTo: toTable2,
|
71221
|
+
columnsTo: columnsTo2,
|
71222
|
+
tableThrough,
|
71223
|
+
columnsThroughFrom,
|
71224
|
+
columnsThroughTo
|
71225
|
+
});
|
71226
|
+
if (!tableRelations[toTable2]) {
|
71227
|
+
tableRelations[toTable2] = [];
|
71228
|
+
}
|
71229
|
+
tableRelations[toTable2].push({
|
71230
|
+
name: (0, import_pluralize.plural)(toTable1),
|
71231
|
+
type: "many",
|
71232
|
+
tableFrom: tableFrom2,
|
71233
|
+
columnsFrom: fk22.columnsFrom,
|
71234
|
+
tableTo: toTable2,
|
71235
|
+
columnsTo: columnsTo2
|
71236
|
+
});
|
71237
|
+
}
|
71238
|
+
} else {
|
71239
|
+
fks.forEach((fk4) => {
|
71240
|
+
const tableNameFrom = paramNameFor(fk4.tableFrom, table5.schema);
|
71241
|
+
const tableNameTo = paramNameFor(fk4.tableTo, fk4.schemaTo);
|
71242
|
+
const tableFrom = withCasing3(tableNameFrom, casing2);
|
71243
|
+
const tableTo = withCasing3(tableNameTo, casing2);
|
71244
|
+
const columnsFrom = fk4.columnsFrom.map((it) => withCasing3(it, casing2));
|
71245
|
+
const columnsTo = fk4.columnsTo.map((it) => withCasing3(it, casing2));
|
71246
|
+
imports.push(tableTo, tableFrom);
|
71247
|
+
const keyFrom = tableFrom;
|
71248
|
+
if (!tableRelations[keyFrom]) {
|
71249
|
+
tableRelations[keyFrom] = [];
|
71250
|
+
}
|
71251
|
+
tableRelations[keyFrom].push({
|
71252
|
+
name: (0, import_pluralize.singular)(tableTo),
|
71253
|
+
type: "one",
|
71254
|
+
tableFrom,
|
71255
|
+
columnsFrom,
|
71256
|
+
tableTo,
|
71257
|
+
columnsTo
|
71258
|
+
});
|
71259
|
+
const keyTo = tableTo;
|
71260
|
+
if (!tableRelations[keyTo]) {
|
71261
|
+
tableRelations[keyTo] = [];
|
71262
|
+
}
|
71263
|
+
tableRelations[keyTo].push({
|
71264
|
+
name: (0, import_pluralize.plural)(tableFrom),
|
71265
|
+
type: "many",
|
71266
|
+
tableFrom: tableTo,
|
71267
|
+
columnsFrom: columnsTo,
|
71268
|
+
tableTo: tableFrom,
|
71269
|
+
columnsTo: columnsFrom
|
71270
|
+
});
|
71231
71271
|
});
|
71232
|
-
}
|
71272
|
+
}
|
71233
71273
|
});
|
71234
|
-
const
|
71235
|
-
|
71236
|
-
import { ${uniqueImports.join(
|
71237
|
-
", "
|
71238
|
-
)} } from "./schema";
|
71274
|
+
const importsTs = `import { defineRelations } from "drizzle-orm";
|
71275
|
+
import * as schema from "./schema";
|
71239
71276
|
|
71240
71277
|
`;
|
71241
|
-
const
|
71242
|
-
|
71243
|
-
|
71244
|
-
|
71245
|
-
|
71246
|
-
|
71247
|
-
|
71248
|
-
|
71249
|
-
|
71250
|
-
|
71251
|
-
)
|
71252
|
-
if (hasMultipleRelations) {
|
71253
|
-
relationName = relation.type === "one" ? `${relation.tableFrom}_${relation.columnFrom}_${relation.tableTo}_${relation.columnTo}` : `${relation.tableTo}_${relation.columnTo}_${relation.tableFrom}_${relation.columnFrom}`;
|
71254
|
-
}
|
71255
|
-
const hasDuplicatedRelation = originArray.some(
|
71256
|
-
(it, originIndex) => relationIndex !== originIndex && it.name === relation.name
|
71257
|
-
);
|
71258
|
-
if (hasDuplicatedRelation) {
|
71259
|
-
name = `${relation.name}_${relation.type === "one" ? relation.columnFrom : relation.columnTo}`;
|
71260
|
-
}
|
71261
|
-
return {
|
71262
|
-
...relation,
|
71263
|
-
name,
|
71264
|
-
relationName
|
71265
|
-
};
|
71278
|
+
let relationString = `export const relations = defineRelations(schema, (r) => ({`;
|
71279
|
+
Object.entries(tableRelations).forEach(([table5, relations4]) => {
|
71280
|
+
const preparedRelations = relations4.map(
|
71281
|
+
(relation, relationIndex, originArray) => {
|
71282
|
+
let name = relation.name;
|
71283
|
+
let relationName;
|
71284
|
+
const hasMultipleRelations = originArray.some(
|
71285
|
+
(it, originIndex) => relationIndex !== originIndex && it.tableTo === relation.tableTo
|
71286
|
+
);
|
71287
|
+
if (hasMultipleRelations) {
|
71288
|
+
relationName = relation.type === "one" ? `${relation.tableFrom}_${relation.columnsFrom.join("_")}_${relation.tableTo}_${relation.columnsTo.join("_")}` : `${relation.tableTo}_${relation.columnsTo.join("_")}_${relation.tableFrom}_${relation.columnsFrom.join("_")}`;
|
71266
71289
|
}
|
71267
|
-
|
71268
|
-
|
71269
|
-
|
71270
|
-
|
71271
|
-
|
71272
|
-
references: [${relation.tableTo}.${relation.columnTo}]${relation.relationName ? `,
|
71273
|
-
relationName: "${relation.relationName}"` : ""}
|
71274
|
-
}),`;
|
71275
|
-
} else {
|
71276
|
-
return ` ${relation.name}: many(${relation.tableTo}${relation.relationName ? `, {
|
71277
|
-
relationName: "${relation.relationName}"
|
71278
|
-
}` : ""}),`;
|
71290
|
+
const hasDuplicatedRelation = originArray.some(
|
71291
|
+
(it, originIndex) => relationIndex !== originIndex && it.name === relation.name
|
71292
|
+
);
|
71293
|
+
if (hasDuplicatedRelation) {
|
71294
|
+
name = `${relation.name}_${relation.type === "one" ? relation.columnsFrom.join("_") : relation.columnsTo.join("_")}`;
|
71279
71295
|
}
|
71280
|
-
|
71281
|
-
|
71282
|
-
|
71283
|
-
|
71284
|
-
|
71285
|
-
|
71296
|
+
return {
|
71297
|
+
...relation,
|
71298
|
+
name,
|
71299
|
+
relationName
|
71300
|
+
};
|
71301
|
+
}
|
71302
|
+
);
|
71303
|
+
relationString += `
|
71304
|
+
${table5}: {`;
|
71305
|
+
preparedRelations.forEach((relation) => {
|
71306
|
+
if (relation.type === "one") {
|
71307
|
+
const from = relation.columnsFrom.length === 1 ? `r.${relation.tableFrom}.${relation.columnsFrom[0]}` : `[${relation.columnsFrom.map((it) => `r.${relation.tableFrom}.${it}`).join(", ")}]`;
|
71308
|
+
const to = relation.columnsTo.length === 1 ? `r.${relation.tableTo}.${relation.columnsTo[0]}` : `[${relation.columnsTo.map((it) => `r.${relation.tableTo}.${it}`).join(", ")}]`;
|
71309
|
+
relationString += `
|
71310
|
+
${relation.name}: r.one.${relation.tableTo}({
|
71311
|
+
from: ${from},
|
71312
|
+
to: ${to}` + (relation.relationName ? `,
|
71313
|
+
alias: "${relation.relationName}"` : "") + `
|
71314
|
+
}),`;
|
71315
|
+
} else if (relation.type === "many") {
|
71316
|
+
relationString += `
|
71317
|
+
${relation.name}: r.many.${relation.tableTo}(` + (relation.relationName ? `{
|
71318
|
+
alias: "${relation.relationName}"
|
71319
|
+
}` : "") + `),`;
|
71320
|
+
} else {
|
71321
|
+
const from = relation.columnsThroughFrom.length === 1 ? `r.${relation.tableFrom}.${relation.columnsFrom[0]}.through(r.${relation.tableThrough}.${relation.columnsThroughFrom[0]})` : `[${relation.columnsThroughFrom.map((it) => `r.${relation.tableFrom}.${it}.through(${relation.tableThrough}.${it})`).join(", ")}]`;
|
71322
|
+
const to = relation.columnsThroughTo.length === 1 ? `r.${relation.tableTo}.${relation.columnsThroughTo[0]}.through(r.${relation.tableThrough}.${relation.columnsThroughTo[0]})` : `[${relation.columnsThroughTo.map((it) => `r.${relation.tableTo}.${it}.through(${relation.tableThrough}.${it})`).join(", ")}]`;
|
71323
|
+
relationString += `
|
71324
|
+
${relation.name}: r.many.${relation.tableTo}({
|
71325
|
+
from: ${from},
|
71326
|
+
to: ${to}` + (relation.relationName ? `,
|
71327
|
+
alias: "${relation.relationName}"` : "") + `
|
71328
|
+
}),`;
|
71329
|
+
}
|
71330
|
+
});
|
71331
|
+
relationString += `
|
71332
|
+
},`;
|
71333
|
+
});
|
71334
|
+
relationString += `
|
71335
|
+
}))`;
|
71286
71336
|
return {
|
71287
|
-
file: importsTs +
|
71337
|
+
file: importsTs + relationString
|
71288
71338
|
};
|
71289
71339
|
};
|
71290
71340
|
}
|
@@ -77582,7 +77632,7 @@ init_utils5();
|
|
77582
77632
|
var version2 = async () => {
|
77583
77633
|
const { npmVersion } = await ormCoreVersions();
|
77584
77634
|
const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
|
77585
|
-
const envVersion = "0.30.4-
|
77635
|
+
const envVersion = "0.30.4-d004082";
|
77586
77636
|
const kitVersion = envVersion ? `v${envVersion}` : "--";
|
77587
77637
|
const versions = `drizzle-kit: ${kitVersion}
|
77588
77638
|
${ormVersion}`;
|