Skip to content

Connection

Arian Johnson edited this page May 4, 2018 · 21 revisions

Creates a new MySQL Connection Pool.

Kind: global class


new Connection(settingsopt)

Instantiates a new Connection object. It can be configured in the following ways:

  • Via a settings object passed directly to the Connection on instantiation.
  • Via the database.cfg.js file in the /config/ folder.
  • If neither are found, Connection assumes the local mysql database on your server.
Param Type Default Description
settings opt DBSettings {} The database server pool settings.

Members

connection.config : DBConfig

Describes the global database settings.Config object (used for all pool servers).

  • Kind: instance property of Connection
  • Read only: true

connection.servers : DBPool

Describes the collection of DBPool servers in settings.Pool.

  • Kind: instance property of Connection
  • Read only: true

connection.pool : MySQL.PoolCluster

A MySQL connection pool

  • Kind: instance property of Connection
  • Read only: true

connection.keptAlive : boolean

Whether or not the Connection is being kept alive

  • Kind: instance property of Connection
  • Read only: true

Methods

connection.init()

Initiates the Database pool.


connection.ping()

Sends a ping to the database, expecting a response.


connection.keepAlive()

Will continually ping the db at an interval specified in the configs.


connection.acquire(success, failure)

Aquires a database connection from the pool.

Param Type Description
success CBsuccess A callback to handle the MySQL connection pool that was successfully acquired.
failure CBfailure A callback to handle the failure to aquire a MySQL connection pool.

connection.finish()

Closes the database connection.


connection.log(message, err)

Sends out database logs.

Param Type Description
message string On success; message is displayed as-is. On error it's used as a sprintf-style template for err.message.
err Error An error object; if applicable.

Clone this wiki locally