Esempio n. 1
0
def fetchModel(id):
    if request.method == "GET":
        with get_session_scope() as session:
            m = session.query(Model).get(id)
            return json.dumps({"success": True, "data": m.as_json(session)})
    if request.method == "PUT":
        with get_session_scope() as session:
            data = request.json
            m = session.query(Model).get(id)
            m.name = data.get("name")
            session.add(m)
            session.commit()
            return json.dumps({"success": True, "data": m.as_json(session)})
Esempio n. 2
0
def getModelList():
    with get_session_scope() as session:
        models = session.query(Model).all()
        rst = []
        for m in models:
            rst.append(m.as_json(session))

        return json.dumps({"success": True, "data": rst})
Esempio n. 3
0
def addModel():

    reqData = request.get_json()

    with get_session_scope() as session:

        model = Model()
        model.name = reqData.get("name", "null")
        session.add(model)
        session.commit()
        return json.dumps({"success": True})
Esempio n. 4
0
def buildCode(id):
    with get_session_scope() as session:
        m = session.query(Model).get(id)
        ginApi = CodeBuilder.buildGinApi(m)
        gormModel = CodeBuilder.buildGormModel(m)
        js = CodeBuilder.buildRestJs(m)
        data = {
            "ginApi": ginApi,
            "gormModel": gormModel,
            "js": js,
        }
        return json.dumps({"success": True, "data": data})
Esempio n. 5
0
def updateColumn(id):

    reqData = request.get_json()
    with get_session_scope() as session:
        col = session.query(SqlColumn).get(id)
        col.name = reqData.get("name", "")
        col.type = reqData.get("type", "")
        col.comment = reqData.get("comment", "")
        col.model_id = reqData.get("model_id", 0)
        session.add(col)
        session.commit()
        return json.dumps({"success": True, "data": col.as_json(session)})
Esempio n. 6
0
 def buildGormModel(cls, model):
     with get_session_scope() as session:
         cols = session.query(SqlColumn).filter(
             SqlColumn.model_id == model.id).all()
         template = env.get_template('gorm.temp')
         m = {
             "int": "int",
             "text": "string",
             "date": "time.Time",
         }
         for col in cols:
             col.name = col.name.capitalize()
             col.type = m.get(col.type, "string")
         rst = template.render(modelName='Abc', cols=cols)
         return rst
Esempio n. 7
0
 def buildRestJs(cls, model):
     with get_session_scope() as session:
         cols = session.query(SqlColumn).filter(
             SqlColumn.model_id == model.id).all()
         template = env.get_template('js.temp')
         m = {
             "int": "int",
             "text": "string",
             "date": "time.Time",
         }
         for col in cols:
             col.name = col.name.capitalize()
             col.type = m.get(col.type, "string")
         urlName = model.name.lower()
         objName = model.name[0].lower() + model.name[1:]
         rst = template.render(
             modelName=model.name,
             urlName=urlName,
             objName=objName,
         )
         return rst