Retrieve the schema builder for the database connection. And set a custom blueprint resolver to return an
instance of the Culpa Blueprint class.

@param Connection $connection
@return \Illuminate\Database\Schema\Builder
484791
protected static function getSchemaBuilder(Connection $connection)
    {
        $schemaBuilder = $connection->getSchemaBuilder();
        $schemaBuilder->blueprintResolver(function ($table, $callback) {
            return new Blueprint($table, $callback);
        });

        return $schemaBuilder;
    }
166660
public static function fromConnection(Connection $connection, $table, array $types = [])
    {
        $name = $connection->getDriver()->getName();
        switch ($name) {
        case 'pdo_mysql':
            return new MysqlSelector($connection, $table, $types);
        case 'pdo_sqlite':
            return new SqliteSelector($connection, $table, $types);
        default:
            throw new DBALException("Unsupported database type: $name");
        }
    }
409773
public function getPresenceVerifierFor($connection)
    {
        return tap($this->getPresenceVerifier(), function ($verifier) use ($connection) {
            $verifier->setConnection($connection);
        });
    }
405481
protected function getLegacyDrupalVersion(Connection $connection)
    {
        // Don't assume because a table of that name exists, that it has the columns
        // we're querying. Catch exceptions and report that the source database is
        // not Drupal.

        // Druppal 5/6/7 can be detected by the schema_version in the system table.
        if ($connection->schema()->tableExists('system')) {
            try {
                $version_string = $connection->query('SELECT schema_version FROM {system} WHERE name = :module', [':module' => 'system'])
                    ->fetchField();
                if ($version_string && $version_string[0] == '1') {
                    if ((int) $version_string >= 1000) {
                        $version_string = '5';
                    } else {
                        $version_string = false;
                    }
                }
            } catch (\PDOException $e) {
                $version_string = false;
            }
        }
        // For Drupal 8 (and we're predicting beyond) the schema version is in the
        // key_value store.
        elseif ($connection->schema()->tableExists('key_value')) {
            $result = $connection->query("SELECT value FROM {key_value} WHERE collection = :system_schema  and name = :module", [':system_schema' => 'system.schema', ':module' => 'system'])->fetchField();
            $version_string = unserialize($result);
        } else {
            $version_string = false;
        }

        return $version_string ? substr($version_string, 0, 1) : false;
    }
964097
protected function getDatabaseVersion(Connection $db)
    {
        $driver = $db->getDriver();
        if (!$driver instanceof VersionAwarePlatformDriver) {
            return null;
        }
        $params = $db->getParams();
        if (isset($params['serverVersion'])) {
            $rawVersion = (string) $params['serverVersion'];
        } else {
            $connection = $db->getWrappedConnection();
            if (!$connection instanceof ServerInfoAwareConnection) {
                return null;
            }
            $rawVersion = (string) $connection->getServerVersion();
        }
        if (!preg_match('/^\d+\.\d+(?:\.\d+)?/', $rawVersion, $matches)) {
            return null;
        }

        return $matches[0];
    }
629327
protected function getConnection($connection = null)
    {
        $database = $this->app->make('db');

        $connection = $connection ?: $database->getDefaultConnection();

        return $database->connection($connection);
    }
1302866
protected function configure(Connection $connection, $type)
    {
        $connection = $this->setPdoForType($connection, $type);

        // First we'll set the fetch mode and a few other dependencies of the database
        // connection. This method basically just configures and prepares it to get
        // used by the application. Once we're finished we'll return it back out.
        if ($this->container->has('events')) {
            $connection->setEventDispatcher($this->container['events']);
        }

        // Here we'll set a reconnector callback. This reconnector can be any callable
        // so we will set a Closure to reconnect from this manager with the name of
        // the connection, which will allow us to reconnect from the connections.
        $connection->setReconnector(function ($connection) {
            $this->reconnect($connection->getName());
        });

        return $connection;
    }
196311
public function toCypher(ConnectionInterface $connection, IlluminateSchemaGrammar $grammar)
    {
        $statements = [];

        // Each type of command has a corresponding compiler function on the schema
        // grammar which is used to build the necessary SQL statements to build
        // the blueprint element, so we'll just call that compilers function.
        foreach ($this->commands as $command)
        {
            $method = 'compile'.ucfirst($command->name);

            if (method_exists($grammar, $method))
            {
                if ( ! is_null($cypher = $grammar->$method($this, $command, $connection)))
                {
                    $statements = array_merge($statements, (array) $cypher);
                }
            }
        }

        return $statements;
    }
236889
protected function updateConnection($connection)
    {
        if ($this->connection !== $connection) {
            $this->connection  = $connection;
            $this->schemaSetUp = false;
        }

        return $this;
    }
478033
public function queryBuilder($connection = null)
    {
        $key = $connection ?? $this->defaultConnection;

        if (!isset($this->queryBuilders[$key]))
        {
            $this->connection($key); // init connection
            $this->queryBuilders[$key] = new QueryBuilder($this->adapterProviders[$key]);
        }

        return $this->queryBuilders[$key];
    }
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;
    }
788487
public function setConnection(Connection $connection)
    {
        $this->connection = $connection;
        $this->prefix     = $this->connection->getConfig('prefix');

        return $this;
    }
836701
protected function createDatabaseSchema(Connection $connection, DatabaseSchemaInterface $schema): void
    {
        try {
            $this->createScopesTable($connection, $schema);
            $this->createClientsTable($connection, $schema);
            $this->createRedirectUrisTable($connection, $schema);
            $this->createTokensTable($connection, $schema);
            $this->createClientsScopesTable($connection, $schema);
            $this->createTokensScopesTable($connection, $schema);
        } catch (DBALException $exception) {
            if ($connection->isConnected() === true) {
                $this->removeDatabaseSchema($connection, $schema);
            }

            throw $exception;
        }
    }
77460
public function getExporter(?string $connection = null): AbstractExporter
    {
        $config = $this->config->extract('database');

        // Check is new or legacy
        if ($config->get('connections')) {
            $connection = $connection ?: $config->get('connection', 'local');

            $config = $config->extract('connections.' . $connection);
        }

        $driver = $config->get('driver', 'mysql');

        $class = 'Windwalker\Core\Database\Exporter\\' . ucfirst($driver) . 'Exporter';

        return $this->container->createSharedObject($class);
    }
1155205
public function build(Connection $connection, Grammar $grammar)
    {
        $statement = [
            'index' => $this->index,
            'type'  => $this->type,
            'body'  => [
                $this->type => [
                    '_source'    => [
                        'enabled' => true,
                    ],
                    'properties' => $this->toDSL($grammar),
                ],
            ],
        ];

        return $connection->mapStatement($statement);
    }
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;
    }
324709
private function loadPropertiesForTable($table, Connection $connection)
    {
        $columns = $connection->getSchemaManager()->listTableColumns($table);

        $props = [];

        foreach ($columns as $name => $column)
        {
            $processingType = $this->doctrineColumnToProcessingType($column);

            $props[$name] = [
                'processing_type' => $processingType,
                'doctrine_type' => $column->getType()->getName(),
            ];
        }

        return $props;
    }