lib/sailsDbMigrate.js
function buildURL(connection) {
  var scheme;
  var url;

  switch (connection.adapter) {
    case 'sails-mysql':
      scheme = 'mysql';
      break;
    case 'sails-postgresql':
      scheme = 'postgres';
      break;
    case 'sails-mongo':
      scheme = 'mongodb'
      break;
    default:
      throw new Error('migrations not supported for ' + connection.adapter);
  }

  // return the connection url if one is configured
  if (connection.url) {
    return connection.url;
  }

  url = scheme + '://';
  if (connection.user) {
    url += connection.user;
    if (connection.password) {
      url += ':' + encodeURIComponent(connection.password)
    }
    url += '@';
  }
  url += connection.host || 'localhost';
  if (connection.port) {
    url += ':' + connection.port;
  }
  if (connection.database) {
    url += '/' + encodeURIComponent(connection.database);
  }

  var params = [];
  if (connection.multipleStatements) {
    params.push('multipleStatements=true');
  }

  if (params.length > 0) {
    url += '?' + params.join('&');
  }

  return url;
}
function buildURL(connection) {
  var scheme;
  var url;

  switch (connection.adapter) {
    case 'sails-mysql':
      scheme = 'mysql';
      break;
    case 'sails-postgresql':
      scheme = 'postgres';
      break;
    case 'sails-mongo':
      scheme = 'mongodb'
      break;
    default:
      throw new Error('migrations not supported for ' + connection.adapter);
  }

  // return the connection url if one is configured
  if (connection.url) {
    return connection.url;
  }

  url = scheme + '://';
  if (connection.user) {
    url += connection.user;
    if (connection.password) {
      url += ':' + encodeURIComponent(connection.password)
    }
    url += '@';
  }
  url += connection.host || 'localhost';
  if (connection.port) {
    url += ':' + connection.port;
  }
  if (connection.database) {
    url += '/' + encodeURIComponent(connection.database);
  }

  var params = [];
  if (connection.multipleStatements) {
    params.push('multipleStatements=true');
  }

  if (params.length > 0) {
    url += '?' + params.join('&');
  }

  return url;
}
function buildURL ( connection ) { var scheme ; var url ; switch ( connection . adapter ) { case 'sails-mysql' : scheme = 'mysql' ; break ; case 'sails-postgresql' : scheme = 'postgres' ; break ; case 'sails-mongo' : scheme = 'mongodb' break ; default : throw new Error ( 'migrations not supported for ' + connection . adapter ) ; } // return the connection url if one is configured if ( connection . url ) { return connection . url ; } url = scheme + '://' ; if ( connection . user ) { url += connection . user ; if ( connection . password ) { url += ':' + encodeURIComponent ( connection . password ) } url += '@' ; } url += connection . host || 'localhost' ; if ( connection . port ) { url += ':' + connection . port ; } if ( connection . database ) { url += '/' + encodeURIComponent ( connection . database ) ; } var params = [ ] ; if ( connection . multipleStatements ) { params . push ( 'multipleStatements=true' ) ; } if ( params . length > 0 ) { url += '?' + params . join ( '&' ) ; } return url ; }
Build a URL from the Sails connection config.

@param {object} connection Sails connection config.
@returns {string} URL for connecting to the specified database.
@throws Error if adapter is not supported.
Build a URL from the Sails connection config .