Created
November 26, 2020 18:06
-
-
Save marcosdeaguiar/89384391686d3fcd42543af7bba6867a to your computer and use it in GitHub Desktop.
Setup TypeORM connection loop.
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 { createConnection, Connection, getConnection } from "typeorm"; | |
import { CONNECTION_STRING } from "./config"; | |
const setupTypeORM = async () => { | |
let connection: any = null; | |
while (connection == undefined || !connection.isConnected) | |
{ | |
try { | |
connection = await createConnection({ | |
type: 'postgres', | |
url: CONNECTION_STRING, | |
entities: [ | |
"src/entity/**/*.ts" | |
] | |
}); | |
console.log("TypeORM connected."); | |
} | |
catch(err: any) | |
{ | |
console.log("Fail to connect TypeORM."); | |
await new Promise(resolve => setTimeout(resolve, 1000)); | |
} | |
} | |
} | |
export default setupTypeORM; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment