def model_inspection(mapper: Mapper, cls: DeclarativeMeta) -> None: name = cls.__tablename__ for col in cls.__table__.columns: model_properties[name].append(col.key) if col.type == PickleType and isinstance(col.default.arg, list): property_types[col.key] = "list" else: column_type = { Boolean: "bool", Integer: "int", Float: "float", JSON: "dict", PickleType: "dict", }.get(type(col.type), "str") if col.key not in property_types: property_types[col.key] = column_type if hasattr(cls, "parent_cls"): model_properties[name].extend(model_properties[cls.parent_cls]) if "Service" in name and name != "Service": model_properties[name].extend(model_properties["Service"]) model = {name: cls, name.lower(): cls} models.update(model) for relation in mapper.relationships: if getattr(relation.mapper.class_, "private", False): continue property = str(relation).split(".")[1] relationships[name][property] = { "model": relation.mapper.class_.__tablename__, "list": relation.uselist, }
def model_inspection(mapper, model): name = model.__tablename__ for col in inspect(model).columns: if not col.info.get("model_properties", True): continue model_properties[name].append(col.key) if col.type == PickleType and isinstance( col.default.arg, list): property_types[col.key] = "list" else: column_type = { Boolean: "bool", Integer: "int", Float: "float", JSON: "dict", PickleType: "dict", }.get(type(col.type), "str") if col.key not in property_types: property_types[col.key] = column_type for descriptor in inspect(model).all_orm_descriptors: if descriptor.extension_type is ASSOCIATION_PROXY: property = ( descriptor.info.get("name") or f"{descriptor.target_collection}_{descriptor.value_attr}" ) model_properties[name].append(property) if hasattr(model, "parent_type"): model_properties[name].extend( model_properties[model.parent_type]) if "service" in name and name != "service": model_properties[name].extend(model_properties["service"]) models.update({name: model, name.lower(): model}) model_properties[name].extend(model.model_properties) model_properties[name] = list(set(model_properties[name])) for relation in mapper.relationships: if getattr(relation.mapper.class_, "private", False): continue property = str(relation).split(".")[1] relationships[name][property] = { "model": relation.mapper.class_.__tablename__, "list": relation.uselist, }