public static function getDatabaseConfig($database)
    {
        $cached = self::$cache[$database] ?? null;
        if ($cached !== null) {
            return $cached;
        }

        if (self::$config === null) {
            throw new \BadMethodCallException('Config was not loaded');
        }
        if (!array_key_exists($database, self::$config['databases'])) {
            throw new \LogicException("Unknown database '$database'");
        }

        $data = self::$config['databases'][$database];
        if (is_string($data)) {
            $data = ['database_name' => $data];
        }

        $server = $data['server'] ?? 'default';
        $servers = self::$config['servers'] ?? [];
        if (array_key_exists($server, $servers)) {
            unset($data['server']);
            $data = array_merge($servers[$server], $data);
        }

        self::$cache[$database] = $data;
        return $data;
    }