express-ts-template/src/config/index.ts

21 lines
671 B
TypeScript
Raw Normal View History

2023-10-24 06:27:28 +00:00
import { AppDataSource } from "./database"
2023-10-24 05:25:21 +00:00
import { User } from "../entity/User"
2023-10-24 05:16:21 +00:00
AppDataSource.initialize().then(async () => {
console.log("Inserting a new user into the database...")
const user = new User()
user.firstName = "Timber"
user.lastName = "Saw"
user.age = 25
await AppDataSource.manager.save(user)
console.log("Saved a new user with id: " + user.id)
console.log("Loading users from the database...")
const users = await AppDataSource.manager.find(User)
console.log("Loaded users: ", users)
console.log("Here you can setup and run express / fastify / any other framework.")
}).catch(error => console.log(error))