{"id":97000,"date":"2024-10-20T14:09:17","date_gmt":"2024-10-20T06:09:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/97000\/"},"modified":"2024-10-20T14:09:18","modified_gmt":"2024-10-20T06:09:18","slug":"python%e7%9a%84orm%e6%a1%86%e6%9e%b6sqlobject-1-1-3%e7%99%bc%e5%b8%83","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/97000\/","title":{"rendered":"Python\u7684ORM\u6846\u67b6SQLObject 1.1.3\u767c\u5e03"},"content":{"rendered":"<h1 id=\"python%e7%9a%84orm%e6%a1%86%e6%9e%b6sqlobject-1-1-3%e7%99%bc%e5%b8%83-wToIxwkCQx\">Python\u7684ORM\u6846\u67b6SQLObject 1.1.3\u767c\u5e03<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u8edf\u9ad4\u958b\u767c\u4e2d\uff0c\u5c0d\u65bc\u6578\u64da\u5eab\u7684\u64cd\u4f5c\u5f80\u5f80\u9700\u8981\u4e00\u500b\u9ad8\u6548\u4e14\u6613\u65bc\u4f7f\u7528\u7684\u5de5\u5177\u3002Python\u7684ORM\uff08\u5c0d\u8c61\u95dc\u806f\u6620\u5c04\uff09\u6846\u67b6SQLObject\u6b63\u662f\u9019\u6a23\u4e00\u500b\u5de5\u5177\u3002\u6700\u8fd1\uff0cSQLObject 1.1.3\u7248\u672c\u7684\u767c\u5e03\u5f15\u8d77\u4e86\u958b\u767c\u8005\u7684\u5ee3\u6cdb\u95dc\u6ce8\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e\u9019\u4e00\u7248\u672c\u7684\u4e3b\u8981\u7279\u6027\u53ca\u5176\u5c0d\u958b\u767c\u8005\u7684\u5f71\u97ff\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afsqlobject%ef%bc%9f-wToIxwkCQx\">\u4ec0\u9ebc\u662fSQLObject\uff1f<\/h2>\n<p>SQLObject\u662f\u4e00\u500b\u7528\u65bcPython\u7684ORM\u6846\u67b6\uff0c\u65e8\u5728\u7c21\u5316\u6578\u64da\u5eab\u64cd\u4f5c\u3002\u5b83\u5141\u8a31\u958b\u767c\u8005\u4f7f\u7528Python\u5c0d\u8c61\u4f86\u8868\u793a\u6578\u64da\u5eab\u4e2d\u7684\u8868\uff0c\u4e26\u901a\u904e\u5c0d\u8c61\u7684\u65b9\u6cd5\u4f86\u9032\u884c\u6578\u64da\u7684\u589e\u522a\u6539\u67e5\u3002\u9019\u7a2e\u65b9\u5f0f\u4e0d\u50c5\u63d0\u9ad8\u4e86\u958b\u767c\u6548\u7387\uff0c\u9084\u4f7f\u4ee3\u78bc\u66f4\u52a0\u6613\u65bc\u7dad\u8b77\u3002<\/p>\n<h2 id=\"sqlobject-1-1-3%e7%9a%84%e4%b8%bb%e8%a6%81%e7%89%b9%e6%80%a7-wToIxwkCQx\">SQLObject 1.1.3\u7684\u4e3b\u8981\u7279\u6027<\/h2>\n<p>SQLObject 1.1.3\u7248\u672c\u7684\u767c\u5e03\u5e36\u4f86\u4e86\u4e00\u4e9b\u91cd\u8981\u7684\u6539\u9032\u548c\u65b0\u7279\u6027\uff0c\u4ee5\u4e0b\u662f\u5e7e\u500b\u503c\u5f97\u6ce8\u610f\u7684\u65b9\u9762\uff1a<\/p>\n<ul>\n<li><strong>\u6027\u80fd\u512a\u5316\uff1a<\/strong>\u65b0\u7248\u672c\u5c0d\u67e5\u8a62\u6027\u80fd\u9032\u884c\u4e86\u512a\u5316\uff0c\u7279\u5225\u662f\u5728\u8655\u7406\u5927\u91cf\u6578\u64da\u6642\uff0c\u80fd\u986f\u8457\u63d0\u9ad8\u67e5\u8a62\u901f\u5ea6\u3002<\/li>\n<li><strong>\u652f\u6301Python 3\uff1a<\/strong>\u96a8\u8457Python 3\u7684\u666e\u53ca\uff0cSQLObject 1.1.3\u7248\u672c\u5b8c\u5168\u652f\u6301Python 3\uff0c\u9019\u4f7f\u5f97\u958b\u767c\u8005\u80fd\u5920\u5229\u7528Python 3\u7684\u65b0\u7279\u6027\u3002<\/li>\n<li><strong>\u6539\u9032\u7684\u6587\u6a94\uff1a<\/strong>\u65b0\u7248\u672c\u7684\u6587\u6a94\u66f4\u52a0\u8a73\u7d30\uff0c\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u793a\u4f8b\u548c\u4f7f\u7528\u6307\u5357\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u5feb\u4e0a\u624b\u3002<\/li>\n<li><strong>\u932f\u8aa4\u4fee\u5fa9\uff1a<\/strong>\u4fee\u5fa9\u4e86\u591a\u500b\u5df2\u77e5\u7684bug\uff0c\u63d0\u5347\u4e86\u7a69\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8sqlobject-1-1-3-wToIxwkCQx\">\u5982\u4f55\u4f7f\u7528SQLObject 1.1.3<\/h2>\n<p>\u4f7f\u7528SQLObject\u9032\u884c\u6578\u64da\u5eab\u64cd\u4f5c\u76f8\u5c0d\u7c21\u55ae\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u57fa\u672c\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528SQLObject\u4f86\u5275\u5efa\u4e00\u500b\u6578\u64da\u8868\u4e26\u9032\u884c\u57fa\u672c\u7684\u64cd\u4f5c\uff1a<\/p>\n<pre><code>from sqlobject import *\n\n# \u9023\u63a5\u5230\u6578\u64da\u5eab\nsqlhub.processConnection = connectionForURI('sqlite:\/:memory:')\n\n# \u5b9a\u7fa9\u4e00\u500b\u6578\u64da\u8868\nclass Person(SQLObject):\n    name = StringCol()\n    age = IntCol()\n\n# \u5275\u5efa\u6578\u64da\u8868\nPerson.createTable()\n\n# \u63d2\u5165\u6578\u64da\nperson = Person(name='Alice', age=30)\n\n# \u67e5\u8a62\u6578\u64da\nfor p in Person.select():\n    print(p.name, p.age)\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u9996\u5148\u9023\u63a5\u5230\u4e00\u500bSQLite\u6578\u64da\u5eab\uff0c\u7136\u5f8c\u5b9a\u7fa9\u4e86\u4e00\u500b\u540d\u70ba`Person`\u7684\u6578\u64da\u8868\uff0c\u4e26\u63d2\u5165\u4e86\u4e00\u689d\u6578\u64da\u3002\u6700\u5f8c\uff0c\u6211\u5011\u67e5\u8a62\u4e26\u6253\u5370\u51fa\u6240\u6709\u7684\u6578\u64da\u3002<\/p>\n<h2 id=\"sqlobject%e7%9a%84%e5%84%aa%e5%8b%a2-wToIxwkCQx\">SQLObject\u7684\u512a\u52e2<\/h2>\n<p>\u4f7f\u7528SQLObject\u7684\u4e3b\u8981\u512a\u52e2\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u7c21\u5316\u6578\u64da\u5eab\u64cd\u4f5c\uff1a<\/strong>\u958b\u767c\u8005\u53ef\u4ee5\u901a\u904e\u5c0d\u8c61\u64cd\u4f5c\u4f86\u9032\u884c\u6578\u64da\u5eab\u64cd\u4f5c\uff0c\u7121\u9700\u7de8\u5beb\u7e41\u7463\u7684SQL\u8a9e\u53e5\u3002<\/li>\n<li><strong>\u63d0\u9ad8\u4ee3\u78bc\u53ef\u8b80\u6027\uff1a<\/strong>\u4f7f\u7528Python\u5c0d\u8c61\u4f7f\u4ee3\u78bc\u66f4\u52a0\u76f4\u89c0\uff0c\u6613\u65bc\u7406\u89e3\u548c\u7dad\u8b77\u3002<\/li>\n<li><strong>\u8de8\u6578\u64da\u5eab\u652f\u6301\uff1a<\/strong>SQLObject\u652f\u6301\u591a\u7a2e\u6578\u64da\u5eab\uff0c\u5305\u62ecSQLite\u3001MySQL\u548cPostgreSQL\u7b49\uff0c\u65b9\u4fbf\u958b\u767c\u8005\u6839\u64da\u9700\u6c42\u9078\u64c7\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-wToIxwkCQx\">\u7e3d\u7d50<\/h2>\n<p>SQLObject 1.1.3\u7684\u767c\u5e03\u70baPython\u958b\u767c\u8005\u63d0\u4f9b\u4e86\u4e00\u500b\u66f4\u5f37\u5927\u548c\u9ad8\u6548\u7684ORM\u5de5\u5177\u3002\u96a8\u8457\u6027\u80fd\u7684\u63d0\u5347\u548c\u5c0dPython 3\u7684\u652f\u6301\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u8f15\u9b06\u5730\u9032\u884c\u6578\u64da\u5eab\u64cd\u4f5c\uff0c\u5f9e\u800c\u5c08\u6ce8\u65bc\u696d\u52d9\u908f\u8f2f\u7684\u5be6\u73fe\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u7a69\u5b9a\u7684<code><a href=\"https:\/\/server.hk\">VPS<\/a><\/code>\u89e3\u6c7a\u65b9\u6848\u4f86\u90e8\u7f72\u60a8\u7684\u61c9\u7528\uff0cServer.HK\u63d0\u4f9b\u4e86\u591a\u7a2e\u9078\u64c7\uff0c\u5305\u62ec<code><a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a><\/code>\u548c<code><a href=\"https:\/\/server.hk\">\u4e91\u670d\u52a1\u5668<\/a><\/code>\uff0c\u4ee5\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22Python\u7684ORM\u6846\u67b6SQLObject 1.1.3\u7684\u6700\u65b0\u767c\u5e03\uff0c\u63d0\u5347\u6578\u64da\u5eab\u64cd\u4f5c\u6548\u7387\uff0c\u7c21\u5316\u958b\u767c\u6d41\u7a0b\uff0c\u589e\u5f37\u529f\u80fd\u8207\u7a69\u5b9a\u6027\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-97000","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/97000","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=97000"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/97000\/revisions"}],"predecessor-version":[{"id":97001,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/97000\/revisions\/97001"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=97000"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=97000"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=97000"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}