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.
775122
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;
}
686685
public static function use($connection)
    {
        if (! is_null($config = config("database.redis.clusters.{$connection}.0"))) {
            config(["database.redis.{$connection}" => $config]);
        } elseif (is_null($config) && is_null($config = config("database.redis.{$connection}"))) {
            throw new Exception("Redis connection [{$connection}] has not been configured.");
        }

        config(['database.redis.horizon' => array_merge($config, [
            'options' => ['prefix' => config('horizon.prefix') ?: 'horizon:'],
        ])]);
    }
802792
function assetsConfig() {
  return function(req, res, next) {
    //-- assets version
    res.locals.assetsVersion = sails.config.assets.version;

    //-- assets base_url
    res.locals.assetsBaseUrl = sails.config.assets.base_url;

    next();
  };
}
15530
function getSchema(connection) {
  const schema_sql = connection.schema_sql
    ? connection.schema_sql
    : SCHEMA_SQL_INFORMATION_SCHEMA;
  return runQuery(schema_sql, connection).then(queryResult =>
    formatSchemaQueryResults(queryResult)
  );
}
317038
protected function createConnection($connection)
    {
        // Load config connection
        $config = Arr::get($this->config, 'connections.' . $connection);
        if (is_null($config)) {
            throw new \InvalidArgumentException("config connection [$connection] not found.");
        }

        $driver = Arr::get($config, 'driver');
        if (is_null($driver)) {
            throw new \InvalidArgumentException("driver connection [$connection] not information.");
        }

        // We'll check to see if a creator method exists for the given connection. If not we
        // will check for a custom connection creator, which allows developers to create
        // connections using their own customized connection creator Closure to create it.
        if (isset($this->customCreators[$driver])) {
            return $this->callCustomCreator($driver, $config);
        } else {
            $method = 'create' . Str::studly($driver) . 'Driver';

            if (method_exists($this, $method)) {
                return $this->$method($config);
            }
        }
        throw new \InvalidArgumentException("driver [$driver] connection [$connection] not supported.");
    }
1325618
function connectToDB(connObject, ssl, _callback) {
        let connection;
        let sslObject;
        let connectionObject;
        if (ssl == true) {
            sslObject = {
                ca: fs.readFileSync(connObject.certificatePath),
            };
        }
        console.log('Setting connection params');
        if (connObject.dbtype === 'mysql') {
            if (ssl == true) {
                connectionObject = {
                    host: connObject.server,
                    port: connObject.port,
                    user: connObject.username,
                    password: connObject.password,
                    database: connObject.database,
                    connectTimeout: connObject.connTimeout,
                    ssl: sslObject,
                };
            } else {
                connectionObject = {
                    host: connObject.server,
                    port: connObject.port,
                    user: connObject.username,
                    password: connObject.password,
                    database: connObject.database,
                    connectTimeout: connObject.timeout,
                };
            }

            console.log('After initializing params for connection');
            // check if db connection string is provided
            if (checkTypes.assigned(connObject.connectionString)) {
                connection = mysql.createConnection(connectString);
            } else {
                connection = mysql.createConnection(connectionObject);
            }
            console.log('Calling connection connect');
            connection.connect(function(err) {
                _callback(err, connection);
                return connection;
            });
            return connection;
        } else {
            // TBD: Add implementation for handling other types of database and drivers.
            console.log('Invalid Database Type');
            return 0;
        }
    }
189895
function(callback)
    {
        // Connect to the given URI with the given options
        self.mongo.MongoClient.connect(self.config.uri, defaultOpts, function(err, db) {

            if (err) {
                return callback && callback(err);
            }

            // Rewrite connection
            self.connection = db;

            callback && callback(null, db);
        });
    }
210163
public HttpURLConnection buildConnection(URI baseServiceUri, String tail) {
    try {
      HttpURLConnection client = (HttpURLConnection) baseServiceUri.resolve(tail).toURL().openConnection();
      return client;
    } catch(MalformedURLException mue) {
      throw new EFhirClientException("Invalid Service URL", mue);
    } catch(IOException ioe) {
      throw new EFhirClientException("Unable to establish connection to server: " + baseServiceUri.toString() + tail, ioe);
    }
  }
485493
public void connectClient(Connection connection) {
    threadContext.checkThread();

    // Note we do not use method references here because the "state" variable changes over time.
    // We have to use lambdas to ensure the request handler points to the current state.
    connection.handler(RegisterRequest.class, (Function<RegisterRequest, CompletableFuture<RegisterResponse>>) request -> state.register(request));
    connection.handler(ConnectRequest.class, (Function<ConnectRequest, CompletableFuture<ConnectResponse>>) request -> state.connect(request, connection));
    connection.handler(KeepAliveRequest.class, (Function<KeepAliveRequest, CompletableFuture<KeepAliveResponse>>) request -> state.keepAlive(request));
    connection.handler(UnregisterRequest.class, (Function<UnregisterRequest, CompletableFuture<UnregisterResponse>>) request -> state.unregister(request));
    connection.handler(ResetRequest.class, (Consumer<ResetRequest>) request -> state.reset(request));
    connection.handler(CommandRequest.class, (Function<CommandRequest, CompletableFuture<CommandResponse>>) request -> state.command(request));
    connection.handler(QueryRequest.class, (Function<QueryRequest, CompletableFuture<QueryResponse>>) request -> state.query(request));

    connection.onClose(stateMachine.executor().context().sessions()::unregisterConnection);
  }
140185
def setConnection(self, connection):
        
        # define custom properties
        if not isinstance(connection, orb.Connection):
            conn = orb.Connection.byName(connection)
            if not conn:
                raise orb.errors.BackendNotFound(connection)
            connection = conn(self)
        else:
            connection.setDatabase(self)

        self.__connection = connection
854297
function getDatabaseConnector(database, options, callback) {
    if (typeof options === "function") {
        callback = options
        options = {}
    }

    options = extend({}, defaults, options)

    var server = new Server(options.host, options.port, options.serverOptions)
        , databaseConnector = new Db(database, server, options.dbOptions)

    databaseConnector.open(authOrReturn)

    function authOrReturn(err, db) {
        if (err) {
            return callback(err)
        }

        if (options.user || options.password) {
            db.authenticate(options.user, options.password
                , options.authenticateOptions, returnDb)
        } else {
            callback(null, db)
        }

        function returnDb(err, success) {
            if (err) {
                return callback(err)
            }

            if (!success) {
                return callback(new Error("auth failed"))
            }

            callback(null, db)
        }
    }
}
1306659
public function connection($connection = null)
    {
        $type = $connection ?? $this->defaultConnection;

        if (!isset($this->connection[$type]))
        {
            $slice = $this->slice->getSlice($type);

            $key     = $slice->getRequired('adapter');
            $adapter = $this->adapters[$key];

            $this->adapterProviders[$type] = new $adapter();

            $this->adapterProviders[$type]->setHost($slice->getData('host'));
            $this->adapterProviders[$type]->setPort($slice->getData('port'));

            if (method_exists($this->adapterProviders[$type], 'setPath'))
            {
                $this->adapterProviders[$type]->setPath($slice->getData('path'));
            }

            $this->adapterProviders[$type]->setDbName($slice->getData('database'));

            $this->adapterProviders[$type]->setConnection($this);

            $this->adapterProviders[$type]->setPDOClass(Connection::class);

            $options = [
                Connection::ATTR_DEFAULT_FETCH_MODE => Connection::FETCH_ASSOC,
                //Connection::ATTR_EMULATE_PREPARES   => true,
                //Connection::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
                //Connection::ATTR_PERSISTENT         => false,
                //Connection::MYSQL_ATTR_INIT_COMMAND       => 'SET NAMES utf8mb4'
            ];

            if ($this->adapterProviders[$type]->name() !== 'sqlite')
            {
                $options[Connection::ATTR_ERRMODE] = Connection::ERRMODE_EXCEPTION;
            }

            $this->connection[$type] = $this->adapterProviders[$type]->connection(
                $slice->getData('username'),
                $slice->getData('password'),
                $slice->getData('options', $options)
            );
        }

        return $this->connection[$type];
    }
407377
function getClient(callback) {
  if (!connectionOptions) {
    callback('Connection options missing. Please call db.connect before any other database functions to configure the database configuration');
  }

  if (activeBackend === 'mysql') {
    if (activeDb) {
      return callback(null, activeDb);
    }
    else {
      connect(connectionOptions);
      return callback(null, activeDb);
    }
  }
  else if (activeBackend === 'pgsql') {
    return pg.connect(connectionOptions, callback);
  }
}
425339
protected function getDatabaseConnectionConfig($connection)
    {
        $connections = $this->proxy->get('database.connections');
        if (!isset($connections[$connection])) {
            throw new Exception('Unknown database connection: ' . $connection);
        }
        $config = $connections[$connection];
        if (!in_array($config['driver'], ['mysql', 'pgsql'])) {
            throw new Exception('Currently only MySQL and PostgreSQL databases are supported using the laravel config');
        }
        return $config;
    }
1118088
function Client(config = {}) {
  this.config = config;
  this.logger = new Logger(config);

  //Client is a required field, so throw error if it's not supplied.
  //If 'this.dialect' is set, then this is a 'super()' call, in which case
  //'client' does not have to be set as it's already assigned on the client prototype.

  if (this.dialect && !this.config.client) {
    this.logger.warn(
      `Using 'this.dialect' to identify the client is deprecated and support for it will be removed in the future. Please use configuration option 'client' instead.`
    );
  }
  const dbClient = this.config.client || this.dialect;
  if (!dbClient) {
    throw new Error(`knex: Required configuration option 'client' is missing.`);
  }

  if (config.version) {
    this.version = config.version;
  }

  this.connectionSettings = cloneDeep(config.connection || {});
  if (this.driverName && config.connection) {
    this.initializeDriver();
    if (!config.pool || (config.pool && config.pool.max !== 0)) {
      this.initializePool(config);
    }
  }
  this.valueForUndefined = this.raw('DEFAULT');
  if (config.useNullAsDefault) {
    this.valueForUndefined = null;
  }
}
341429
function configureConnection(connection) {
        // Set the common hub
        abp.signalr.hubs.common = connection;

        // Reconnect if hub disconnects
        connection.onclose(function (e) {
            if (e) {
                abp.log.debug('Connection closed with error: ' + e);
            }
            else {
                abp.log.debug('Disconnected');
            }

            if (!abp.signalr.autoConnect) {
                return;
            }

            setTimeout(function () {
                if ($.connection.hub.state === $.signalR.connectionState.disconnected) {
                    $.connection.hub.start();
                }
            }, 5000);
        });

        // Register to get notifications
        connection.on('getNotification', function (notification) {
            abp.event.trigger('abp.notifications.received', notification);
        });
    }
905515
function connect() {
      var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var callback = arguments[1];

      this.host = props.host || '127.0.0.1';
      this.port = props.port || 21000;
      this.resultType = props.resultType || null;
      this.timeout = props.timeout || 1000;
      this.transport = props.transport || _thrift2.default.TBufferedTransport;
      this.protocol = props.protocol || _thrift2.default.TBinaryProtocol;
      this.options = {
        transport: this.transport,
        protocol: this.protocol,
        timeout: this.timeout
      };

      var deferred = _thrift.Q.defer();

      var connection = _thrift2.default.createConnection(this.host, this.port, this.options);
      var client = _thrift2.default.createClient(_ImpalaService2.default, connection);

      connection.on('error', ImpalaClient.onErrorDeferred(deferred));

      connection.on('connect', function () {
        deferred.resolve('Connection is established.');
      });

      this.client = client;
      this.connection = connection;

      deferred.promise.nodeify(callback);
      return deferred.promise;
    }