chore(backend): Setup MikroORM
Simpele configuratie, geen integratie Succesvol commando's uitvoeren werkt
This commit is contained in:
		
							parent
							
								
									6d73120975
								
							
						
					
					
						commit
						2f280d3fb2
					
				
					 8 changed files with 1341 additions and 191 deletions
				
			
		|  | @ -1,15 +1,21 @@ | |||
| import express, {Express, Request, Response} from 'express'; | ||||
| import initORM from './orm' | ||||
| 
 | ||||
| const app: Express = express(); | ||||
| 
 | ||||
| const port: string | number = process.env.PORT || 3000; | ||||
| 
 | ||||
| // TODO Replace with Express routes
 | ||||
| app.get('/', (_, res: Response) => { | ||||
|   res.json({ | ||||
|       message: 'Hello Dwengo!' | ||||
|   }); | ||||
| }); | ||||
| 
 | ||||
| app.listen(port, () => { | ||||
| async function startServer() { | ||||
|   const orm = await initORM(); | ||||
|   app.listen(port, () => { | ||||
|     console.log(`Server is running at http://localhost:${port}`); | ||||
| }) | ||||
|   }); | ||||
| } | ||||
| 
 | ||||
| startServer(); | ||||
|  |  | |||
							
								
								
									
										13
									
								
								backend/src/entities/user.entity.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								backend/src/entities/user.entity.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,13 @@ | |||
| import { Entity, OneToOne, PrimaryKey, Property } from '@mikro-orm/core' | ||||
| 
 | ||||
| @Entity() | ||||
| export class User { | ||||
|   @PrimaryKey({ type: 'number' }) | ||||
|   id!: number; | ||||
| 
 | ||||
|   @Property() | ||||
|   firstName: string = ''; | ||||
| 
 | ||||
|   @Property() | ||||
|   lastName: string = ''; | ||||
| } | ||||
							
								
								
									
										12
									
								
								backend/src/mikro-orm.config.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								backend/src/mikro-orm.config.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,12 @@ | |||
| import { Options } from '@mikro-orm/core' | ||||
| import { PostgreSqlDriver } from '@mikro-orm/postgresql' | ||||
| 
 | ||||
| const config: Options = { | ||||
|   driver: PostgreSqlDriver, | ||||
|   dbName: 'dwengo', | ||||
|   entities: ['dist/**/*.entity.js'], | ||||
|   entitiesTs: ['src/**/*.entity.ts'], | ||||
|   debug: true | ||||
| }; | ||||
| 
 | ||||
| export default config; | ||||
							
								
								
									
										6
									
								
								backend/src/orm.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								backend/src/orm.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,6 @@ | |||
| import { MikroORM } from '@mikro-orm/core' | ||||
| import config from './mikro-orm.config'; | ||||
| 
 | ||||
| export default async function initORM() { | ||||
|   await MikroORM.init(config); | ||||
| } | ||||
		Reference in a new issue