src/Builder/TypeTableBuilder.php
public function prepareCreateTableStatement(TypeInterface $type)
    {
        $result = [];

        $result[] = 'CREATE TABLE IF NOT EXISTS ' . $this->getConnection()->escapeTableName($type->getName()) . ' (';

        $generaterd_field_indexes = [];

        foreach ($type->getAllFields() as $field) {
            if ($field instanceof ScalarField) {
                $result[] = '    ' . $this->prepareFieldStatement($field) . ',';
            }

            if ($field instanceof JsonFieldInterface) {
                foreach ($field->getValueExtractors() as $value_extractor) {
                    $result[] = '    ' . $this->prepareGeneratedFieldStatement($field, $value_extractor) . ',';

                    if ($value_extractor->getAddIndex()) {
                        $generaterd_field_indexes[] = new Index($value_extractor->getFieldName());
                    }
                }
            }
        }

        $indexes = $type->getAllIndexes();

        if (!empty($generaterd_field_indexes)) {
            $indexes = array_merge($indexes, $generaterd_field_indexes);
        }

        foreach ($indexes as $index) {
            $result[] = '    ' . $this->prepareIndexStatement($index) . ',';
        }

        $last_line = count($result) - 1;
        $result[$last_line] = rtrim($result[$last_line], ',');

        $result[] = ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;';

        return implode("\n", $result);
    }
public function prepareCreateTableStatement(TypeInterface $type)
    {
        $result = [];

        $result[] = 'CREATE TABLE IF NOT EXISTS ' . $this->getConnection()->escapeTableName($type->getName()) . ' (';

        $generaterd_field_indexes = [];

        foreach ($type->getAllFields() as $field) {
            if ($field instanceof ScalarField) {
                $result[] = '    ' . $this->prepareFieldStatement($field) . ',';
            }

            if ($field instanceof JsonFieldInterface) {
                foreach ($field->getValueExtractors() as $value_extractor) {
                    $result[] = '    ' . $this->prepareGeneratedFieldStatement($field, $value_extractor) . ',';

                    if ($value_extractor->getAddIndex()) {
                        $generaterd_field_indexes[] = new Index($value_extractor->getFieldName());
                    }
                }
            }
        }

        $indexes = $type->getAllIndexes();

        if (!empty($generaterd_field_indexes)) {
            $indexes = array_merge($indexes, $generaterd_field_indexes);
        }

        foreach ($indexes as $index) {
            $result[] = '    ' . $this->prepareIndexStatement($index) . ',';
        }

        $last_line = count($result) - 1;
        $result[$last_line] = rtrim($result[$last_line], ',');

        $result[] = ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;';

        return implode("\n", $result);
    }
public function prepareCreateTableStatement ( TypeInterface $ type ) { $ result = [ ] ; $ result [ ] = 'CREATE TABLE IF NOT EXISTS ' . $ this -> getConnection ( ) -> escapeTableName ( $ type -> getName ( ) ) . ' (' ; $ generaterd_field_indexes = [ ] ; foreach ( $ type -> getAllFields ( ) as $ field ) { if ( $ field instanceof ScalarField ) { $ result [ ] = '    ' . $ this -> prepareFieldStatement ( $ field ) . ',' ; } if ( $ field instanceof JsonFieldInterface ) { foreach ( $ field -> getValueExtractors ( ) as $ value_extractor ) { $ result [ ] = '    ' . $ this -> prepareGeneratedFieldStatement ( $ field , $ value_extractor ) . ',' ; if ( $ value_extractor -> getAddIndex ( ) ) { $ generaterd_field_indexes [ ] = new Index ( $ value_extractor -> getFieldName ( ) ) ; } } } } $ indexes = $ type -> getAllIndexes ( ) ; if ( ! empty ( $ generaterd_field_indexes ) ) { $ indexes = array_merge ( $ indexes , $ generaterd_field_indexes ) ; } foreach ( $ indexes as $ index ) { $ result [ ] = '    ' . $ this -> prepareIndexStatement ( $ index ) . ',' ; } $ last_line = count ( $ result ) - 1 ; $ result [ $ last_line ] = rtrim ( $ result [ $ last_line ] , ',' ) ; $ result [ ] = ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;' ; return implode ( "\n" , $ result ) ; }
Prepare CREATE TABLE statement for the given type.

@param  TypeInterface $type
@return string
Prepare CREATE TABLE statement for the given type .