/// Generate the DDL for one table, i.e. one `create table` statement
/// and all `create index` statements for the table's columns
///
/// See the unit tests at the end of this file for the actual DDL that
/// gets generated
Generate the DDL for one table, i.e. one `create table` statement
and all `create index` statements for the table's columns

See the unit tests at the end of this file for the actual DDL that
gets generated
Generate the DDL for one table i . e . one ` create table ` statement and all ` create index ` statements for the table ' s columns See the unit tests at the end of this file for the actual DDL that gets generated
fn as_ddl(&self, out: &mut String, layout: &Layout) -> fmt::Result {
        write!(
            out,
            "create table {}.{} (\n",
            layout.schema,
            self.name.quoted()
        )?;
        for column in self.columns.iter() {
            write!(out, "    ")?;
            column.as_ddl(out)?;
            write!(out, ",\n")?;
        }
        // Add block_range column and constraint
        write!(
            out,
            "\n        {vid}                  bigserial primary key,\
             \n        {block_range}          int4range not null,
        exclude using gist   (id with =, {block_range} with &&)\n);\n",
            vid = VID_COLUMN,
            block_range = BLOCK_RANGE_COLUMN
        )?;
        // Create indexes. Skip columns whose type is an array of enum,
        // since there is no good way to index them with Postgres 9.6.
        // Once we move to Postgres 11, we can enable that
        // (tracked in graph-node issue #1330)
        for (i, column) in self
            .columns
            .iter()
            .filter(|col| !(col.is_list() && col.is_enum()))
            .enumerate()
        {
            // Attributes that are plain strings are indexed with a BTree; but
            // they can be too large for Postgres' limit on values that can go
            // into a BTree. For those attributes, only index the first
            // STRING_PREFIX_SIZE characters
            let index_expr = if column.is_text() {
                format!("left({}, {})", column.name.quoted(), STRING_PREFIX_SIZE)
            } else {
                column.name.quoted()
            };
            let method = if column.is_list() { "gin" } else { "btree" };
            write!(
                out,
                "create index attr_{table_index}_{column_index}_{table_name}_{column_name}\n    on {schema_name}.\"{table_name}\" using {method}({index_expr});\n",
                table_index = self.position,
                table_name = self.name,
                column_index = i,
                column_name = column.name,
                schema_name = layout.schema,
                method = method,
                index_expr = index_expr,
            )?;
        }
        write!(out, "\n")
    }
fn as_ddl ( & self , out : & mut String , layout : & Layout ) -> fmt :: Result { write ! ( out " \n " layout schema self name quoted ( ) ) ? ; for column in self . columns . iter ( ) { write ! ( out " " ) ? ; column . as_ddl ( out ) ? ; write ! ( out " \n " ) ? ; } // Add block_range column and constraint write ! ( out " \n \
 \n \n \n " vid VID_COLUMN block_range BLOCK_RANGE_COLUMN ) ? ; // Create indexes. Skip columns whose type is an array of enum, // since there is no good way to index them with Postgres 9.6. // Once we move to Postgres 11, we can enable that // (tracked in graph-node issue #1330) for ( i , column ) in self . columns . iter ( ) . filter ( | col | ! ( col . is_list ( ) && col . is_enum ( ) ) ) . enumerate ( ) { // Attributes that are plain strings are indexed with a BTree; but // they can be too large for Postgres' limit on values that can go // into a BTree. For those attributes, only index the first // STRING_PREFIX_SIZE characters let index_expr = if column . is_text ( ) { format ! ( " " column name quoted ( ) STRING_PREFIX_SIZE ) } else { column . name . quoted ( ) } ; let method = if column . is_list ( ) { " " } else { " " } ; write ! ( out " \n \" \" \n " table_index self position table_name self name column_index i column_name column name schema_name layout schema method method index_expr index_expr ) ? ; } write ! ( out " \n " ) }
Generate the DDL for one table, i.e.
Generate the DDL for one table i . e .
&self
out
&mut String
layout
&Layout