tianyun 3 rokov pred
rodič
commit
75a9bc8be3

+ 10 - 0
fastapi-demo/config/model_util.py

@@ -0,0 +1,10 @@
+def to_dict(model):
+    return {c.name: getattr(model, c.name, None) for c in model.__table__.columns}
+
+
+def to_list(models: list):
+    return [to_dict(model) for model in models]
+
+
+def to_str(model):
+    return str(to_dict(model))

+ 0 - 5
fastapi-demo/config/models.py

@@ -14,8 +14,3 @@ class DbKafka(Base):
     name = Column(String(200), nullable=False)
     json_str = Column(String(5000), nullable=False)
 
-    def to_dict(self):
-        return {c.name: getattr(self, c.name, None) for c in self.__table__.columns}
-
-    def __repr__(self):
-        return str(self.to_dict())

+ 1 - 0
fastapi-demo/config/sqlacodegen.sh

@@ -0,0 +1 @@
+sqlacodegen mysql+pymysql://root:password@127.0.0.1:3306/db_name > models.py