Get a schema builder instance for the connection.

@param $connection \Illuminate\Database\Connection
@return \FrenchFrogs\Laravel\Database\Schema\MysqlBuilder
964596
static public function getSchemaBuilder($connection)
    {

        if (get_class($connection) === 'Illuminate\Database\MySqlConnection') {
            /** @var \Illuminate\Database\MySqlConnection $connection */
            $MySqlGrammar = $connection->withTablePrefix(new MySqlGrammar);
            $connection->setSchemaGrammar($MySqlGrammar);
            return new MySqlBuilder($connection);
        }

        return $connection->getSchemaBuilder();
    }
1374120
protected function getSchemaBuilder()
    {
        /** @var  \Illuminate\Database\DatabaseManager  $db */
        $db = app()->make('db');

        return $db->connection($this->hasConnection() ? $this->getConnection() : null)
                  ->getSchemaBuilder();
    }
1198584
protected function resultsToModelsWithRelations($connection, ResultSet $results)
    {
        $models = [];

        if ($results->valid())
        {
            $grammar = $this->getQuery()->getGrammar();
            $columns = $results->getColumns();

            foreach ($results as $result)
            {
                $attributes = $this->getProperties($columns, $result);
                // Now that we have the attributes, we first check for mutations
                // and if exists, we will need to mutate the attributes accordingly.
                if ($this->shouldMutate($attributes))
                {
                    foreach ($attributes as $identifier => $values)
                    {
                        $cropped = $grammar->cropLabelIdentifier($identifier);

                        if (! isset($models[$cropped])) $models[$cropped] = [];

                        if(isset($this->mutations[$cropped]))
                        {
                            $mutationModel = $this->getMutationModel($cropped);
                            $model = $mutationModel->newFromBuilder($values);
                            $model->setConnection($mutationModel->getConnectionName());

                            $models[$cropped][] = $model;
                        }
                    }
                }
            }
        }

        return $models;
    }
324834
protected function getDriverName($connection)
    {
        try {
            return DB::connection($connection)->getDriverName();
        } catch (Exception $e) {
            $this->eye->logger()->debug('Unable to find DB driver', $connection);
        }

        return 'unknown';
    }
76244
public function build(Connection $connection, Grammar $grammar)
    {
        $command = $this->parseCommand($this->commands[0]->get('name'));
        $schema  = $connection->getSchemaBuilder();

        if ($command === "drop") {
            $schema->dropIfExists($this->getI18NTableName());
        }

        parent::build($connection, $grammar);

        if ($command === "create") {
            $primary      = $this->i18n_primary;
            $i18n_columns = $this->i18n_columns;
            $table_name   = $this->table;
            $schema->create($this->getI18NTableName(), function (Blueprint $table) use ($table_name, $primary, $i18n_columns) {
                foreach ($primary as $name => $col) {
                    $table->columns[] = $col;

                    $table->foreign($col->get('name'))->references($col->get('name'))->on($table_name)->onDelete('cascade');
                }

                foreach ($i18n_columns as $col) {
                    $table->columns[] = $col;
                }

                $table->string($this->i18n_code_field, 10);
                $table->primary(array_merge(array_keys($primary), [$this->i18n_code_field]));
            });
        }
    }
892400
function newQuery($connection)
    {

        $config = $this->config["connections"][$connection];

        $query = new Query($this->connections[$connection]);

        if (array_key_exists("index", $config) and $config["index"] != "") {
            $query->index($config["index"]);
        }

        return $query;
    }
172071
private function setPreferredCharsetCollation(Connection $connection)
    {
        // Let's get the currently configured connection charset and collation
        $connectionParams = $connection->getParams();
        $connectionCharset = isset($connectionParams['character_set']) ? $this->characterSetCollationResolver->normalizeCharacterSet($connectionParams['character_set']) : '';
        $connectionCollation = isset($connectionParams['collation']) ? $this->characterSetCollationResolver->normalizeCollation($connectionParams['collation']) : '';
        try {
            list($characterSet, $collation) = $this->characterSetCollationResolver->resolveCharacterSetAndCollation($connection);
        } catch (CharacterSetCollationException $x) {
            // Unsupported character set and/or collation
            return $connection;
        }
        if ($connectionCharset === $characterSet && $connectionCollation === $collation) {
            // No changes required
            return $connection;
        }

        return $this->reconfigureCharacterSetCollation($connection, $characterSet, $collation);
    }
45390
public function newFromBuilder($attributes = [], $connection = null)
    {
        // Create Instance
        $manager = app(OptionManager::class);
        $type = array_get((array) $attributes, 'type');
        $entity = $type ? $manager->findByNamespace($type) : null;
        $model = $entity ? $entity->newInstance([], true) : $this->newInstance([], true);

        $model->setRawAttributes((array) $attributes, true);
        $model->setConnection($connection ?: $this->getConnectionName());
        $model->fireModelEvent('retrieved', false);

        return $model;
    }
553276
public function newFromBuilder($attributes = array(), $connection = null) {
    $typeField = static::$singleTableTypeField;
    $attributes = (array) $attributes;

    $classType = array_key_exists($typeField, $attributes) ? $attributes[$typeField] : null;

    if ($classType !== null) {
      $childTypes = static::getSingleTableTypeMap();
      if (array_key_exists($classType, $childTypes)) {
        $class = $childTypes[$classType];
        $instance = (new $class)->newInstance([], true);
        $instance->setFilteredAttributes($attributes);
        $instance->setConnection($connection ?: $this->getConnectionName());
        $instance->fireModelEvent('retrieved', false);
        return $instance;
      } else {
        // Something has gone very wrong with the Global Scope
        // There is not graceful recovery so complain loudly.
        throw new SingleTableInheritanceException("Cannot construct newFromBuilder for unrecognized $typeField=$classType");
      }
    } else {
      // There are some cases, like Model::pluck('id'), where $attributes does not contain classType
      // In those situations defer to the original implementation.
      return parent::newFromBuilder($attributes, $connection);
    }
  }
562333
protected static function schemaBuilder($name = null)
    {
        /**
         * @var $db \Illuminate\Database\DatabaseManager
         */
        $db = static::$app['db'];

        $builder = $db->connection($name)->getSchemaBuilder();

        $builder->blueprintResolver(function ($table, $callback) {
            return new Blueprint($table, $callback);
        });

        return $builder;
    }
1238258
public static function table( $table, $connection = null )
	{
		return self::getInstance()->getConnection($connection)->table($table);
	}
1188766
public function newFromBuilder($attributes = array(), $connection = null)
    {
        $model = parent::newFromBuilder($attributes, $connection);
        $model->inspectJsonColumns();
        $model->addHintedAttributes();

        return $model;
    }
745734
public function createDoctrineDBALSchemaManager(\Doctrine\DBAL\Connection $connection)
    {

        $em_default = $this->getEntityManager();

        $em_new = \Doctrine\ORM\EntityManager::create($connection, $em_default->getConfiguration());

        $schemaManager = $em_new->getConnection()->getSchemaManager();

        return $schemaManager;
    }
624291
protected function prepare(Connection $connection)
	{
		$connection->setFetchMode($this->app['config']['database.fetch']);

		if ($this->app->bound('events'))
		{
			$connection->setEventDispatcher($this->app['events']);
		}

		// The database connection can also utilize a cache manager instance when cache
		// functionality is used on queries, which provides an expressive interface
		// to caching both fluent queries and FlyORM queries that are executed.
		$app = $this->app;

		$connection->setCacheManager(function() use ($app)
		{
			return $app['cache'];
		});

		// We will setup a Closure to resolve the paginator instance on the connection
		// since the Paginator isn't sued on every request and needs quite a few of
		// our dependencies. It'll be more efficient to lazily resolve instances.
		$connection->setPaginator(function() use ($app)
		{
			return $app['paginator'];
		});

		return $connection;
	}
538091
public function findByConnection($connection)
    {
        return $this->first(function ($client, $key) use ($connection) {
            return $client->connection === $connection;
        });
    }
734652
protected function getNewMySqlConnection(array $config, string $connection = null)
    {
        if ($connection && isset($config[$connection])) {
            $config = array_merge($config, $config[$connection]);
        }

        return ConnectorFactory::make(FW::version())->connect($config);
    }
792416
public function connectTo($schema) {
		$info = clone $this->getInfo();
		$info->setSchema($schema);
		return new DatabaseConnection($info);
	}