title: typeorm: what is the difference between getRepository() and getConnection()?
body: <p><a href="https://typeorm.io/#/select-query-builder/how-to-create-and-use-a-querybuilder" rel="noreferrer">https://typeorm.io/#/select-query-builder/how-to-create-and-use-a-querybuilder</a></p>
  <p>There are several ways how you can create a Query Builder:</p>
  <p>Using connection:</p>
  <pre><code>import {getConnection} from &quot;typeorm&quot;;
  
  const user = await getConnection()
      .createQueryBuilder()
      .select(&quot;user&quot;)
      .from(User, &quot;user&quot;)
      .where(&quot;user.id = :id&quot;, { id: 1 })
      .getOne();
  </code></pre>
  <p>Using entity manager:</p>
  <pre><code>import {getManager} from &quot;typeorm&quot;;
  
  const user = await getManager()
      .createQueryBuilder(User, &quot;user&quot;)
      .where(&quot;user.id = :id&quot;, { id: 1 })
      .getOne();
  </code></pre>
  <p>Using repository:</p>
  <pre><code>import {getRepository} from &quot;typeorm&quot;;
  
  const user = await getRepository(User)
      .createQueryBuilder(&quot;user&quot;)
      .where(&quot;user.id = :id&quot;, { id: 1 })
      .getOne();
  </code></pre>
  <p>The documentation never explains the difference among these methods.
  When to use each method?</p>