Connection
Connection
does not setup a database connection as it might seem, instead it sets up a connection pool. If you are interested in a real database connection, then refer to QueryRunner
documentation. Each instance of QueryRunner
is a separate isolated database connection. Connection pool setup is established once connect
method of the Connection
is called. connect
method is called automatically if you setup your connection using createConnection
function. Disconnection (closing all connections in the pool) is made when close
is called. Generally, you must create connection only once in your application bootstrap, and close it after you completely finished working with the database. In practice, if you are building a backend for your site and your backend server always stays running - you never close a connection.createConnection
and createConnections
functions.createConnection
creates a single connection:url
attribute, plus the type
attribute, will work too.createConnections
creates multiple connections:Connection
based on connection options you pass and call a connect
method. You can create ormconfig.json file in the root of your project and connection options will be automatically read from this file by those methods. Root of your project is the same level where your node_modules
directory is.default
. Usually, you use multiple connections when you use multiple databases or multiple connection configurations.getConnection
function:ConnectionManager
ConnectionManager
class. For example:ConnectionManager
:getConnection()
anymore - you'll need to store your connection manager instance and use connectionManager.get
to get a connection you need.ConnectionManager
only if you really think you need it.getConnection
function:ConnectionManager#get
to get a connection, but using getConnection()
is enough in most cases.EntityManager
and Repository
. For more information about them see Entity Manager and Repository documentation.Connection
much. Most of the time you only create a connection and use getRepository()
and getManager()
to access your connection's manager and repositories without directly using connection object: