drizzle-kit 0.30.4-c7c31ad → 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 +64 -22
- package/api.mjs +64 -22
- 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, tableRelations = {}, tablesRelations = {}, tableNamesMap = {}, depth = 0) {
|
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, tableRelations = {}, tablesRelati
|
|
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, tableRelations = {}, tablesRelati
|
|
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,7 +23283,15 @@ function relationsFilterToSQL(table5, filter2, tableRelations = {}, tablesRelati
|
|
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));
|
@@ -23291,13 +23320,14 @@ function relationsFilterToSQL(table5, filter2, tableRelations = {}, tablesRelati
|
|
23291
23320
|
const {
|
23292
23321
|
filter: relationFilter,
|
23293
23322
|
joinCondition
|
23294
|
-
} = relationToSQL(relation, table5, targetTable, throughTable);
|
23323
|
+
} = relationToSQL(casing2, relation, table5, targetTable, throughTable);
|
23295
23324
|
const subfilter = typeof value === "boolean" ? void 0 : relationsFilterToSQL(
|
23296
23325
|
targetTable,
|
23297
23326
|
value,
|
23298
23327
|
targetConfig.relations,
|
23299
23328
|
tablesRelations,
|
23300
23329
|
tableNamesMap,
|
23330
|
+
casing2,
|
23301
23331
|
depth + 1
|
23302
23332
|
);
|
23303
23333
|
const filter22 = and(
|
@@ -23346,20 +23376,20 @@ function relationExtrasToSQL(table5, extras) {
|
|
23346
23376
|
selection
|
23347
23377
|
};
|
23348
23378
|
}
|
23349
|
-
function relationToSQL(relation, sourceTable, targetTable, throughTable) {
|
23379
|
+
function relationToSQL(casing2, relation, sourceTable, targetTable, throughTable) {
|
23350
23380
|
if (relation.through) {
|
23351
23381
|
const outerColumnWhere = relation.sourceColumns.map((s, i) => {
|
23352
23382
|
const t = relation.through.source[i];
|
23353
23383
|
return eq(
|
23354
|
-
sql`${sourceTable}.${sql.identifier(s
|
23355
|
-
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)}`
|
23356
23386
|
);
|
23357
23387
|
});
|
23358
23388
|
const innerColumnWhere = relation.targetColumns.map((s, i) => {
|
23359
23389
|
const t = relation.through.target[i];
|
23360
23390
|
return eq(
|
23361
|
-
sql`${throughTable}.${sql.identifier(is(t._.column, Column2) ? t._.column
|
23362
|
-
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))}`
|
23363
23393
|
);
|
23364
23394
|
});
|
23365
23395
|
return {
|
@@ -23373,8 +23403,8 @@ function relationToSQL(relation, sourceTable, targetTable, throughTable) {
|
|
23373
23403
|
const columnWhere = relation.sourceColumns.map((s, i) => {
|
23374
23404
|
const t = relation.targetColumns[i];
|
23375
23405
|
return eq(
|
23376
|
-
sql`${sourceTable}.${sql.identifier(s
|
23377
|
-
sql`${targetTable}.${sql.identifier(t
|
23406
|
+
sql`${sourceTable}.${sql.identifier(casing2.getColumnCasing(s))}`,
|
23407
|
+
sql`${targetTable}.${sql.identifier(casing2.getColumnCasing(t))}`
|
23378
23408
|
);
|
23379
23409
|
});
|
23380
23410
|
const fullWhere = and(
|
@@ -27124,7 +27154,7 @@ var init_dialect = __esm({
|
|
27124
27154
|
});
|
27125
27155
|
}
|
27126
27156
|
buildRqbColumn(column5, key) {
|
27127
|
-
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)}`;
|
27128
27158
|
}
|
27129
27159
|
buildRelationalQuery({
|
27130
27160
|
tables,
|
@@ -27148,7 +27178,10 @@ var init_dialect = __esm({
|
|
27148
27178
|
table5 = aliasedTable(table5, `d${currentDepth}`);
|
27149
27179
|
const limit = isSingle ? 1 : params?.limit;
|
27150
27180
|
const offset = params?.offset;
|
27151
|
-
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;
|
27152
27185
|
const order = params?.orderBy ? relationsOrderToSQL(table5, params.orderBy) : void 0;
|
27153
27186
|
const columns = this.buildColumns(table5, selection, params);
|
27154
27187
|
const extras = params?.extras ? relationExtrasToSQL(table5, params.extras) : void 0;
|
@@ -27169,6 +27202,7 @@ var init_dialect = __esm({
|
|
27169
27202
|
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
27170
27203
|
const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `tr${currentDepth}`) : void 0;
|
27171
27204
|
const { filter: filter2, joinCondition } = relationToSQL(
|
27205
|
+
this.casing,
|
27172
27206
|
relation,
|
27173
27207
|
table5,
|
27174
27208
|
targetTable,
|
@@ -33156,7 +33190,7 @@ var init_dialect2 = __esm({
|
|
33156
33190
|
});
|
33157
33191
|
}
|
33158
33192
|
buildRqbColumn(column5, key) {
|
33159
|
-
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)}`;
|
33160
33194
|
}
|
33161
33195
|
buildRelationalQuery({
|
33162
33196
|
tables,
|
@@ -33182,7 +33216,10 @@ var init_dialect2 = __esm({
|
|
33182
33216
|
const limit = isSingle ? 1 : params?.limit;
|
33183
33217
|
const offset = params?.offset;
|
33184
33218
|
const columns = this.buildColumns(table5, selection, params);
|
33185
|
-
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;
|
33186
33223
|
const order = params?.orderBy ? relationsOrderToSQL(table5, params.orderBy) : void 0;
|
33187
33224
|
const extras = params?.extras ? relationExtrasToSQL(table5, params.extras) : void 0;
|
33188
33225
|
if (extras)
|
@@ -33201,6 +33238,7 @@ var init_dialect2 = __esm({
|
|
33201
33238
|
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
33202
33239
|
const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `tr${currentDepth}`) : void 0;
|
33203
33240
|
const { filter: filter2, joinCondition } = relationToSQL(
|
33241
|
+
this.casing,
|
33204
33242
|
relation,
|
33205
33243
|
table5,
|
33206
33244
|
targetTable,
|
@@ -38966,7 +39004,7 @@ var init_dialect3 = __esm({
|
|
38966
39004
|
});
|
38967
39005
|
}
|
38968
39006
|
buildRqbColumn(column5, key) {
|
38969
|
-
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)}`;
|
38970
39008
|
}
|
38971
39009
|
buildRelationalQuery({
|
38972
39010
|
tables,
|
@@ -38992,7 +39030,10 @@ var init_dialect3 = __esm({
|
|
38992
39030
|
const limit = isSingle ? 1 : params?.limit;
|
38993
39031
|
const offset = params?.offset;
|
38994
39032
|
const columns = this.buildColumns(table5, selection, params);
|
38995
|
-
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;
|
38996
39037
|
const order = params?.orderBy ? relationsOrderToSQL(table5, params.orderBy) : void 0;
|
38997
39038
|
const extras = params?.extras ? relationExtrasToSQL(table5, params.extras) : void 0;
|
38998
39039
|
if (extras)
|
@@ -39013,6 +39054,7 @@ var init_dialect3 = __esm({
|
|
39013
39054
|
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
39014
39055
|
const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `tr${currentDepth}`) : void 0;
|
39015
39056
|
const { filter: filter2, joinCondition } = relationToSQL(
|
39057
|
+
this.casing,
|
39016
39058
|
relation,
|
39017
39059
|
table5,
|
39018
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, tableRelations = {}, tablesRelations = {}, tableNamesMap = {}, depth = 0) {
|
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, tableRelations = {}, tablesRelati
|
|
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, tableRelations = {}, tablesRelati
|
|
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,7 +23288,15 @@ function relationsFilterToSQL(table5, filter2, tableRelations = {}, tablesRelati
|
|
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));
|
@@ -23296,13 +23325,14 @@ function relationsFilterToSQL(table5, filter2, tableRelations = {}, tablesRelati
|
|
23296
23325
|
const {
|
23297
23326
|
filter: relationFilter,
|
23298
23327
|
joinCondition
|
23299
|
-
} = relationToSQL(relation, table5, targetTable, throughTable);
|
23328
|
+
} = relationToSQL(casing2, relation, table5, targetTable, throughTable);
|
23300
23329
|
const subfilter = typeof value === "boolean" ? void 0 : relationsFilterToSQL(
|
23301
23330
|
targetTable,
|
23302
23331
|
value,
|
23303
23332
|
targetConfig.relations,
|
23304
23333
|
tablesRelations,
|
23305
23334
|
tableNamesMap,
|
23335
|
+
casing2,
|
23306
23336
|
depth + 1
|
23307
23337
|
);
|
23308
23338
|
const filter22 = and(
|
@@ -23351,20 +23381,20 @@ function relationExtrasToSQL(table5, extras) {
|
|
23351
23381
|
selection
|
23352
23382
|
};
|
23353
23383
|
}
|
23354
|
-
function relationToSQL(relation, sourceTable, targetTable, throughTable) {
|
23384
|
+
function relationToSQL(casing2, relation, sourceTable, targetTable, throughTable) {
|
23355
23385
|
if (relation.through) {
|
23356
23386
|
const outerColumnWhere = relation.sourceColumns.map((s, i) => {
|
23357
23387
|
const t = relation.through.source[i];
|
23358
23388
|
return eq(
|
23359
|
-
sql`${sourceTable}.${sql.identifier(s
|
23360
|
-
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)}`
|
23361
23391
|
);
|
23362
23392
|
});
|
23363
23393
|
const innerColumnWhere = relation.targetColumns.map((s, i) => {
|
23364
23394
|
const t = relation.through.target[i];
|
23365
23395
|
return eq(
|
23366
|
-
sql`${throughTable}.${sql.identifier(is(t._.column, Column2) ? t._.column
|
23367
|
-
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))}`
|
23368
23398
|
);
|
23369
23399
|
});
|
23370
23400
|
return {
|
@@ -23378,8 +23408,8 @@ function relationToSQL(relation, sourceTable, targetTable, throughTable) {
|
|
23378
23408
|
const columnWhere = relation.sourceColumns.map((s, i) => {
|
23379
23409
|
const t = relation.targetColumns[i];
|
23380
23410
|
return eq(
|
23381
|
-
sql`${sourceTable}.${sql.identifier(s
|
23382
|
-
sql`${targetTable}.${sql.identifier(t
|
23411
|
+
sql`${sourceTable}.${sql.identifier(casing2.getColumnCasing(s))}`,
|
23412
|
+
sql`${targetTable}.${sql.identifier(casing2.getColumnCasing(t))}`
|
23383
23413
|
);
|
23384
23414
|
});
|
23385
23415
|
const fullWhere = and(
|
@@ -27129,7 +27159,7 @@ var init_dialect = __esm({
|
|
27129
27159
|
});
|
27130
27160
|
}
|
27131
27161
|
buildRqbColumn(column5, key) {
|
27132
|
-
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)}`;
|
27133
27163
|
}
|
27134
27164
|
buildRelationalQuery({
|
27135
27165
|
tables,
|
@@ -27153,7 +27183,10 @@ var init_dialect = __esm({
|
|
27153
27183
|
table5 = aliasedTable(table5, `d${currentDepth}`);
|
27154
27184
|
const limit = isSingle ? 1 : params?.limit;
|
27155
27185
|
const offset = params?.offset;
|
27156
|
-
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;
|
27157
27190
|
const order = params?.orderBy ? relationsOrderToSQL(table5, params.orderBy) : void 0;
|
27158
27191
|
const columns = this.buildColumns(table5, selection, params);
|
27159
27192
|
const extras = params?.extras ? relationExtrasToSQL(table5, params.extras) : void 0;
|
@@ -27174,6 +27207,7 @@ var init_dialect = __esm({
|
|
27174
27207
|
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
27175
27208
|
const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `tr${currentDepth}`) : void 0;
|
27176
27209
|
const { filter: filter2, joinCondition } = relationToSQL(
|
27210
|
+
this.casing,
|
27177
27211
|
relation,
|
27178
27212
|
table5,
|
27179
27213
|
targetTable,
|
@@ -33161,7 +33195,7 @@ var init_dialect2 = __esm({
|
|
33161
33195
|
});
|
33162
33196
|
}
|
33163
33197
|
buildRqbColumn(column5, key) {
|
33164
|
-
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)}`;
|
33165
33199
|
}
|
33166
33200
|
buildRelationalQuery({
|
33167
33201
|
tables,
|
@@ -33187,7 +33221,10 @@ var init_dialect2 = __esm({
|
|
33187
33221
|
const limit = isSingle ? 1 : params?.limit;
|
33188
33222
|
const offset = params?.offset;
|
33189
33223
|
const columns = this.buildColumns(table5, selection, params);
|
33190
|
-
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;
|
33191
33228
|
const order = params?.orderBy ? relationsOrderToSQL(table5, params.orderBy) : void 0;
|
33192
33229
|
const extras = params?.extras ? relationExtrasToSQL(table5, params.extras) : void 0;
|
33193
33230
|
if (extras)
|
@@ -33206,6 +33243,7 @@ var init_dialect2 = __esm({
|
|
33206
33243
|
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
33207
33244
|
const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `tr${currentDepth}`) : void 0;
|
33208
33245
|
const { filter: filter2, joinCondition } = relationToSQL(
|
33246
|
+
this.casing,
|
33209
33247
|
relation,
|
33210
33248
|
table5,
|
33211
33249
|
targetTable,
|
@@ -38971,7 +39009,7 @@ var init_dialect3 = __esm({
|
|
38971
39009
|
});
|
38972
39010
|
}
|
38973
39011
|
buildRqbColumn(column5, key) {
|
38974
|
-
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)}`;
|
38975
39013
|
}
|
38976
39014
|
buildRelationalQuery({
|
38977
39015
|
tables,
|
@@ -38997,7 +39035,10 @@ var init_dialect3 = __esm({
|
|
38997
39035
|
const limit = isSingle ? 1 : params?.limit;
|
38998
39036
|
const offset = params?.offset;
|
38999
39037
|
const columns = this.buildColumns(table5, selection, params);
|
39000
|
-
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;
|
39001
39042
|
const order = params?.orderBy ? relationsOrderToSQL(table5, params.orderBy) : void 0;
|
39002
39043
|
const extras = params?.extras ? relationExtrasToSQL(table5, params.extras) : void 0;
|
39003
39044
|
if (extras)
|
@@ -39018,6 +39059,7 @@ var init_dialect3 = __esm({
|
|
39018
39059
|
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
39019
39060
|
const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `tr${currentDepth}`) : void 0;
|
39020
39061
|
const { filter: filter2, joinCondition } = relationToSQL(
|
39062
|
+
this.casing,
|
39021
39063
|
relation,
|
39022
39064
|
table5,
|
39023
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}`;
|