Skip to content

Commit

Permalink
feat(mikro-orm): introduce @Orm() decorator
Browse files Browse the repository at this point in the history
`@Connection()` decorator has been deprecated and aliased with new `@Orm()` to align API with MikroORM naming convention

closes #1741
  • Loading branch information
derevnjuk authored and Romakita committed Jan 29, 2022
1 parent 01dd0b4 commit 1efc2ed
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
5 changes: 0 additions & 5 deletions packages/orm/mikro-orm/src/decorators/connection.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/orm/mikro-orm/src/decorators/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./transactional";
export * from "./connection";
export * from "./orm";
export * from "./entityManager";
10 changes: 10 additions & 0 deletions packages/orm/mikro-orm/src/decorators/orm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {MikroOrmRegistry} from "../services";
import {Inject} from "@tsed/di";

/**
* @deprecated Since 2022-02-01. Use {@link Orm} instead
*/
export const Connection = (contextName?: string): PropertyDecorator => Orm(contextName);

export const Orm = (contextName?: string): PropertyDecorator =>
Inject(MikroOrmRegistry, (registry: MikroOrmRegistry) => registry.get(contextName)) as PropertyDecorator;
14 changes: 7 additions & 7 deletions packages/orm/mikro-orm/test/helpers/services/UserService.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {Injectable} from "@tsed/di";
import {EntityManager, MikroORM} from "@mikro-orm/core";
import {Connection, Em} from "../../../src";
import {Orm, Em} from "../../../src";

@Injectable()
export class UserService {
@Connection()
connection!: MikroORM;
@Orm()
orm!: MikroORM;

@Connection("db1")
connection1!: MikroORM;
@Orm("db1")
orm1!: MikroORM;

@Connection("db2")
connection2!: MikroORM;
@Orm("db2")
orm2!: MikroORM;

@Em()
em!: EntityManager;
Expand Down
12 changes: 6 additions & 6 deletions packages/orm/mikro-orm/test/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ describe("TypeORM integration", () => {
const service = PlatformTest.injector.get<UserService>(UserService)!;

expect(service).toBeInstanceOf(UserService);
expect(service.connection).toBeInstanceOf(MikroORM);
expect(service.connection.em.name).toBe("default");
expect(service.orm).toBeInstanceOf(MikroORM);
expect(service.orm.em.name).toBe("default");
expect(service.em.name).toBe("default");

expect(service.connection1).toBeInstanceOf(MikroORM);
expect(service.connection1.em.name).toBe("db1");
expect(service.orm1).toBeInstanceOf(MikroORM);
expect(service.orm1.em.name).toBe("db1");
expect(service.em1.name).toBe("db1");

expect(service.connection2).toBeInstanceOf(MikroORM);
expect(service.connection2.em.name).toBe("db2");
expect(service.orm2).toBeInstanceOf(MikroORM);
expect(service.orm2.em.name).toBe("db2");
expect(service.em2.name).toBe("db2");

expect(service.em3).toEqual(undefined);
Expand Down

0 comments on commit 1efc2ed

Please sign in to comment.