title: TypeORM create connection globally
body: <p>I am using <a href="https://github.com/typeorm/typeorm" rel="nofollow noreferrer">typeorm</a> with typescript in my node Js application. I am trying to figure out the way of using the single DB connection for all functions in the class. For example, I have two functions my class and want to use the global/single connection for all functions instead of creating a connection in every function as shown below:</p>
  
  <pre><code>export class SQLDBService implements IDatabaseService{
  private readonly logger = getLogger("SQLDBService");
  private connection:Connection;
  
  
    getConversation(conversationId: string): ConversationEntity {
  
      let conversationEntity = new ConversationEntity();
      createConnection(/*...*/).then(async connection =&gt; {
          let dbObj = await connection.getRepository(ConversationEntity).findOne({
              conversationId: Equal(conversationId)
          });
          if(dbObj)
              conversationEntity = dbObj;
      });
      return conversationEntity;
  }
  
    pushWrapUp(conversationId: string, wrapUp: string): void {
  
      createConnection().then(async connection =&gt; {
          let conversationEntity = await connection.getRepository(ConversationEntity).findOne({
              conversationId: Equal(conversationId)
          });
          if(conversationEntity){
              conversationEntity.wrapUp = wrapUp;
              conversationEntity.endTime = new Date();
              await connection.manager.save(conversationEntity);
          }
      });
  }}
  </code></pre>
  
  <p>Can someone point me in the right direction?</p>