Skip to content

app-context/app-context-mysql2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

app-context-mysql2

mysql2 initializer for app-context

Usage

This initializer can be auto-installed by using it in your context file.

This initializer will attach the configured connections to APP.mysql.

module.exports = function() {
  this.runlevel('connected')
    // attach a connection to APP.mysql - use the value at APP.config.mysql as the connection string
    .use('mysql2', '$mysql')

    // attach a connection to APP.mysql
    .use('mysql2', 'mysql://localhost:3306/foobar')

    // attach a connection pool to APP.mysql
    .use('mysql2', {url: 'mysql://localhost:3306/foobar', pool: true})

    // create 2 connections and attach them as an object to APP.mysql
    // this will create APP.mysql.users and APP.mysql.data
    .use('mysql2', {
      users: '$mysql.users',
      data: '$mysql.data'
    })

    // you can also pass options to each connection
    .use('mysql2', {
      users: {url: 'mysql://localhost:3306/users', pool: true},
      data: {url: 'mysql://localhost:3306/data', connectTimeout: 3000}
    })
};

Connection Configurations

Each connection can be configured with either a connection string (like mysql://localhost:3306/users) or with an object. The object will be passed through to the mysql constructor and can consist of any options from connection options. There is a special url option not listed that this initializer will parse and fill in for you (like the user, password, host, and port).

Connection Pooling

You can make any connection a pool by adding {pool: true} to the configuration. Other options from the configuration will be passed through to the mysql driver. You can see the available options at connection options and pool options.

About

mysql2 initializer for app-context

Resources

Stars

Watchers

Forks

Packages

No packages published