@mikro-orm/core 7.0.0-dev.175 → 7.0.0-dev.176

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/errors.d.ts CHANGED
@@ -67,6 +67,7 @@ export declare class MetadataError<T extends AnyEntity = AnyEntity> extends Vali
67
67
  static targetKeyNotFound(meta: EntityMetadata, prop: EntityProperty): MetadataError<Partial<any>>;
68
68
  static dangerousPropertyName(meta: EntityMetadata, prop: EntityProperty): MetadataError<Partial<any>>;
69
69
  static viewEntityWithoutExpression(meta: EntityMetadata): MetadataError;
70
+ static materializedWithoutView(meta: EntityMetadata): MetadataError;
70
71
  private static fromMessage;
71
72
  }
72
73
  export declare class NotFoundError<T extends AnyEntity = AnyEntity> extends ValidationError<T> {
package/errors.js CHANGED
@@ -228,6 +228,9 @@ export class MetadataError extends ValidationError {
228
228
  static viewEntityWithoutExpression(meta) {
229
229
  return new MetadataError(`View entity ${meta.className} is missing 'expression'. View entities must have an expression defining the SQL query.`);
230
230
  }
231
+ static materializedWithoutView(meta) {
232
+ return new MetadataError(`Entity ${meta.className} has 'materialized: true' but is missing 'view: true'. Materialized views must also be marked as views.`);
233
+ }
231
234
  static fromMessage(meta, prop, message) {
232
235
  return new MetadataError(`${meta.className}.${prop.name} ${message}`);
233
236
  }
@@ -19,6 +19,9 @@ const DANGEROUS_PROPERTY_NAMES = ['__proto__', 'constructor', 'prototype'];
19
19
  export class MetadataValidator {
20
20
  validateEntityDefinition(metadata, name, options) {
21
21
  const meta = metadata.get(name);
22
+ if (meta.materialized && !meta.view) {
23
+ throw MetadataError.materializedWithoutView(meta);
24
+ }
22
25
  // View entities (expression with view flag) behave like regular tables but are read-only
23
26
  // They can have primary keys and are created as actual database views
24
27
  if (meta.view) {
@@ -35,6 +35,18 @@ export type EntityOptions<T, E = T extends EntityClass<infer P> ? P : T> = {
35
35
  * View entities are read-only by default.
36
36
  */
37
37
  view?: boolean;
38
+ /**
39
+ * Marks the view entity as a materialized view. Requires `view: true`.
40
+ * Materialized views store the query results and must be refreshed to update data.
41
+ * Only supported on PostgreSQL.
42
+ */
43
+ materialized?: boolean;
44
+ /**
45
+ * For materialized views, whether to populate data immediately on creation.
46
+ * Defaults to `true`. Set to `false` to create an unpopulated materialized view.
47
+ * Only applicable when `materialized: true`.
48
+ */
49
+ withData?: boolean;
38
50
  /** Used to make ORM aware of externally defined triggers. This is needed for MS SQL Server multi inserts, ignored in other dialects. */
39
51
  hasTriggers?: boolean;
40
52
  /** SQL query that maps to a {@doclink virtual-entities | virtual entity}, or for view entities, the view definition. */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
3
  "type": "module",
4
- "version": "7.0.0-dev.175",
4
+ "version": "7.0.0-dev.176",
5
5
  "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.",
6
6
  "exports": {
7
7
  "./package.json": "./package.json",
@@ -27,6 +27,7 @@ export declare abstract class Platform {
27
27
  supportsNativeEnums(): boolean;
28
28
  /** for postgres text enums (default) */
29
29
  usesEnumCheckConstraints(): boolean;
30
+ supportsMaterializedViews(): boolean;
30
31
  getSchemaHelper(): unknown;
31
32
  indexForeignKeys(): boolean;
32
33
  /**
@@ -41,6 +41,9 @@ export class Platform {
41
41
  usesEnumCheckConstraints() {
42
42
  return false;
43
43
  }
44
+ supportsMaterializedViews() {
45
+ return false;
46
+ }
44
47
  getSchemaHelper() {
45
48
  return undefined;
46
49
  }
package/typings.d.ts CHANGED
@@ -474,6 +474,10 @@ export interface EntityMetadata<Entity = any, Class extends EntityCtor<Entity> =
474
474
  virtual?: boolean;
475
475
  /** True if this entity represents a database view (not a virtual entity). */
476
476
  view?: boolean;
477
+ /** True if this is a materialized view (PostgreSQL only). Requires `view: true`. */
478
+ materialized?: boolean;
479
+ /** For materialized views, whether data is populated on creation. Defaults to true. */
480
+ withData?: boolean;
477
481
  expression?: string | ((em: any, where: ObjectQuery<Entity>, options: FindOptions<Entity, any, any, any>, stream?: boolean) => MaybePromise<Raw | object | string>);
478
482
  discriminatorColumn?: EntityKey<Entity> | AnyString;
479
483
  discriminatorValue?: number | string;
package/utils/Utils.js CHANGED
@@ -123,7 +123,7 @@ export function parseJsonSafe(value) {
123
123
  }
124
124
  export class Utils {
125
125
  static PK_SEPARATOR = '~~~';
126
- static #ORM_VERSION = '7.0.0-dev.175';
126
+ static #ORM_VERSION = '7.0.0-dev.176';
127
127
  /**
128
128
  * Checks if the argument is instance of `Object`. Returns false for arrays.
129
129
  */