{"id":25493,"date":"2024-11-24T09:12:32","date_gmt":"2024-11-24T01:12:32","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25493\/"},"modified":"2024-11-24T09:12:32","modified_gmt":"2024-11-24T01:12:32","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-python-%e7%9a%84-uvicorn-fastapi-peewee-pymysql-%e7%8e%af%e5%a2%83%e4%b8%ad%e5%ae%9e%e7%8e%b0-sql-%e6%9f%a5%e8%af%a2%e8%b6%85%e6%97%b6%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25493\/","title":{"rendered":"\u5982\u4f55\u5728 Python \u7684 uvicorn + fastapi + peewee + pymysql \u73af\u5883\u4e2d\u5b9e\u73b0 SQL \u67e5\u8be2\u8d85\u65f6\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173062244279520.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728 Python \u7684 uvicorn + fastapi + peewee + pymysql \u73af\u5883\u4e2d\u5b9e\u73b0 SQL \u67e5\u8be2\u8d85\u65f6\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728 Python \u7684 uvicorn + fastapi + peewee + pymysql \u73af\u5883\u4e2d\u5b9e\u73b0 SQL \u67e5\u8be2\u8d85\u65f6\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728  \u4e2d\u5b9e\u73b0\u5ba2\u6237\u7aef sql \u67e5\u8be2\u8d85\u65f6<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 orm\uff08\u5bf9\u8c61\u5173\u7cfb\u6620\u5c04\u5668\uff09\u6216\u9a71\u52a8\u5e93\u65f6\uff0c\u786e\u4fdd sql \u67e5\u8be2\u5728\u6307\u5b9a\u65f6\u95f4\u8303\u56f4\u5185\u5b8c\u6210\u975e\u5e38\u91cd\u8981\u3002\u4e3a\u4e86\u9632\u6b62\u53ef\u80fd\u7684\u5b89\u5168\u6f0f\u6d1e\uff0c\u9700\u8981\u5bf9\u67e5\u8be2\u8bbe\u7f6e\u65f6\u95f4\u4e0a\u9650\u3002<\/p>\n<p>\u5b9e\u73b0\u8fd9\u4e00\u76ee\u7684\u7684\u4f18\u96c5\u89e3\u51b3\u65b9\u6848\u662f\u4f7f\u7528\u4ee5\u4e0b py \u53c2\u6570\uff1a<\/p>\n<ul>\n<li> <strong>&#8220;connection_timeout&#8221;:<\/strong> \u8fde\u63a5\u5efa\u7acb\u7684\u8d85\u65f6\u65f6\u95f4\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09\u3002<\/li>\n<li> <strong>&#8220;read_timeout&#8221;:<\/strong> \u4ece\u8fde\u63a5\u8bfb\u53d6\u6570\u636e\u7684\u8d85\u65f6\u65f6\u95f4\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09\u3002<\/li>\n<li> <strong>&#8220;write_timeout&#8221;:<\/strong> \u5411\u8fde\u63a5\u5199\u5165\u6570\u636e\u7684\u8d85\u65f6\u65f6\u95f4\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff0c\u8981\u5728 uvicorn + fastapi + peewee + pymysql \u73af\u5883\u4e2d\u5c06 sql \u67e5\u8be2\u8d85\u65f6\u8bbe\u7f6e\u4e3a 60 \u79d2\uff0c\u53ef\u4ee5\u4fee\u6539\u8fde\u63a5\u53c2\u6570\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>from peewee import MySQLDatabase\n\ndb = MySQLDatabase(...)\n\ndb.connect(\n    connection_timeout=60,\n    read_timeout=60,\n    write_timeout=60,\n)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8bbe\u7f6e\u8fd9\u4e9b\u53c2\u6570\u540e\uff0c\u4efb\u4f55 sql \u67e5\u8be2\u90fd\u5c06\u53d7\u5230\u6307\u5b9a\u8d85\u65f6\u65f6\u95f4\u7684\u9650\u5236\u3002\u8d85\u8fc7\u6b64\u65f6\u95f4\u9650\u5236\u7684\u67e5\u8be2\u5c06\u5f15\u53d1\u5f02\u5e38\u3002<\/p>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u65e2\u4f18\u96c5\u53c8\u6709\u6548\u5730\u5b9e\u73b0\u4e86 sql \u67e5\u8be2\u8d85\u65f6\uff0c\u800c\u65e0\u9700\u4fee\u6539 mysql \u670d\u52a1\u5668\u8bbe\u7f6e\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728 Python \u7684 uvicorn + fastapi + peewee + py \u73af\u5883\u4e2d\u5b9e\u73b0 SQL \u67e5\u8be2\u8d85\u65f6\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728 \u4e2d\u5b9e\u73b0\u5ba2\u6237\u7aef sql \u67e5\u8be2\u8d85\u65f6 \u5728\u4f7f\u7528 orm\uff08\u5bf9\u8c61\u5173\u7cfb\u6620\u5c04\u5668\uff09\u6216\u9a71\u52a8\u5e93\u65f6\uff0c\u786e\u4fdd sql \u67e5\u8be2\u5728\u6307\u5b9a\u65f6\u95f4\u8303\u56f4\u5185\u5b8c\u6210\u975e\u5e38\u91cd\u8981\u3002\u4e3a\u4e86\u9632\u6b62\u53ef\u80fd\u7684\u5b89\u5168\u6f0f\u6d1e\uff0c\u9700\u8981\u5bf9\u67e5\u8be2\u8bbe\u7f6e\u65f6\u95f4\u4e0a\u9650\u3002 \u5b9e\u73b0\u8fd9\u4e00\u76ee\u7684\u7684\u4f18\u96c5\u89e3\u51b3\u65b9\u6848\u662f\u4f7f\u7528\u4ee5\u4e0b py \u53c2\u6570\uff1a &#8220;connection_timeout&#8221;: \u8fde\u63a5\u5efa\u7acb\u7684\u8d85\u65f6\u65f6\u95f4\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09\u3002 &#8220;read_timeout&#8221;: \u4ece\u8fde\u63a5\u8bfb\u53d6\u6570\u636e\u7684\u8d85\u65f6\u65f6\u95f4\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09\u3002 &#8220;write_timeout&#8221;: \u5411\u8fde\u63a5\u5199\u5165\u6570\u636e\u7684\u8d85\u65f6\u65f6\u95f4\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09\u3002 \u4f8b\u5982\uff0c\u8981\u5728 uvicorn + fastapi + peewee + pymysql \u73af\u5883\u4e2d\u5c06 sql \u67e5\u8be2\u8d85\u65f6\u8bbe\u7f6e\u4e3a 60 \u79d2\uff0c\u53ef\u4ee5\u4fee\u6539\u8fde\u63a5\u53c2\u6570\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b from peewee import MySQLDatabase db = MySQLDatabase(&#8230;) db.connect( connection_timeout=60, read_timeout=60, write_timeout=60, ) \u767b\u5f55\u540e\u590d\u5236 \u8bbe\u7f6e\u8fd9\u4e9b\u53c2\u6570\u540e\uff0c\u4efb\u4f55 sql \u67e5\u8be2\u90fd\u5c06\u53d7\u5230\u6307\u5b9a\u8d85\u65f6\u65f6\u95f4\u7684\u9650\u5236\u3002\u8d85\u8fc7\u6b64\u65f6\u95f4\u9650\u5236\u7684\u67e5\u8be2\u5c06\u5f15\u53d1\u5f02\u5e38\u3002 \u8fd9\u79cd\u65b9\u6cd5\u65e2\u4f18\u96c5\u53c8\u6709\u6548\u5730\u5b9e\u73b0\u4e86 sql \u67e5\u8be2\u8d85\u65f6\uff0c\u800c\u65e0\u9700\u4fee\u6539 mysql \u670d\u52a1\u5668\u8bbe\u7f6e\u3002 \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728 Python \u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-25493","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25493","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=25493"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25493\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}