Created
March 25, 2020 09:41
-
-
Save mattwynne/adcfee0254fddc7290445f68d8f64342 to your computer and use it in GitHub Desktop.
ten second pause at end of typeorm script... why?
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
import "reflect-metadata"; | |
import {createConnection} from "typeorm"; | |
import {User} from "./entity/User"; | |
process.on('exit', () => { | |
console.log('exit: ', new Date()) | |
}) | |
createConnection().then(async connection => { | |
console.log("Inserting a new user into the database..."); | |
const user = new User(); | |
user.firstName = "Timber"; | |
user.lastName = "Saw"; | |
user.age = 25; | |
await connection.manager.save(user); | |
console.log("Saved a new user with id: " + user.id); | |
console.log("Loading users from the database..."); | |
const users = await connection.manager.find(User); | |
console.log("Loaded users: ", users); | |
console.log("Here you can setup and run express/koa/any other framework."); | |
console.log(new Date()) | |
}).catch(error => console.log(error)); | |
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
➤ npm start | |
> tmp@0.0.1 start /Users/matt/projects/tmp | |
> ts-node src/index.ts | |
Inserting a new user into the database... | |
Saved a new user with id: 7 | |
Loading users from the database... | |
Loaded users: [ | |
User { id: 1, firstName: 'Timber', lastName: 'Saw', age: 25 }, | |
User { id: 2, firstName: 'Timber', lastName: 'Saw', age: 25 }, | |
User { id: 3, firstName: 'Timber', lastName: 'Saw', age: 25 }, | |
User { id: 4, firstName: 'Timber', lastName: 'Saw', age: 25 }, | |
User { id: 5, firstName: 'Timber', lastName: 'Saw', age: 25 }, | |
User { id: 6, firstName: 'Timber', lastName: 'Saw', age: 25 }, | |
User { id: 7, firstName: 'Timber', lastName: 'Saw', age: 25 } | |
] | |
Here you can setup and run express/koa/any other framework. | |
2020-03-25T09:36:19.569Z | |
exit: 2020-03-25T09:36:29.574Z |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment