public static function fromArray(array $config)
    {
        if (!isset($config['engine'])) {
            throw new \InvalidArgumentException("Missing engine: must be either 'mysql' or 'sqlite'");
        }

        if (!in_array(strtolower($config['engine']), ['sqlite', 'mysql'])) {
            throw new \InvalidArgumentException("Unsupported engine {$config['engine']}");
        }

        if ($config['engine'] === 'sqlite') {
            return static::sqlite(
                $config['file'],
                $config['options'] ?? []
            );
        }

        if ($config['engine'] === 'mysql') {
            return static::mysql(
                $config['host'],
                $config['name'],
                $config['user'] ?? null,
                $config['pass'] ?? null,
                $config['options'] ?? []
            );
        }

        return null;
    }