drizzle-kit 0.30.4-c417a27 → 0.30.4-c7c31ad

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.
Files changed (4) hide show
  1. package/api.js +46 -47
  2. package/api.mjs +46 -47
  3. package/bin.cjs +1 -1
  4. package/package.json +1 -1
package/api.js CHANGED
@@ -23232,7 +23232,7 @@ function relationsFieldFilterToSQL(column5, filter2) {
23232
23232
  return void 0;
23233
23233
  return and(...parts);
23234
23234
  }
23235
- function relationsFilterToSQL(table5, filter2) {
23235
+ function relationsFilterToSQL(table5, filter2, tableRelations = {}, tablesRelations = {}, tableNamesMap = {}, depth = 0) {
23236
23236
  const entries = Object.entries(filter2);
23237
23237
  if (!entries.length)
23238
23238
  return void 0;
@@ -23269,14 +23269,44 @@ function relationsFilterToSQL(table5, filter2) {
23269
23269
  continue;
23270
23270
  }
23271
23271
  default: {
23272
- const column5 = fieldSelectionToSQL(table5, target);
23273
- const colFilter = relationsFieldFilterToSQL(
23274
- column5,
23275
- value
23272
+ if (table5[Columns][target]) {
23273
+ const column5 = fieldSelectionToSQL(table5, target);
23274
+ const colFilter = relationsFieldFilterToSQL(
23275
+ column5,
23276
+ value
23277
+ );
23278
+ if (colFilter)
23279
+ parts.push(colFilter);
23280
+ continue;
23281
+ }
23282
+ const relation = tableRelations[target];
23283
+ if (!relation) {
23284
+ throw new DrizzleError({
23285
+ message: `Unknown relational filter field: "${target}"`
23286
+ });
23287
+ }
23288
+ const targetTable = aliasedTable(relation.targetTable, `f${depth}`);
23289
+ const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `ft${depth}`) : void 0;
23290
+ const targetConfig = tablesRelations[tableNamesMap[getTableUniqueName(relation.targetTable)]];
23291
+ const {
23292
+ filter: relationFilter,
23293
+ joinCondition
23294
+ } = relationToSQL(relation, table5, targetTable, throughTable);
23295
+ const subfilter = typeof value === "boolean" ? void 0 : relationsFilterToSQL(
23296
+ targetTable,
23297
+ value,
23298
+ targetConfig.relations,
23299
+ tablesRelations,
23300
+ tableNamesMap,
23301
+ depth + 1
23276
23302
  );
23277
- if (colFilter)
23278
- parts.push(colFilter);
23279
- continue;
23303
+ const filter22 = and(
23304
+ relationFilter,
23305
+ subfilter
23306
+ );
23307
+ 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)`;
23308
+ if (filter22)
23309
+ parts.push((value ? exists : notExists)(subquery));
23280
23310
  }
23281
23311
  }
23282
23312
  }
@@ -23334,12 +23364,10 @@ function relationToSQL(relation, sourceTable, targetTable, throughTable) {
23334
23364
  });
23335
23365
  return {
23336
23366
  filter: and(
23337
- relation.where ? relationsFilterToSQL(relation.isReversed ? targetTable : sourceTable, relation.where) : void 0
23367
+ relation.where ? relationsFilterToSQL(relation.isReversed ? targetTable : sourceTable, relation.where) : void 0,
23368
+ ...outerColumnWhere
23338
23369
  ),
23339
- joinCondition: and(
23340
- ...outerColumnWhere,
23341
- ...innerColumnWhere
23342
- )
23370
+ joinCondition: and(...innerColumnWhere)
23343
23371
  };
23344
23372
  }
23345
23373
  const columnWhere = relation.sourceColumns.map((s, i) => {
@@ -23364,8 +23392,10 @@ var init_relations = __esm({
23364
23392
  "use strict";
23365
23393
  init_table();
23366
23394
  init_table();
23395
+ init_alias();
23367
23396
  init_column();
23368
23397
  init_entity();
23398
+ init_errors();
23369
23399
  init_expressions();
23370
23400
  init_sql();
23371
23401
  _a35 = entityKind;
@@ -27118,7 +27148,7 @@ var init_dialect = __esm({
27118
27148
  table5 = aliasedTable(table5, `d${currentDepth}`);
27119
27149
  const limit = isSingle ? 1 : params?.limit;
27120
27150
  const offset = params?.offset;
27121
- const where = params?.where && relationWhere ? and(relationsFilterToSQL(table5, params.where), relationWhere) : params?.where ? relationsFilterToSQL(table5, params.where) : relationWhere;
27151
+ const where = params?.where && relationWhere ? and(relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap), relationWhere) : params?.where ? relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap) : relationWhere;
27122
27152
  const order = params?.orderBy ? relationsOrderToSQL(table5, params.orderBy) : void 0;
27123
27153
  const columns = this.buildColumns(table5, selection, params);
27124
27154
  const extras = params?.extras ? relationExtrasToSQL(table5, params.extras) : void 0;
@@ -27134,17 +27164,6 @@ var init_dialect = __esm({
27134
27164
  return;
27135
27165
  return sql.join(
27136
27166
  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
27167
  const relation = tableConfig.relations[k];
27149
27168
  const isSingle2 = is(relation, One);
27150
27169
  const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
@@ -33163,7 +33182,7 @@ var init_dialect2 = __esm({
33163
33182
  const limit = isSingle ? 1 : params?.limit;
33164
33183
  const offset = params?.offset;
33165
33184
  const columns = this.buildColumns(table5, selection, params);
33166
- const where = params?.where && relationWhere ? and(relationsFilterToSQL(table5, params.where), relationWhere) : params?.where ? relationsFilterToSQL(table5, params.where) : relationWhere;
33185
+ const where = params?.where && relationWhere ? and(relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap), relationWhere) : params?.where ? relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap) : relationWhere;
33167
33186
  const order = params?.orderBy ? relationsOrderToSQL(table5, params.orderBy) : void 0;
33168
33187
  const extras = params?.extras ? relationExtrasToSQL(table5, params.extras) : void 0;
33169
33188
  if (extras)
@@ -33177,16 +33196,6 @@ var init_dialect2 = __esm({
33177
33196
  return;
33178
33197
  return sql.join(
33179
33198
  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
33199
  const relation = tableConfig.relations[k];
33191
33200
  const isSingle2 = is(relation, One);
33192
33201
  const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
@@ -38983,7 +38992,7 @@ var init_dialect3 = __esm({
38983
38992
  const limit = isSingle ? 1 : params?.limit;
38984
38993
  const offset = params?.offset;
38985
38994
  const columns = this.buildColumns(table5, selection, params);
38986
- const where = params?.where && relationWhere ? and(relationsFilterToSQL(table5, params.where), relationWhere) : params?.where ? relationsFilterToSQL(table5, params.where) : relationWhere;
38995
+ const where = params?.where && relationWhere ? and(relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap), relationWhere) : params?.where ? relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap) : relationWhere;
38987
38996
  const order = params?.orderBy ? relationsOrderToSQL(table5, params.orderBy) : void 0;
38988
38997
  const extras = params?.extras ? relationExtrasToSQL(table5, params.extras) : void 0;
38989
38998
  if (extras)
@@ -38999,16 +39008,6 @@ var init_dialect3 = __esm({
38999
39008
  return sql.join(
39000
39009
  withEntries.map(([k, join]) => {
39001
39010
  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
39011
  const relation = tableConfig.relations[k];
39013
39012
  const isSingle2 = is(relation, One);
39014
39013
  const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
package/api.mjs CHANGED
@@ -23237,7 +23237,7 @@ function relationsFieldFilterToSQL(column5, filter2) {
23237
23237
  return void 0;
23238
23238
  return and(...parts);
23239
23239
  }
23240
- function relationsFilterToSQL(table5, filter2) {
23240
+ function relationsFilterToSQL(table5, filter2, tableRelations = {}, tablesRelations = {}, tableNamesMap = {}, depth = 0) {
23241
23241
  const entries = Object.entries(filter2);
23242
23242
  if (!entries.length)
23243
23243
  return void 0;
@@ -23274,14 +23274,44 @@ function relationsFilterToSQL(table5, filter2) {
23274
23274
  continue;
23275
23275
  }
23276
23276
  default: {
23277
- const column5 = fieldSelectionToSQL(table5, target);
23278
- const colFilter = relationsFieldFilterToSQL(
23279
- column5,
23280
- value
23277
+ if (table5[Columns][target]) {
23278
+ const column5 = fieldSelectionToSQL(table5, target);
23279
+ const colFilter = relationsFieldFilterToSQL(
23280
+ column5,
23281
+ value
23282
+ );
23283
+ if (colFilter)
23284
+ parts.push(colFilter);
23285
+ continue;
23286
+ }
23287
+ const relation = tableRelations[target];
23288
+ if (!relation) {
23289
+ throw new DrizzleError({
23290
+ message: `Unknown relational filter field: "${target}"`
23291
+ });
23292
+ }
23293
+ const targetTable = aliasedTable(relation.targetTable, `f${depth}`);
23294
+ const throughTable = relation.throughTable ? aliasedTable(relation.throughTable, `ft${depth}`) : void 0;
23295
+ const targetConfig = tablesRelations[tableNamesMap[getTableUniqueName(relation.targetTable)]];
23296
+ const {
23297
+ filter: relationFilter,
23298
+ joinCondition
23299
+ } = relationToSQL(relation, table5, targetTable, throughTable);
23300
+ const subfilter = typeof value === "boolean" ? void 0 : relationsFilterToSQL(
23301
+ targetTable,
23302
+ value,
23303
+ targetConfig.relations,
23304
+ tablesRelations,
23305
+ tableNamesMap,
23306
+ depth + 1
23281
23307
  );
23282
- if (colFilter)
23283
- parts.push(colFilter);
23284
- continue;
23308
+ const filter22 = and(
23309
+ relationFilter,
23310
+ subfilter
23311
+ );
23312
+ 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)`;
23313
+ if (filter22)
23314
+ parts.push((value ? exists : notExists)(subquery));
23285
23315
  }
23286
23316
  }
23287
23317
  }
@@ -23339,12 +23369,10 @@ function relationToSQL(relation, sourceTable, targetTable, throughTable) {
23339
23369
  });
23340
23370
  return {
23341
23371
  filter: and(
23342
- relation.where ? relationsFilterToSQL(relation.isReversed ? targetTable : sourceTable, relation.where) : void 0
23372
+ relation.where ? relationsFilterToSQL(relation.isReversed ? targetTable : sourceTable, relation.where) : void 0,
23373
+ ...outerColumnWhere
23343
23374
  ),
23344
- joinCondition: and(
23345
- ...outerColumnWhere,
23346
- ...innerColumnWhere
23347
- )
23375
+ joinCondition: and(...innerColumnWhere)
23348
23376
  };
23349
23377
  }
23350
23378
  const columnWhere = relation.sourceColumns.map((s, i) => {
@@ -23369,8 +23397,10 @@ var init_relations = __esm({
23369
23397
  "use strict";
23370
23398
  init_table();
23371
23399
  init_table();
23400
+ init_alias();
23372
23401
  init_column();
23373
23402
  init_entity();
23403
+ init_errors();
23374
23404
  init_expressions();
23375
23405
  init_sql();
23376
23406
  _a35 = entityKind;
@@ -27123,7 +27153,7 @@ var init_dialect = __esm({
27123
27153
  table5 = aliasedTable(table5, `d${currentDepth}`);
27124
27154
  const limit = isSingle ? 1 : params?.limit;
27125
27155
  const offset = params?.offset;
27126
- const where = params?.where && relationWhere ? and(relationsFilterToSQL(table5, params.where), relationWhere) : params?.where ? relationsFilterToSQL(table5, params.where) : relationWhere;
27156
+ const where = params?.where && relationWhere ? and(relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap), relationWhere) : params?.where ? relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap) : relationWhere;
27127
27157
  const order = params?.orderBy ? relationsOrderToSQL(table5, params.orderBy) : void 0;
27128
27158
  const columns = this.buildColumns(table5, selection, params);
27129
27159
  const extras = params?.extras ? relationExtrasToSQL(table5, params.extras) : void 0;
@@ -27139,17 +27169,6 @@ var init_dialect = __esm({
27139
27169
  return;
27140
27170
  return sql.join(
27141
27171
  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
27172
  const relation = tableConfig.relations[k];
27154
27173
  const isSingle2 = is(relation, One);
27155
27174
  const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
@@ -33168,7 +33187,7 @@ var init_dialect2 = __esm({
33168
33187
  const limit = isSingle ? 1 : params?.limit;
33169
33188
  const offset = params?.offset;
33170
33189
  const columns = this.buildColumns(table5, selection, params);
33171
- const where = params?.where && relationWhere ? and(relationsFilterToSQL(table5, params.where), relationWhere) : params?.where ? relationsFilterToSQL(table5, params.where) : relationWhere;
33190
+ const where = params?.where && relationWhere ? and(relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap), relationWhere) : params?.where ? relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap) : relationWhere;
33172
33191
  const order = params?.orderBy ? relationsOrderToSQL(table5, params.orderBy) : void 0;
33173
33192
  const extras = params?.extras ? relationExtrasToSQL(table5, params.extras) : void 0;
33174
33193
  if (extras)
@@ -33182,16 +33201,6 @@ var init_dialect2 = __esm({
33182
33201
  return;
33183
33202
  return sql.join(
33184
33203
  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
33204
  const relation = tableConfig.relations[k];
33196
33205
  const isSingle2 = is(relation, One);
33197
33206
  const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
@@ -38988,7 +38997,7 @@ var init_dialect3 = __esm({
38988
38997
  const limit = isSingle ? 1 : params?.limit;
38989
38998
  const offset = params?.offset;
38990
38999
  const columns = this.buildColumns(table5, selection, params);
38991
- const where = params?.where && relationWhere ? and(relationsFilterToSQL(table5, params.where), relationWhere) : params?.where ? relationsFilterToSQL(table5, params.where) : relationWhere;
39000
+ const where = params?.where && relationWhere ? and(relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap), relationWhere) : params?.where ? relationsFilterToSQL(table5, params.where, tableConfig.relations, schema5, tableNamesMap) : relationWhere;
38992
39001
  const order = params?.orderBy ? relationsOrderToSQL(table5, params.orderBy) : void 0;
38993
39002
  const extras = params?.extras ? relationExtrasToSQL(table5, params.extras) : void 0;
38994
39003
  if (extras)
@@ -39004,16 +39013,6 @@ var init_dialect3 = __esm({
39004
39013
  return sql.join(
39005
39014
  withEntries.map(([k, join]) => {
39006
39015
  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
39016
  const relation = tableConfig.relations[k];
39018
39017
  const isSingle2 = is(relation, One);
39019
39018
  const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
package/bin.cjs CHANGED
@@ -77582,7 +77582,7 @@ init_utils5();
77582
77582
  var version2 = async () => {
77583
77583
  const { npmVersion } = await ormCoreVersions();
77584
77584
  const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
77585
- const envVersion = "0.30.4-c417a27";
77585
+ const envVersion = "0.30.4-c7c31ad";
77586
77586
  const kitVersion = envVersion ? `v${envVersion}` : "--";
77587
77587
  const versions = `drizzle-kit: ${kitVersion}
77588
77588
  ${ormVersion}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-kit",
3
- "version": "0.30.4-c417a27",
3
+ "version": "0.30.4-c7c31ad",
4
4
  "homepage": "https://orm.drizzle.team",
5
5
  "keywords": [
6
6
  "drizzle",