-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: multiple database connection with
autoLoadEntities
(#62)
- Loading branch information
Showing
5 changed files
with
100 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { AnyEntity, EntityName } from '@mikro-orm/core'; | ||
|
||
export class MikroOrmEntitiesStorage { | ||
|
||
private static readonly storage = new Map<string, Set<EntityName<AnyEntity>>>(); | ||
|
||
static addEntity(entity: EntityName<AnyEntity>, contextName = 'default') { | ||
let set = this.storage.get(contextName); | ||
if (!set) { | ||
set = new Set<EntityName<AnyEntity>>(); | ||
this.storage.set(contextName, set); | ||
} | ||
|
||
set.add(entity); | ||
} | ||
|
||
static getEntities(contextName = 'default') { | ||
return this.storage.get(contextName)?.values() || []; | ||
} | ||
|
||
static clear(contextName = 'default') { | ||
const set = this.storage.get(contextName); | ||
if (!set) { | ||
return; | ||
} | ||
|
||
set.clear(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters