def type_imports(self) -> List[Import]: column_type = self.column_type if isinstance(column_type, str): return [ Import(type_=Import.Type.LIBRARY, import_name=column_type, import_from="sqlalchemy") ] elif isinstance(column_type, Enum): if in_same_package(self, column_type): return [ Import( type_=Import.Type.LOCAL, import_name=self.message_field.type_obj.namespace. other[0].name, import_from=render_path( self.message_field.namespace.packages), ), Import(type_=Import.Type.LIBRARY, import_name="Enum", import_from="sqlalchemy"), ] else: return [ Import(type_=Import.Type.LOCAL, import_name=render_path( self.message_field.type_obj.namespace. packages)), Import(type_=Import.Type.LIBRARY, import_name="Enum", import_from="sqlalchemy"), ] elif isinstance(column_type, Message): if not self.is_relationship: return [] imports = [ Import(type_=Import.Type.LIBRARY, import_name="relationship", import_from="sqlalchemy.orm") ] if in_same_package(self, column_type): return imports else: imports.append( Import(type_=Import.Type.LOCAL, import_name=render_path( column_type.namespace.packages))) return imports else: return [ Import(type_=Import.Type.LOCAL, import_name=render_path( column_type.namespace.packages)) ]
def output_interface_string(self) -> str: interface = self.output_obj.interface # type: TypescriptMessageInterface if in_same_package(self, interface): return interface.root_class_name else: return render_path(interface.namespace + [interface.root_class_name])
def _source_type_string(self) -> str: if self.type in (self.Type.MESSAGE, self.type.ENUM): if in_same_package(self, self.type_obj): return self.type_obj.name else: return render_path(self.type_obj.full_namespace) else: return FIELDS_TYPES_MAP[self.type]
def type_string(self) -> str: column_type = self.column_type if isinstance(column_type, str): return "{}()".format(column_type) elif isinstance(column_type, Enum): if in_same_package(self, column_type): return "Enum({})".format( render_path(column_type.full_namespace.other)) else: return "Enum({})".format( render_path(column_type.full_namespace)) elif isinstance(column_type, Py3Model): return "" # TODO: fixme else: raise ValueError( "Unknown field `column_type`: {}".format(column_type))
def relationships_strings(self) -> List[str]: relationships = [] for field in self.fields.values(): # type: Py3Model.Field column_type = field.column_type if isinstance(column_type, Py3Model) and column_type.is_model: if in_same_package(self, column_type): relationships.append("{} = relationship('{}')".format( field.name, render_path(column_type.namespace.other + [column_type.class_name]))) else: relationships.append("{} = relationship('{}')".format( field.name, render_path(column_type.namespace + [column_type.class_name]))) # else: # raise ValueError("Relationship must be only with other model") return relationships
def output_type_string(self) -> str: obj = self.output_obj if in_same_package(self, obj): return render_path(obj.namespace.other + [obj.name]) else: return render_path(obj.namespace + [obj.name])
def get_from_current_class_name(self, current: TypescriptMessage): if in_same_package(self, current): return current.root_class_name else: return "{}.{}".format(render_path(self.namespace.packages), self.root_class_name)
def _get_enum_type_name(self): if in_same_package(self, self.type_obj): return self.type_obj.root_class_name else: return render_path(self.type_obj.namespace + [self.type_obj.root_class_name])
def output_string(self) -> str: if in_same_package(self, self.input_obj, exclude_root=True): return render_path(self.output_obj.full_namespace.other) else: return render_path(self.output_obj.full_namespace)