src/RocknRoot/StrayFw/Database/Postgres/Mutation/AddTable.php
public static function statement(Database $database, array $schema, $mapping, $tableName, $modelName)
    {
        $tableDefinition = $schema[$modelName];
        if (isset($tableDefinition['fields']) === false) {
            throw new InvalidSchemaDefinition('model "' . $modelName . '" has no field');
        }
        $sql = 'CREATE TABLE ' . $tableName . ' (';
        $primary = array();
        foreach ($tableDefinition['fields'] as $fieldName => $fieldDefinition) {
            $fieldRealName = null;
            if (isset($fieldDefinition['name']) === true) {
                $fieldRealName = $fieldDefinition['name'];
            } else {
                $fieldRealName = Helper::codifyName($modelName) . '_' . Helper::codifyName($fieldName);
            }
            $sql .= Column::generateDefinition($schema, $mapping, $fieldRealName, $fieldDefinition);
            if (isset($fieldDefinition['primary']) === true && $fieldDefinition['primary'] === true) {
                $primary[] = $fieldRealName;
            }
            $sql .= ', ';
        }
        if (count($primary) > 0) {
            $sql .= 'CONSTRAINT pk_' . $tableName . ' PRIMARY KEY (' . implode(', ', $primary) . '), ';
        } else {
            Logger::get()->warning('table "' . $tableName . '" has no primary key');
        }
        $sql = substr($sql, 0, -2) . ')';
        $statement = $database->getMasterLink()->prepare($sql);

        return $statement;
    }
public static function statement(Database $database, array $schema, $mapping, $tableName, $modelName)
    {
        $tableDefinition = $schema[$modelName];
        if (isset($tableDefinition['fields']) === false) {
            throw new InvalidSchemaDefinition('model "' . $modelName . '" has no field');
        }
        $sql = 'CREATE TABLE ' . $tableName . ' (';
        $primary = array();
        foreach ($tableDefinition['fields'] as $fieldName => $fieldDefinition) {
            $fieldRealName = null;
            if (isset($fieldDefinition['name']) === true) {
                $fieldRealName = $fieldDefinition['name'];
            } else {
                $fieldRealName = Helper::codifyName($modelName) . '_' . Helper::codifyName($fieldName);
            }
            $sql .= Column::generateDefinition($schema, $mapping, $fieldRealName, $fieldDefinition);
            if (isset($fieldDefinition['primary']) === true && $fieldDefinition['primary'] === true) {
                $primary[] = $fieldRealName;
            }
            $sql .= ', ';
        }
        if (count($primary) > 0) {
            $sql .= 'CONSTRAINT pk_' . $tableName . ' PRIMARY KEY (' . implode(', ', $primary) . '), ';
        } else {
            Logger::get()->warning('table "' . $tableName . '" has no primary key');
        }
        $sql = substr($sql, 0, -2) . ')';
        $statement = $database->getMasterLink()->prepare($sql);

        return $statement;
    }
Prepare and return according PDO statement.

@throws InvalidSchemaDefinition if a model has no field
@param  Database                $database        database
@param  array                   $schema          schema definition
@param  string                  $mapping         mapping name
@param  string                  $tableName       table real name
@param  string                  $modelName       model name
@return \PDOStatement           $statement       prepared query