feat(backend): Mechanisme geïmplementeerd om makkelijk repositories te verkrijgen.
This commit is contained in:
		
							parent
							
								
									374de3b21a
								
							
						
					
					
						commit
						b730be375c
					
				
					 4 changed files with 26 additions and 11 deletions
				
			
		|  | @ -1,4 +1,4 @@ | |||
| import {AnyEntity, EntityName, EntityRepository, MikroORM} from '@mikro-orm/core'; | ||||
| import { EntityManager, MikroORM} from '@mikro-orm/core'; | ||||
| import config from './mikro-orm.config.js'; | ||||
| import {EnvVars, getEnvVar} from "./util/envvars"; | ||||
| 
 | ||||
|  | @ -17,10 +17,9 @@ export async function initORM(testingMode: boolean = false) { | |||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| export function getRepository<T extends AnyEntity>(entityName: EntityName<T>): EntityRepository<T> { | ||||
|     if (orm === undefined) { | ||||
|         throw new Error("ORM is not initialized yet"); | ||||
| export function forkEntityManager(): EntityManager { | ||||
|     if (!orm) { | ||||
|         throw Error("Accessing the Entity Manager before the ORM is fully initialized.") | ||||
|     } | ||||
|     return orm.em.fork().getRepository(entityName); | ||||
|     return orm.em.fork(); | ||||
| } | ||||
|  |  | |||
		Reference in a new issue
	
	 Gerald Schmittinger
						Gerald Schmittinger