{"id":61485,"date":"2024-10-13T11:28:16","date_gmt":"2024-10-13T03:28:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/61485\/"},"modified":"2024-10-13T11:28:16","modified_gmt":"2024-10-13T03:28:16","slug":"google-gae-datastore%ef%bc%9a%e9%9b%b2%e8%a8%88%e7%ae%97%e4%b8%ad%e7%9a%84%e7%b5%90%e6%a7%8b%e5%8c%96%e6%95%b8%e6%93%9a","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/61485\/","title":{"rendered":"Google GAE Datastore\uff1a\u96f2\u8a08\u7b97\u4e2d\u7684\u7d50\u69cb\u5316\u6578\u64da"},"content":{"rendered":"<h1 id=\"google-gae-datastore%ef%bc%9a%e9%9b%b2%e8%a8%88%e7%ae%97%e4%b8%ad%e7%9a%84%e7%b5%90%e6%a7%8b%e5%8c%96%e6%95%b8%e6%93%9a-XnRwDbYDTh\">Google GAE Datastore\uff1a\u96f2\u8a08\u7b97\u4e2d\u7684\u7d50\u69cb\u5316\u6578\u64da<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u96f2\u8a08\u7b97\u6642\u4ee3\uff0c\u6578\u64da\u7684\u5b58\u5132\u548c\u7ba1\u7406\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u91cd\u8981\u3002Google App Engine\uff08GAE\uff09\u63d0\u4f9b\u7684Datastore\u662f\u4e00\u7a2e\u9ad8\u6548\u7684\u7d50\u69cb\u5316\u6578\u64da\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\uff0c\u9069\u5408\u5404\u7a2e\u61c9\u7528\u7a0b\u5e8f\u7684\u9700\u6c42\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0eGoogle GAE Datastore\u7684\u7279\u9ede\u3001\u512a\u52e2\u4ee5\u53ca\u4f7f\u7528\u793a\u4f8b\uff0c\u5e6b\u52a9\u8b80\u8005\u66f4\u597d\u5730\u7406\u89e3\u9019\u4e00\u6280\u8853\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afgoogle-gae-datastore%ef%bc%9f-XnRwDbYDTh\">\u4ec0\u9ebc\u662fGoogle GAE Datastore\uff1f<\/h2>\n<p>Google GAE Datastore\u662f\u4e00\u7a2eNoSQL\u6578\u64da\u5eab\uff0c\u5c08\u70ba\u96f2\u7aef\u61c9\u7528\u7a0b\u5e8f\u8a2d\u8a08\u3002\u5b83\u652f\u6301\u81ea\u52d5\u64f4\u5c55\uff0c\u80fd\u5920\u6839\u64da\u61c9\u7528\u7a0b\u5e8f\u7684\u9700\u6c42\u52d5\u614b\u8abf\u6574\u8cc7\u6e90\u3002Datastore\u7684\u6578\u64da\u6a21\u578b\u57fa\u65bc\u5be6\u9ad4\uff08Entity\uff09\u548c\u5c6c\u6027\uff08Property\uff09\uff0c\u9019\u4f7f\u5f97\u7528\u6236\u80fd\u5920\u9748\u6d3b\u5730\u5b58\u5132\u548c\u6aa2\u7d22\u6578\u64da\u3002<\/p>\n<h2 id=\"datastore%e7%9a%84%e4%b8%bb%e8%a6%81%e7%89%b9%e9%bb%9e-XnRwDbYDTh\">Datastore\u7684\u4e3b\u8981\u7279\u9ede<\/h2>\n<ul>\n<li><strong>\u81ea\u52d5\u64f4\u5c55\uff1a<\/strong>Datastore\u80fd\u5920\u6839\u64da\u6d41\u91cf\u81ea\u52d5\u64f4\u5c55\uff0c\u7121\u9700\u7528\u6236\u624b\u52d5\u5e72\u9810\u3002<\/li>\n<li><strong>\u9ad8\u53ef\u7528\u6027\uff1a<\/strong>Google\u7684\u57fa\u790e\u8a2d\u65bd\u78ba\u4fdd\u4e86\u6578\u64da\u7684\u9ad8\u53ef\u7528\u6027\u548c\u6301\u4e45\u6027\u3002<\/li>\n<li><strong>\u5f37\u5927\u7684\u67e5\u8a62\u529f\u80fd\uff1a<\/strong>\u652f\u6301\u8907\u96dc\u7684\u67e5\u8a62\uff0c\u5305\u62ec\u7be9\u9078\u3001\u6392\u5e8f\u548c\u5206\u9801\u3002<\/li>\n<li><strong>\u4e8b\u52d9\u652f\u6301\uff1a<\/strong>\u63d0\u4f9bACID\u4e8b\u52d9\u652f\u6301\uff0c\u78ba\u4fdd\u6578\u64da\u7684\u4e00\u81f4\u6027\u3002<\/li>\n<\/ul>\n<h2 id=\"datastore%e7%9a%84%e5%84%aa%e5%8b%a2-XnRwDbYDTh\">Datastore\u7684\u512a\u52e2<\/h2>\n<p>\u4f7f\u7528Google GAE Datastore\u7684\u512a\u52e2\u4e3b\u8981\u9ad4\u73fe\u5728\u4ee5\u4e0b\u5e7e\u500b\u65b9\u9762\uff1a<\/p>\n<ul>\n<li><strong>\u7c21\u5316\u7684\u6578\u64da\u7ba1\u7406\uff1a<\/strong>\u7528\u6236\u7121\u9700\u64d4\u5fc3\u5e95\u5c64\u7684\u786c\u4ef6\u548c\u57fa\u790e\u8a2d\u65bd\uff0cGoogle\u6703\u81ea\u52d5\u8655\u7406\u9019\u4e9b\u554f\u984c\u3002<\/li>\n<li><strong>\u9748\u6d3b\u7684\u6578\u64da\u6a21\u578b\uff1a<\/strong>\u7528\u6236\u53ef\u4ee5\u6839\u64da\u9700\u6c42\u81ea\u7531\u5b9a\u7fa9\u6578\u64da\u7d50\u69cb\uff0c\u7121\u9700\u9810\u5148\u8a2d\u8a08\u6578\u64da\u6a21\u5f0f\u3002<\/li>\n<li><strong>\u9ad8\u6548\u7684\u6027\u80fd\uff1a<\/strong>Datastore\u7684\u8a2d\u8a08\u4f7f\u5176\u80fd\u5920\u5feb\u901f\u8655\u7406\u5927\u91cf\u6578\u64da\u8acb\u6c42\uff0c\u9069\u5408\u9ad8\u6d41\u91cf\u61c9\u7528\u3002<\/li>\n<\/ul>\n<h2 id=\"%e4%bd%bf%e7%94%a8%e7%a4%ba%e4%be%8b-XnRwDbYDTh\">\u4f7f\u7528\u793a\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684Python\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528Google GAE Datastore\u4f86\u5b58\u5132\u548c\u6aa2\u7d22\u6578\u64da\uff1a<\/p>\n<pre><code>from google.cloud import datastore\n\n# \u5275\u5efaDatastore\u5ba2\u6236\u7aef\nclient = datastore.Client()\n\n# \u5275\u5efa\u4e00\u500b\u65b0\u7684\u5be6\u9ad4\ndef create_entity(name, age):\n    entity = datastore.Entity(client.key('Person'))\n    entity.update({\n        'name': name,\n        'age': age\n    })\n    client.put(entity)\n    return entity.key\n\n# \u67e5\u8a62\u5be6\u9ad4\ndef query_entities():\n    query = client.query(kind='Person')\n    results = list(query.fetch())\n    return results\n\n# \u4f7f\u7528\u793a\u4f8b\ncreate_entity('Alice', 30)\ncreate_entity('Bob', 25)\n\nfor person in query_entities():\n    print(person)\n<\/code><\/pre>\n<h2 id=\"%e7%b5%90%e8%ab%96-XnRwDbYDTh\">\u7d50\u8ad6<\/h2>\n<p>Google GAE Datastore\u4f5c\u70ba\u4e00\u7a2e\u5f37\u5927\u7684\u96f2\u7aef\u6578\u64da\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\uff0c\u70ba\u958b\u767c\u8005\u63d0\u4f9b\u4e86\u9748\u6d3b\u6027\u548c\u9ad8\u6548\u6027\u3002\u7121\u8ad6\u662f\u5c0f\u578b\u61c9\u7528\u9084\u662f\u5927\u578b\u7cfb\u7d71\uff0cDatastore\u90fd\u80fd\u5920\u6eff\u8db3\u5176\u6578\u64da\u5b58\u5132\u9700\u6c42\u3002\u96a8\u8457\u96f2\u8a08\u7b97\u6280\u8853\u7684\u767c\u5c55\uff0c\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\u5c07\u6210\u70ba\u4f01\u696d\u6210\u529f\u7684\u95dc\u9375\u3002<\/p>\n<p>\u5982\u679c\u60a8\u5c0d\u65bc\u96f2\u8a08\u7b97\u548c\u6578\u64da\u5b58\u5132\u6709\u9032\u4e00\u6b65\u7684\u9700\u6c42\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u670d\u52d9\uff0c\u9019\u5c07\u70ba\u60a8\u7684\u61c9\u7528\u63d0\u4f9b\u7a69\u5b9a\u7684\u57fa\u790e\u8a2d\u65bd\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22Google GAE Datastore\uff0c\u96f2\u8a08\u7b97\u4e2d\u7684\u7d50\u69cb\u5316\u6578\u64da\u89e3\u6c7a\u65b9\u6848\uff0c\u63d0\u4f9b\u9ad8\u6548\u3001\u53ef\u64f4\u5c55\u7684\u6578\u64da\u5b58\u5132\u8207\u7ba1\u7406\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-61485","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/61485","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"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=61485"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/61485\/revisions"}],"predecessor-version":[{"id":61486,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/61485\/revisions\/61486"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=61485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=61485"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=61485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}