Formats a string containing the fully-qualified path to represent
a table resource.

@param string $project
@param string $instance
@param string $table

@return string The formatted table resource.
@experimental
358386
public static function tableName($project, $instance, $table)
    {
        return self::getTableNameTemplate()->render([
            'project' => $project,
            'instance' => $instance,
            'table' => $table,
        ]);
    }
1327118
public function render(TableStructure $table, int $indent = 8): string
    {
        return str_repeat(' ', $indent)
            . "\$this->addPrimaryKey('"
            . ($this->name ?: self::GENERIC_PRIMARY_KEY)
            . "', '"
            . $table->renderName()
            . "', ['"
            . implode("', '", $this->columns)
            . "']);";
    }
1201980
public function getCreateTable(string $table): string
	{
		return (string) $this->context->query('SHOW CREATE TABLE ' . $table)->fetch()->{'Create Table'};
	}
402830
public function render(TableStructure $table, int $indent = 12): string
    {
        return str_repeat(' ', $indent) . "'{$this->name}' => " . $this->renderDefinition($table) . ',';
    }
1257401
public static function sessionName($project, $instance, $database, $session)
    {
        return self::getSessionNameTemplate()->render([
            'project' => $project,
            'instance' => $instance,
            'database' => $database,
            'session' => $session,
        ]);
    }
967849
@Deprecated
  public static final String formatDatasetName(String project, String dataset) {
    return DATASET_PATH_TEMPLATE.instantiate(
        "project", project,
        "dataset", dataset);
  }
306842
def database_path(cls, project, instance, database):
        """"""
        return google.api_core.path_template.expand(
            "projects/{project}/instances/{instance}/databases/{database}",
            project=project,
            instance=instance,
            database=database,
        )
697815
protected function makeTable($table): ?Table
    {
        // 如果是字符串,那么应该是表名,创建表对象
        if (is_string($table)) {
            return table($table);
        }

        // 如果已经是表对象,返回
        if ($table instanceof Table) {
            return $table;
        }

        return null;
    }
1055311
public function table($table = '', $tablePrefix = null)
    {
        $hasAlias = is_array($table) ? true : false;
        is_null($tablePrefix) && $tablePrefix = $this->tablePrefix;
        $tableName = $tablePrefix . ($hasAlias ? key($table) : $table);

        $this->table[count($this->table) . '_' . $tableName] = $hasAlias ? current($table) : null;
        return $this;
    }
115163
public function prefixTables($table, bool $use_identifier = false)
    {
        if ($table instanceof \Closure || is_resource($table)) {
            throw new \InvalidArgumentException(
                "Invalid value to be quote, table value could not be instance of `Closure` or as a `Resource`",
                E_USER_ERROR
            );
        }

        $prefix = $this->getTablePrefix();
        if (is_array($table)) {
            foreach ($table as $key => $value) {
                $table[$key] = $this->prefixTables($value, $use_identifier);
            }
            return $table;
        }
        if (is_object($table)) {
            foreach (get_object_vars($table) as $key => $value) {
                $table->{$key} = $this->prefixTables($value, $use_identifier);
            }
            return $table;
        }
        if (!is_string($table)) {
            return null;
        }
        if (strpos($table, $this->currentQuoteIdentifier) !== false) {
            $use_identifier = true;
        }
        if (!empty($prefix) && is_string($prefix) && trim($prefix)) {
            $tableArray = explode('.', $table);
            $tableArray    = $this->trimTableSelector($tableArray);
            if (count($tableArray) > 1) {
                $connectionParams = $this->getConnectionParams();
                if (isset($connectionParams['dbname']) && $tableArray[0] == $connectionParams['dbname']) {
                    $tableArray[1] = $this->prefixTableCallback($tableArray);
                }
                if ($use_identifier) {
                    return $this->currentQuoteIdentifier
                           . implode("{$this->currentQuoteIdentifier}.{$this->currentQuoteIdentifier}", $tableArray)
                           . $this->currentQuoteIdentifier;
                } else {
                    return implode(".", $tableArray);
                }
            } else {
                $table = $this->prefixTableCallback($tableArray[0]);
            }
        }

        return $use_identifier
            ? $this->currentQuoteIdentifier.$table.$this->currentQuoteIdentifier
            : $table;
    }
435282
public static function prettifyTableName($table, $prefix = '')
    {
        if ($prefix) {
            $table = self::removePrefix($table, $prefix);
        }

        return self::underscoresToCamelCase($table, true);
    }
1154331
public function table_simple_name(string $table, bool $escaped = false): ?string
  {
    if ( $table = trim($table) ){
      $bits = explode('.', str_replace($this->qte, '', $table));
      switch ( \count($bits) ){
        case 1:
          $table = $bits[0];
          break;
        case 2:
          $table = $bits[1];
          break;
        case 3:
          $table = $bits[1];
          break;
      }
      if ( bbn\str::check_name($table) ){
        return $escaped ? $this->qte.$table.$this->qte : $table;
      }
    }
		return null;
  }
1172732
protected function prefixTable($table, bool $escape = true): string {
        if ($table instanceof Identifier) {
            return $escape ? $table->escape($this) : (string)$table;
        } else {
            $table = $this->px.$table;
            return $escape ? $this->escape($table) : $table;
        }
    }
64767
private function setTemplate($instance)
    {
        // we don't know what is the template extension, so we need to match by action name
        if (!empty($this->getModule()) && $instance->app()->view()->getAutoload()) {
            $templateDir = Bootstrap::getInstance()
                                    ->getEnvironment()
                                    ->getApplicationAbsolutePath() . 'App/Modules/' . $this->getModule() . '/Views/' . $this->getController();

            if (!is_dir($templateDir)) {
                return false;
            }

            $templates = scandir($templateDir);
            if ($templates) {
                $tplFilename = '';

                $tplActionName = $this->str($this->getAction())->charFirstUpper()->val();

                foreach ($templates as $tpl) {
                    if (strpos($tpl, $tplActionName . '.') !== false) {
                        $tplFilename = $tpl;
                        break;
                    }
                }

                if ($tplFilename != '') {
                    $instance->app()
                             ->view()
                             ->setTemplate('../Modules/' . $this->getModule() . '/Views/' . $this->getController() . '/' . $tplFilename);

                    return true;
                }
            }
        }
    }
325570
private function getInstanceCode(Instance $instance) : Code
    {
        $node = ($this->normalizer)($instance->value);

        return new Code(new Node\Stmt\Return_($node), false);
    }
658852
public function toQueryString(string $key, bool $pretty = true, bool $isSub = false): ?string
    {
        if ($this->table == null) {
            throw new BuilderException(
                "Table is not defined yet! Call 'setTable()' to set target table first.");
        }

        $s = ''; $n = $t = $nt = ''; $ns = ' ';
        $isSub = $isSub ?: $this->isSub;
        // $isSub = $pretty = false;
        if ($pretty) {
            $s = "\t"; $n = "\n"; $t = "\t"; $nt = $n . $t; $ns = $n;
            if ($isSub) {
                $ns = $nt . $t; $t = $t . $t;
            }
        }

        $ret = '';
        switch ($key) {
            case 'select':
                $select = $pretty ? $n . $t . join((', '. $n . $t), $this->query['select'])
                    : join(', ', $this->query['select']);

                $ret = sprintf("SELECT %s%s {$n}{$t}FROM %s",
                    $select,
                    $this->toQueryString('aggregate', $pretty),
                    $this->toQueryString('from', $pretty)
                );

                $ret = trim(
                    $ret
                    . $this->toQueryString('join', $pretty)
                    . $this->toQueryString('where', $pretty)
                    . $this->toQueryString('groupBy', $pretty)
                    . $this->toQueryString('having', $pretty)
                    . $this->toQueryString('orderBy', $pretty)
                    . $this->toQueryString('limit', $pretty)
                );
                break;
            case 'from':
                if (isset($this->query['from'])) {
                    $from = $this->query['from'];
                    if ($pretty) {
                        $tmp = explode("\n", $from);
                        $tmp = array_map(function ($line) use ($t) {
                            if ($line = trim($line)) {
                                $line = ctype_upper($line[0]) || $line[0] == ')'
                                    ? $t . $t . $line : $t . $t . $t . $line;
                            }
                            return $line;
                        }, $tmp);
                        $from = implode("\n", $tmp);
                        $from = preg_split('~^\s*\((.+)\)+\s*(?:AS\s+(.+))~s', $from, 2, 3);
                        $from = '('. $nt . $t . $from[0] . $nt .') AS '. $from[1];
                    } else {
                        $from = preg_replace('~\s+~', ' ', $from);
                    }
                    $ret = $from;
                } else {
                    $ret = $this->table;
                }
                break;
            case 'insert':
                if (isset($this->query['insert'])) {
                    $data = $this->query['insert'];

                    $keys = $this->agent->escapeIdentifier(array_keys($data[0]));
                    $values = [];
                    foreach ($data as $dat) {
                        $values[] = '('. $this->agent->escape(array_values($dat)) .')';
                    }

                    $ret = "INSERT INTO {$this->table} {$nt}({$keys}) {$nt}VALUES ".
                        join(', ', $values);
                }
                break;
            case 'update':
                if (isset($this->query['update'])) {
                    $data = $this->query['update'];

                    $set = [];
                    foreach ($data as $key => $value) {
                        $set[] = $this->agent->escapeIdentifier($key) .' = '. $this->agent->escape($value);
                    }

                    $ret = trim(
                        "UPDATE {$this->table} SET {$nt}". join(', ', $set)
                        . $this->toQueryString('where', $pretty)
                        . $this->toQueryString('orderBy', $pretty)
                        . $this->toQueryString('limit', $pretty)
                    );
                }
                break;
            case 'delete':
                if (isset($this->query['delete'])) {
                    $ret = trim(
                        "DELETE FROM {$this->table}"
                        . $this->toQueryString('where', $pretty)
                        . $this->toQueryString('orderBy', $pretty)
                        . $this->toQueryString('limit', $pretty)
                    );
                }
                break;
            case 'where':
                if (isset($this->query['where'])) {
                    $wheres = $this->query['where'];
                    if (count($wheres) == 1) {
                        $ret = $ns . 'WHERE ('. ($pretty ? $ns . $s . $wheres[0][0] . $ns : $wheres[0][0]) .')';
                    } else {
                        $ws = []; $wsp = 0;
                        foreach ($wheres as $i => $where) {
                            [$where, $op] = $where;
                            $nx = $wheres[$i + 1] ?? null;
                            $nxn = isset($wheres[$i + 2]);
                            $nxOp = strtoupper($nx[1] ?? '');
                            $ws[] = $where;
                            if ($nx) {
                                $ws[] = $op;
                            }
                            if ($op != $nxOp && $nxOp && $nxn) {
                                $ws[] = '(';
                                $wsp++;
                            }
                        }

                        $ret = preg_replace('~ (OR|AND) \( +(["`])?~i', ' \1 (\2', join(' ', $ws)); // :(
                        $ret = $ret . str_repeat(')', $wsp); // close parentheses
                        if ($isSub) {
                            $n = $n . $t; $nt = $n . $s;
                        }
                        $ret = $ns . 'WHERE ('. $nt . $ret . $n . ')';
                    }
                }
                break;
            case 'groupBy':
                if (isset($this->query['groupBy'])) {
                    $ret = $ns .'GROUP BY '. join(', ', $this->query['groupBy']);
                }
                break;
            case 'orderBy':
                if (isset($this->query['orderBy'])) {
                    $ret = $ns .'ORDER BY '. join(', ', $this->query['orderBy']);
                }
                break;
            case 'limit':
                if (isset($this->query['limit'])) {
                    $ret = isset($this->query['limit'][1])
                        ? $ns .'LIMIT '. $this->query['limit'][0] .' OFFSET '. $this->query['limit'][1]
                        : $ns .'LIMIT '. $this->query['limit'][0];
                }
                break;
            case 'join':
                if (isset($this->query['join'])) {
                    $ret = '';
                    foreach ($this->query['join'] as $join) {
                        $ret .= $ns . $join;
                    }
                }
                break;
            case 'having':
                if (isset($this->query['having'])) {
                    $ret = $ns .'HAVING ('. join(' ', $this->query['having']). ')';
                }
                break;
            case 'aggregate':
                if (isset($this->query['aggregate'])) {
                    $ret = ', '. join(', ', $this->query['aggregate']);
                }
                break;
            default:
                throw new BuilderException("Unknown key '{$key}' given");
        }

        return $ret ?: null;
    }
669567
public function getMigrationPath($table, $field = null)
    {
        $name = is_null($field) ?
            $this->getTableMigrationName($table) :
            $this->getTableFieldMigrationName($field, $table);

        return sprintf(
            $this->getBasePath() . '/%s.php',
            $name);
    }