Converts the database to the equivalent doctrine schema.

@param Database $database

@return Schema
359518
public function convertToDoctrineSchema(Database $database) : \Doctrine\DBAL\Schema\Schema
    {
        $schema = new Schema();

        foreach ($database->getTables() as $table) {
            $this->mapTable($schema, $table);
        }

        return $schema;
    }
428393
public function schema($schema = null)
    {
        if (func_num_args()) {
            $this->_schema = $schema;
            return $this;
        }
        if (!$this->_schema) {
            $this->_schema = static::definition();
        }
        return $this->_schema;
    }
303893
public static function describeTable(AdapterInterface $db, $table, $schema = null)
    {
        $columns = $db->describeColumns($table, $schema);
        $indexes = $db->describeIndexes($table, $schema);
        $references = $db->describeReferences($table, $schema);
        $options = $db->tableOptions($table, $schema);

        return new self([
            'name' => $table,
            'schema' => $schema,
            'columns' => array_map([Column::class, 'fromColumn'], $columns),
            'indexes' => array_map([Index::class, 'fromIndex'], $indexes),
            'references' => array_map([Reference::class, 'fromReference'], $references),
            'options' => $options,
        ]);
    }
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();
    }
525434
public function db($db = null)
    {
        if (is_null($db)) {
            return $this->dbName;
        } else {
            $this->dbName = $db;
        }
        return null;
    }
297697
public function getTableSchemas($database = 'base')
    {
        $driver = $this->getDatabase($database)->getDriver();
        $connection = $this->establishConnection($database, Database::TARGET_SLAVE);
        $names = $driver->getTableNames($connection);

        $schemas = [];
        foreach ($names as $name) {
            $schemas[] = $this->getTableSchema($name, $database);
        }

        return $schemas;
    }
1304265
public static function create($database = [])
    {
        try {
            $driver = isset($database['driver']) ? ucwords($database['driver']) : "";
            $className = __NAMESPACE__ . "\\Engines\\" . $driver;
            if (class_exists($className)) {
                return new $className($database);
            } else {
                throw new \RuntimeException("Unidentified connection engine $className.");
            }
        } catch (\PDOException $e) {
            throw new \RuntimeException('Problem connecting to the database: ' . $e->getMessage());
        }
    }
758264
public function setDb( string $db ) : SQLite
   {

      if ( ! $this->_supportedAttributes->get( 'db' )->validateValue( $db ) )
      {
         throw new ArgumentException( 'db', $db, 'Invalid database!' );
      }

      $this->_attributes[ 'db' ] = $db;

      return $this;

   }
33403
public function getTables($database=null)
    {
        if (is_null($this->tables)) {
            $sql    = !empty($database) ? 'SHOW TABLES FROM '.$database : 'SHOW TABLES';
            $this->query($sql);
            $result = $this->fetchAll();
            foreach ($result as $v) {
                $this->tables[] = array_values($v)[0];
            }
        }
        return $this->tables;
    }
601660
public function getBackupInstance($database = null)
	{
		$configuration = array_merge($this->getConfig('database'), $this->getConfig('backup::config'));
		$this->backupInstance = $this->backupFactory->build($configuration, $database);

		return $this->backupInstance;
	}
823242
public function connectDatabase($database = array())
    {
        $model = new BaseModel();
        if (isset($this->options['debugStatus']) && $this->options['debugStatus'] === TRUE) {
            $model->debugStatus = $this->options['debugStatus'];
            if (isset($this->options['debugLevel']) && !empty($this->options['debugLevel'])) {
                $model->debugLevel = $this->options['debugLevel'];
            }
            if (isset($this->options['loggerPath']) && !empty($this->options['loggerPath'])) {
                $model->debugLoggerPath = $this->options['loggerPath'];
            }
            $model->debugLoggerFilename = 'Log-' . date('Y-m-d') . '.log';
            $model->__construct();
        }
        $model->setDatabase($database);

        return $model;
    }
390545
public function createDatabase($database=null)
    {
        if (!$database) $database = $this->getDatabase();
        $sql = $this->getSchema()->getCreateDatabaseSql($database);
        return $this->query($sql);
    }
942047
public function toSql(\Doctrine\DBAL\Schema\SchemaDiff $schema)   //Doctrine\DBAL\Schema\SchemaDiff | \Doctrine\DBAL\Schema\Schema
    {
        return $schema->toSaveSql($this->getPlatform());
        //return $schema->toSql($this->getPlatform()); //it can return with DROP TABLE
    }
1135511
public function setDatabase($database)
    {
        if (!$this->_connection->select_db($database)) {
            throw new AnDatabaseException('Could not connect with database : '.$database);
        }

        $this->_database = $database;
        return $this;
    }
926690
public function getDatabase(string $connection = 'default'): Database
    {
        if (!isset($this->database[$connection])) {
            $this->database[$connection] = new Database($this->getConnection($connection));
        }

        return $this->database[$connection];
    }
190802
public function addDatabase($db)
    {
        if ($db instanceof Database) {
            $db->setAppData($this);
            if ($db->getPlatform() === null) {
                if ($config = $this->getGeneratorConfig()) {
                    $pf = $config->getConfiguredPlatform(null, $db->getName());
                    $db->setPlatform($pf ? $pf : $this->platform);
                } else {
                    $db->setPlatform($this->platform);
                }
            }
            $this->dbList[] = $db;

            return $db;
        } else {
            // XML attributes array / hash
            $d = new Database();
            $d->setAppData($this);
            $d->loadFromXML($db);

            return $this->addDatabase($d); // calls self w/ different param type
        }
    }
805952
private function resolveSchema($reference)
    {
        $schema = $reference;
        if (property_exists($reference, '$ref')) {
            $schemaResolver = $this->document->getSchemaResolver();
            $ref = new Reference($reference);
            $schema = $schemaResolver->resolveReference($ref)->getDocument();
        } elseif ($reference->type === 'array' && !empty($reference->items)) {
            $schema->items = $this->resolveSchema($reference->items);
        }

        // resolve properties
        if (!empty($schema->properties)) {
            $properties = (array) $schema->properties;
            foreach ($properties as $name => $property) {
                if (isset($property->type)
                    && $property->type === 'array'
                    && isset($property->items)
                    && property_exists($property->items, '$ref')
                    && !isset($schema->properties->$name->items)) {
                    $schema->properties->$name->items = $this->resolveSchema($property->items);
                } elseif (property_exists($property, '$ref') && !isset($schema->properties->$name)) {
                    $schema->properties->$name = $this->resolveSchema($property);
                }
            }
        }

        return $schema;
    }