def build_column_description(column: Dict[str, str], skip_identity=False, skip_references=False) -> str: """ Return the description of a table column suitable for a table creation. See build_columns. >>> build_column_description({"name": "key", "sql_type": "int", "not_null": True, "encoding": "raw"}) '"key" int ENCODE raw NOT NULL' >>> build_column_description({"name": "my_key", "sql_type": "int", "references": ["sch.ble", ["key"]]}) '"my_key" int REFERENCES "sch"."ble" ( "key" )' """ column_ddl = '"{name}" {sql_type}'.format(**column) if column.get("identity", False) and not skip_identity: column_ddl += " IDENTITY(1, 1)" if "encoding" in column: column_ddl += " ENCODE {}".format(column["encoding"]) if column.get("not_null", False): column_ddl += " NOT NULL" if "references" in column and not skip_references: [table_identifier, [foreign_column]] = column["references"] foreign_name = TableName.from_identifier(table_identifier) column_ddl += ' REFERENCES {} ( "{}" )'.format(foreign_name, foreign_column) return column_ddl
def dependencies(self) -> FrozenSet[TableName]: if self._dependencies is None: dependent_table_names = [ TableName.from_identifier(d) for d in self.table_design.get("depends_on", []) ] self._dependencies = frozenset(dependent_table_names) return self._dependencies