Connecting to a database

patio.createConnection

When using patio.createConnection to connect a database there are two types of parameters you can use.

Connetion URI

This is a well formed URI that will be used to connect to the database.

Currently supported databases

Query options

Note: All other options will be passed to the underlying driver see the driver documentation for additional options.

  1. //Create a connection to a mysql database at localhost port 3306, with the username test, password test and
  2. // 1 connection by default and a max of 10
  3. var DB = patio.createConnection("mysql://test:testpass@localhost:3306/test?maxConnections=1&minConnections=10");

Connection Object

This is an object to used to connect.

Currently supported databases

Options

Note: All other options will be passed to the underlying driver see the driver documentation for additional options.

  1. //connect using an object
  2. var DB = patio.createConnection({
  3. host : "localhost",
  4. port : 3306,
  5. type : "mysql",
  6. maxConnections : 10,
  7. minConnections : 1,
  8. user : "test",
  9. password : "testpass",
  10. database : 'test'
  11. });
  12. //Create a connection to a mysql database at localhost port 3306, with the username test, password test and
  13. // 1 connection by default and a max of 10

Disconnecting

To disconnect from a database you can use:

  1. patio.disconnect().chain(function(){
  2. //all databases are disconnected all queued queries have finished
  3. });
  1. DB.disconnect().chain(function(){
  2. //database is disconnected and all queued queries have finished
  3. });

Documentation generated using coddoc.