| 
									
										
										
										
											2021-06-17 16:17:15 +02:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-26 17:52:59 +02:00
										 |  |  | const util = require('util'); | 
					
						
							| 
									
										
										
										
											2021-06-17 16:17:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-28 21:37:44 +02:00
										 |  |  | const { Database } = require('../lib/index'); | 
					
						
							| 
									
										
										
										
											2021-06-24 18:28:36 +02:00
										 |  |  | const models = require('./models'); | 
					
						
							|  |  |  | const connections = require('./connections'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-28 21:37:44 +02:00
										 |  |  | async function main(connection) { | 
					
						
							| 
									
										
										
										
											2021-06-28 12:34:29 +02:00
										 |  |  |   const orm = await Database.init({ | 
					
						
							| 
									
										
										
										
											2021-06-28 21:37:44 +02:00
										 |  |  |     connection, | 
					
						
							| 
									
										
										
										
											2021-06-24 18:28:36 +02:00
										 |  |  |     models: Database.transformContentTypes(models), | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-06-17 16:17:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 18:28:36 +02:00
										 |  |  |   try { | 
					
						
							|  |  |  |     // await orm.schema.drop();
 | 
					
						
							|  |  |  |     // await orm.schema.create();
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-26 17:52:59 +02:00
										 |  |  |     await orm.schema.reset(); | 
					
						
							| 
									
										
										
										
											2021-06-24 18:28:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-26 19:40:30 +02:00
										 |  |  |     let res; | 
					
						
							| 
									
										
										
										
											2021-07-08 18:15:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-26 19:40:30 +02:00
										 |  |  |     const c1 = await orm.query('comment').create({ | 
					
						
							| 
									
										
										
										
											2021-07-26 17:52:59 +02:00
										 |  |  |       data: { | 
					
						
							|  |  |  |         title: 'coucou', | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-26 19:40:30 +02:00
										 |  |  |     const c2 = await orm.query('video-comment').create({ | 
					
						
							| 
									
										
										
										
											2021-07-26 17:52:59 +02:00
										 |  |  |       data: { | 
					
						
							| 
									
										
										
										
											2021-07-26 19:40:30 +02:00
										 |  |  |         title: 'coucou', | 
					
						
							| 
									
										
										
										
											2021-07-26 17:52:59 +02:00
										 |  |  |       }, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-26 19:40:30 +02:00
										 |  |  |     res = await orm.query('article').create({ | 
					
						
							| 
									
										
										
										
											2021-07-26 17:52:59 +02:00
										 |  |  |       data: { | 
					
						
							|  |  |  |         dz: [ | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             __type: 'comment', | 
					
						
							|  |  |  |             id: c1.id, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             __type: 'video-comment', | 
					
						
							|  |  |  |             id: c2.id, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2021-07-26 19:40:30 +02:00
										 |  |  |       populate: { | 
					
						
							|  |  |  |         dz: true, | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2021-07-26 17:52:59 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-26 19:40:30 +02:00
										 |  |  |     log(res); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-26 17:52:59 +02:00
										 |  |  |     res = await orm.query('article').findMany({ | 
					
						
							|  |  |  |       populate: { | 
					
						
							|  |  |  |         dz: true, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     log(res); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-01 13:52:01 +02:00
										 |  |  |     // await tests(orm);
 | 
					
						
							| 
									
										
										
										
											2021-06-24 18:28:36 +02:00
										 |  |  |   } finally { | 
					
						
							|  |  |  |     orm.destroy(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-26 17:52:59 +02:00
										 |  |  | function log(res) { | 
					
						
							|  |  |  |   console.log(util.inspect(res, null, null, true)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-28 21:37:44 +02:00
										 |  |  | main(connections.sqlite); |