Explorar o código

Merge remote-tracking branch 'origin/master'

22285461@qq.com hai 6 meses
pai
achega
9f7a5f6d70
Modificáronse 3 ficheiros con 30 adicións e 3 borrados
  1. 3 1
      .gitignore
  2. 9 1
      main.py
  3. 18 1
      model.py

+ 3 - 1
.gitignore

@@ -8,4 +8,6 @@
 /yixue.log
 /.idea/dataSources.xml
 /.idea/sqldialects.xml
-/.idea/vcs.xml
+/.idea/vcs.xml
+
+*.pyc

+ 9 - 1
main.py

@@ -220,7 +220,8 @@ async def getSiZhuInfo(request: SiZhuInfoRequest):
 @app.post("/api/customLogin")
 async def customLogin(request: CustomLogin):
     logging.info("login")
-    dt = CustomUser.select().where(CustomUser.user == request.user, CustomUser.psd == request.psd).first()
+    dt = CustomUser.select().where(CustomUser.user == request.user,
+                                   CustomUser.psd == request.psd).first()
 
     if dt is not None:
         return {"msg": "ok", "name": dt.name, "sexy": dt.sexy}
@@ -312,3 +313,10 @@ async def test(request: Request):
                 content["db"] = "broke , reconnect"
             logging.info("reconnect database")
     return JSONResponse(content=content, headers=headers)
+
+
+@app.get("/api/test2")
+async def test2():
+    users = UserInfo.select().where(UserInfo.customer != None)
+    users = [__build_user_object(dt) for dt in users]
+    return {"message": "Hello World", "users": users}

+ 18 - 1
model.py

@@ -1,3 +1,4 @@
+import logging
 from peewee import *
 from playhouse.pool import PooledMySQLDatabase
 
@@ -10,13 +11,29 @@ database = PooledMySQLDatabase('yixue',
                                stale_timeout=300, )
 
 
+def get_db():
+    db = PooledMySQLDatabase('yixue',
+                             user='yixue',
+                             password='Lai123',
+                             host='test.db.cxhy.cn',
+                             port=3306,
+                             max_connections=32,
+                             stale_timeout=300,
+                             timeout=10, )
+    logging.getLogger().setLevel(logging.INFO)
+    logging.info("get db")
+    print("get db 2222")
+
+    return db
+
+
 class UnknownField(object):
     def __init__(self, *_, **__): pass
 
 
 class BaseModel(Model):
     class Meta:
-        database = database
+        database = get_db()
 
 
 class AreaInfo(BaseModel):