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
				
			
		
							
								
								
									
										1477
									
								
								backend/package-lock.json
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										1477
									
								
								backend/package-lock.json
									
										
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							|  | @ -20,13 +20,19 @@ | ||||||
|   }, |   }, | ||||||
|   "homepage": "https://sel2-1.ugent.be/", |   "homepage": "https://sel2-1.ugent.be/", | ||||||
|   "dependencies": { |   "dependencies": { | ||||||
|  |     "@mikro-orm/core": "^6.4.6", | ||||||
|  |     "@mikro-orm/reflection": "^6.4.6", | ||||||
|  |     "@mikro-orm/postgresql": "^6.4.6", | ||||||
|     "dotenv": "^16.4.7", |     "dotenv": "^16.4.7", | ||||||
|     "express": "^5.0.1" |     "express": "^5.0.1" | ||||||
|   }, |   }, | ||||||
|   "devDependencies": { |   "devDependencies": { | ||||||
|  |     "@mikro-orm/cli": "^6.4.6", | ||||||
|     "@types/express": "^5.0.0", |     "@types/express": "^5.0.0", | ||||||
|     "@types/node": "^22.13.4", |     "@types/node": "^22.13.4", | ||||||
|  |     "ts-node": "^10.9.2", | ||||||
|     "tsx": "^4.19.3", |     "tsx": "^4.19.3", | ||||||
|     "typescript": "^5.7.3" |     "typescript": "^5.7.3", | ||||||
|  |     "vitest": "^3.0.6" | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,15 +1,21 @@ | ||||||
| import express, {Express, Request, Response} from 'express'; | import express, {Express, Request, Response} from 'express'; | ||||||
|  | import initORM from './orm' | ||||||
| 
 | 
 | ||||||
| const app: Express = express(); | const app: Express = express(); | ||||||
| 
 |  | ||||||
| const port: string | number = process.env.PORT || 3000; | const port: string | number = process.env.PORT || 3000; | ||||||
| 
 | 
 | ||||||
|  | // TODO Replace with Express routes
 | ||||||
| app.get('/', (_, res: Response) => { | app.get('/', (_, res: Response) => { | ||||||
|   res.json({ |   res.json({ | ||||||
|       message: 'Hello Dwengo!' |       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}`); |     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); | ||||||
|  | } | ||||||
|  | @ -14,8 +14,8 @@ | ||||||
|     "target": "ESNext",                                  /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ |     "target": "ESNext",                                  /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ | ||||||
|     // "lib": [],                                        /* Specify a set of bundled library declaration files that describe the target runtime environment. */ |     // "lib": [],                                        /* Specify a set of bundled library declaration files that describe the target runtime environment. */ | ||||||
|     // "jsx": "preserve",                                /* Specify what JSX code is generated. */ |     // "jsx": "preserve",                                /* Specify what JSX code is generated. */ | ||||||
|     // "experimentalDecorators": true,                   /* Enable experimental support for legacy experimental decorators. */ |     "experimentalDecorators": true,                      /* Enable experimental support for legacy experimental decorators. */ | ||||||
|     // "emitDecoratorMetadata": true,                    /* Emit design-type metadata for decorated declarations in source files. */ |     "emitDecoratorMetadata": true,                       /* Emit design-type metadata for decorated declarations in source files. */ | ||||||
|     // "jsxFactory": "",                                 /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ |     // "jsxFactory": "",                                 /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ | ||||||
|     // "jsxFragmentFactory": "",                         /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ |     // "jsxFragmentFactory": "",                         /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ | ||||||
|     // "jsxImportSource": "",                            /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ |     // "jsxImportSource": "",                            /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ | ||||||
|  |  | ||||||
		Reference in a new issue