main.py 533 B

123456789101112131415161718192021222324
  1. from enum import Enum
  2. from typing import Optional
  3. from fastapi import FastAPI, Query
  4. import dataset,json
  5. app = FastAPI()
  6. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/cmm_test?charset=utf8mb4')
  7. @app.get("/tags")
  8. async def get_tags():
  9. tag_dict = {}
  10. a=1
  11. table = db.load_table('tag_table')
  12. statement = 'SELECT id,name FROM tag_table'
  13. for row in db.query(statement):
  14. tag_dict[row['id']]=row['name']
  15. json_dump = json.dumps(tag_dict, ensure_ascii=False)
  16. return json_dump