/// Generate the DDL for the entire layout, i.e., all `create table`
/// and `create index` etc. statements needed in the database schema
///
/// See the unit tests at the end of this file for the actual DDL that
/// gets generated
Generate the DDL for the entire layout, i.e., all `create table`
and `create index` etc. statements needed in the database schema

See the unit tests at the end of this file for the actual DDL that
gets generated
Generate the DDL for the entire layout i . e . all ` create table ` and ` create index ` etc . statements needed in the database schema See the unit tests at the end of this file for the actual DDL that gets generated
pub fn as_ddl(&self) -> Result<String, fmt::Error> {
        let mut out = String::new();
        // Output enums first
        for (name, values) in &self.enums {
            let mut sep = "";
            let name = SqlName::from(name.as_str());
            write!(
                out,
                "create type {}.{}\n    as enum (",
                self.schema,
                name.quoted()
            )?;
            for value in values {
                write!(out, "{}'{}'", sep, value)?;
                sep = ", "
            }
            write!(out, ");\n")?;
        }
        // We sort tables here solely because the unit tests rely on
        // 'create table' statements appearing in a fixed order
        let mut tables = self.tables.values().collect::<Vec<_>>();
        tables.sort_by_key(|table| table.position);
        // Output 'create table' statements for all tables
        for table in tables {
            table.as_ddl(&mut out, self)?;
        }
        Ok(out)
    }
pub fn as_ddl ( & self ) -> Result < String , fmt :: Error > { let mut out = String :: new ( ) ; // Output enums first for ( name , values ) in & self . enums { let mut sep = " " ; let name = SqlName :: from ( name . as_str ( ) ) ; write ! ( out " \n " self schema name quoted ( ) ) ? ; for value in values { write ! ( out " " sep value ) ? ; sep = " " } write ! ( out " \n " ) ? ; } // We sort tables here solely because the unit tests rely on // 'create table' statements appearing in a fixed order let mut tables = self . tables . values ( ) . collect :: < Vec < _ > > ( ) ; tables . sort_by_key ( | table | table . position ) ; // Output 'create table' statements for all tables for table in tables { table . as_ddl ( & mut out , self ) ? ; } Ok ( out ) }
Generate the DDL for the entire layout, i.e., all `create table`
and `create index` etc.
Generate the DDL for the entire layout i . e . all ` create table ` and ` create index ` etc .
&self