When using patio.createConnection to connect a database there are two types of parameters you can use.
This is a well formed URI that will be used to connect to the database.
Currently supported databases
pg
: example pg://test:testpass@localhost:5432/test
mysql
: example mysql://test:testpass@localhost:3306/test
Query options
maxConnections
: maximum number of connections to keep in the poolminConnections
: minimum number of connections to keep in the poolNote: All other options will be passed to the underlying driver see the driver documentation for additional options.
//Create a connection to a mysql database at localhost port 3306, with the username test, password test and
// 1 connection by default and a max of 10
var DB = patio.createConnection("mysql://test:testpass@localhost:3306/test?maxConnections=1&minConnections=10");
This is an object to used to connect.
Currently supported databases
pg
: example pg://test:testpass@localhost:5432/test
mysql
: example mysql://test:testpass@localhost:3306/test
Options
type
pg
: use postgres adaptermysql
: use mysql adapterhost
: host of the databaseport
: port the database is accepting connections onuser
: user to connect to the database aspassword
: passworddatabase
: database (schema
) to connect tomaxConnections
: maximum number of connections to keep in the poolminConnections
: minimum number of connections to keep in the poolNote: All other options will be passed to the underlying driver see the driver documentation for additional options.
//connect using an object
var DB = patio.createConnection({
host : "localhost",
port : 3306,
type : "mysql",
maxConnections : 10,
minConnections : 1,
user : "test",
password : "testpass",
database : 'test'
});
//Create a connection to a mysql database at localhost port 3306, with the username test, password test and
// 1 connection by default and a max of 10
To disconnect from a database you can use:
patio.disconnect().chain(function(){
//all databases are disconnected all queued queries have finished
});
DB.disconnect().chain(function(){
//database is disconnected and all queued queries have finished
});