@mikro-orm/sql 7.2.2-dev.17 → 7.2.2-dev.19

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.
@@ -419,7 +419,11 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
419
419
  if ((col.udt_name === 'geometry' || col.udt_name === 'geography') && col.format_type) {
420
420
  type = col.format_type;
421
421
  }
422
- if (type === 'vector' && col.length == null && col.custom_length != null && col.custom_length !== -1) {
422
+ // pgvector stores the dimension in atttypmod for all three of its vector types
423
+ if (['vector', 'halfvec', 'sparsevec'].includes(type) &&
424
+ col.length == null &&
425
+ col.custom_length != null &&
426
+ col.custom_length !== -1) {
423
427
  col.length = col.custom_length;
424
428
  }
425
429
  if (col.length != null && !type.endsWith(`(${col.length})`) && !['text', 'date'].includes(type)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/sql",
3
- "version": "7.2.2-dev.17",
3
+ "version": "7.2.2-dev.19",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "keywords": [
6
6
  "data-mapper",
@@ -53,7 +53,7 @@
53
53
  "@mikro-orm/core": "^7.2.1"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.2.2-dev.17"
56
+ "@mikro-orm/core": "7.2.2-dev.19"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"
@@ -127,7 +127,7 @@ export declare class NativeQueryBuilder implements Subquery {
127
127
  as(alias: string): this;
128
128
  toRaw(): RawQueryFragment;
129
129
  protected compileSelect(): void;
130
- /** Whether this COUNT query needs a subquery wrapper for multi-column distinct. */
130
+ /** Whether this COUNT query needs a subquery wrapper: multi-column distinct, or `distinct on` (keeps the null group). */
131
131
  protected needsCountSubquery(): boolean;
132
132
  protected getFields(countSubquery?: boolean): string;
133
133
  protected compileInsert(): void;
@@ -330,12 +330,12 @@ export class NativeQueryBuilder {
330
330
  this.parts.push(`)${asKeyword}${this.quote('dcnt')}`);
331
331
  }
332
332
  }
333
- /** Whether this COUNT query needs a subquery wrapper for multi-column distinct. */
333
+ /** Whether this COUNT query needs a subquery wrapper: multi-column distinct, or `distinct on` (keeps the null group). */
334
334
  needsCountSubquery() {
335
335
  return (this.type === QueryType.COUNT &&
336
336
  !!this.options.distinct &&
337
- this.options.select.length > 1 &&
338
- !this.platform.supportsMultiColumnCountDistinct());
337
+ ((this.options.select.length > 1 && !this.platform.supportsMultiColumnCountDistinct()) ||
338
+ !!this.options.distinctOn));
339
339
  }
340
340
  getFields(countSubquery) {
341
341
  if (!this.options.select || this.options.select.length === 0) {
@@ -257,7 +257,11 @@ export class QueryBuilder {
257
257
  if (field) {
258
258
  this.#state.fields = Utils.asArray(field);
259
259
  }
260
- else if (distinct || this.hasToManyJoins()) {
260
+ else if (this.#state.distinctOn) {
261
+ this.#state.fields = this.#state.distinctOn;
262
+ distinct = true;
263
+ }
264
+ else if (distinct || this.#state.flags.has(QueryFlag.DISTINCT) || this.hasToManyJoins()) {
261
265
  this.#state.fields = this.mainAlias.meta.primaryKeys;
262
266
  }
263
267
  else {
@@ -1760,6 +1764,9 @@ export class QueryBuilder {
1760
1764
  case QueryType.COUNT: {
1761
1765
  const fields = this.#state.fields.map(f => this.helper.mapper(f, this.type, undefined, undefined, schema));
1762
1766
  qb.count(fields, this.#state.flags.has(QueryFlag.DISTINCT));
1767
+ if (this.#state.distinctOn && this.#state.flags.has(QueryFlag.DISTINCT)) {
1768
+ qb.distinctOn(this.prepareFields(this.#state.distinctOn, 'where', schema));
1769
+ }
1763
1770
  this.helper.processJoins(qb, this.#state.joins, joinSchema, schemaOverride);
1764
1771
  break;
1765
1772
  }