Guest User

Untitled

a guest
Jul 15th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. import "reflect-metadata";
  2. import { createConnection, ConnectionManager, getConnectionManager } from "typeorm";
  3.  
  4. export class Database {
  5. private connectionManager: ConnectionManager
  6.  
  7. constructor() {
  8. console.log(`Database()`)
  9. this.connectionManager = getConnectionManager()
  10. }
  11.  
  12. public async getConnection() {
  13. console.log(`Database.getConnection()`)
  14.  
  15. try {
  16. return this.connectionManager.get()
  17. }
  18. catch (e) {
  19. console.warn(e)
  20. return createConnection({
  21. type: "postgres",
  22. host: "localhost",
  23. port: 5432,
  24. username: "postgres",
  25. database: "postgres",
  26. entities: [
  27. __dirname + "/entities/*.js"
  28. ],
  29. synchronize: true,
  30. logging: false
  31. })
  32. }
  33. }
  34. }
Add Comment
Please, Sign In to add comment