{"id":43025,"date":"2024-12-01T10:14:46","date_gmt":"2024-12-01T02:14:46","guid":{"rendered":"https:\/\/fwq.ai\/blog\/43025\/"},"modified":"2024-12-01T10:14:46","modified_gmt":"2024-12-01T02:14:46","slug":"neo4j-go-driver-%e5%bc%ba%e5%88%b6%e4%b8%ad%e6%ad%a2%e9%95%bf%e6%97%b6%e9%97%b4%e8%bf%90%e8%a1%8c%e7%9a%84%e6%9f%a5%e8%af%a2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/43025\/","title":{"rendered":"neo4j-go-driver \u5f3a\u5236\u4e2d\u6b62\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u67e5\u8be2"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>neo4j-go-driver \u5f3a\u5236\u4e2d\u6b62\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u67e5\u8be2<\/span><\/p>\n<h1>neo4j-go-driver \u5f3a\u5236\u4e2d\u6b62\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u67e5\u8be2<\/h1>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-28 16:09:34<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u201c\u7eb5\u6709\u75be\u98ce\u6765\uff0c\u4eba\u751f\u4e0d\u8a00\u5f03\u201d\uff0c\u8fd9\u53e5\u8bdd\u9001\u7ed9\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u7684\u670b\u53cb\u4eec\uff0c\u4e5f\u5e0c\u671b\u5728\u9605\u8bfb\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aneo4j-go-driver \u5f3a\u5236\u4e2d\u6b62\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u67e5\u8be2\u300b<\/span>\u540e\uff0c\u80fd\u591f\u771f\u7684\u5e2e\u52a9\u5230\u5927\u5bb6\u3002\u6211\u4e5f\u4f1a\u5728\u540e\u7eed\u7684\u6587\u7ae0\u4e2d\uff0c\u9646\u7eed\u66f4\u65b0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u76f8\u5173\u7684\u6280\u672f\u6587\u7ae0\uff0c\u6709\u597d\u7684\u5efa\u8bae\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u7559\u8a00\uff0c\u975e\u5e38\u611f\u8c22\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u7684\u540e\u7aef\u5e94\u7528\u7a0b\u5e8f\u6709\u51e0\u4e2a neo4j Cypher \u67e5\u8be2\u3002\u5728\u6781\u5c11\u6570\u60c5\u51b5\u4e0b\uff0c\u5176\u4e2d\u4e00\u4e2a\u67e5\u8be2\u9700\u8981\u5f88\u957f\u65f6\u95f4\u624d\u80fd\u5b8c\u6210\uff08\u6211\u731c\u662f\u7531\u4e8e\u672a\u4f18\u5316\u7684\u67e5\u8be2\uff09\uff0c\u4e0d\u4ec5\u5982\u6b64\uff0c\u5b83\u8fd8\u5bfc\u81f4\u670d\u52a1\u5668\u8d44\u6e90\u4f7f\u7528\u91cf\u98d9\u5347\u3002<\/p>\n<p>\u6211\u76ee\u524d\u6b63\u5728\u4ece\u4e8bGo\u7f16\u7a0b\uff0c\u6211\u4f7f\u7528\u5b98\u65b9\u7684neo4j-go-driver\u3002<\/p>\n<p>\u6709\u4ec0\u4e48\u65b9\u6cd5\u53ef\u4ee5\u4f7f\u7528\u9a71\u52a8\u7a0b\u5e8f\u7ec8\u6b62\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u67e5\u8be2\u5417\uff1f\u4ece\u9a71\u52a8\u7a0b\u5e8f\u7684\u6587\u6863\u4e2d\u6211\u627e\u5230\u4e86\u8fd9\u4e2a API WithTxTimeout\u3002\u4f46\u662f\uff0c\u6211\u4e0d\u786e\u5b9a\u8be5 API \u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff0c\u5b83\u662f\u5426\u53ea\u662f\u8868\u9762\u4e0a\u5ffd\u7565\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u67e5\u8be2\uff0c\u8fd8\u662f\u5b9e\u9645\u4e0a\u7ec8\u6b62\u5b83\u3002<\/p>\n<p>\u786e\u5b9e\u9700\u8981\u5e2e\u52a9\u3002\u63d0\u524d\u81f4\u8c22\u3002<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u6211\u8ba4\u4e3a\u5b83\u5e94\u8be5\u7ec8\u6b62\u5b83\u3002 \u4ee3\u7801\u5e94\u5982\u4e0b\u6240\u793a\uff08\u6839\u636e\u67e5\u8be2\uff0c\u5c06 <code>readtransaction<\/code> \u66ff\u6362\u4e3a <code>writetransaction<\/code>\uff09\uff1a<\/p>\n<pre>query := \"match (n) return n\"\ntimeout := 30 * time.second\nresult, err := session.readtransaction(func(tx neo4j.transaction) (interface{}, error) {\n    result, err := tx.run(query, map[string]interface{}{})\n    \/\/ do something interesting\n}, neo4j.withtxtimeout(timeout))\n<\/pre>\n<p>\u60a8\u4e5f\u53ef\u4ee5\u5c06\u670d\u52a1\u5668\u7684\u4e8b\u52a1\u8d85\u65f6\u8bbe\u7f6e\u4e3a\u67d0\u4e2a\u503c\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u7981\u7528\uff1a<\/p>\n<pre>neo4j&gt; CALL dbms.setConfigValue('dbms.transaction.timeout', '360s') ;<\/pre>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aneo4j-go-driver \u5f3a\u5236\u4e2d\u6b62\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u67e5\u8be2\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &gt; &gt; neo4j-go-driver \u5f3a\u5236\u4e2d\u6b62\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u67e5\u8be2 neo4j-go-driver \u5f3a\u5236\u4e2d\u6b62\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u67e5\u8be2 \u6765\u6e90\uff1astackoverflow 2024-04-28 16:09:34 0\u6d4f\u89c8 \u6536\u85cf \u201c\u7eb5\u6709\u75be\u98ce\u6765\uff0c\u4eba\u751f\u4e0d\u8a00\u5f03\u201d\uff0c\u8fd9\u53e5\u8bdd\u9001\u7ed9\u6b63\u5728\u5b66\u4e60Golang\u7684\u670b\u53cb\u4eec\uff0c\u4e5f\u5e0c\u671b\u5728\u9605\u8bfb\u672c\u6587\u300aneo4j-go-driver \u5f3a\u5236\u4e2d\u6b62\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u67e5\u8be2\u300b\u540e\uff0c\u80fd\u591f\u771f\u7684\u5e2e\u52a9\u5230\u5927\u5bb6\u3002\u6211\u4e5f\u4f1a\u5728\u540e\u7eed\u7684\u6587\u7ae0\u4e2d\uff0c\u9646\u7eed\u66f4\u65b0Golang\u76f8\u5173\u7684\u6280\u672f\u6587\u7ae0\uff0c\u6709\u597d\u7684\u5efa\u8bae\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u7559\u8a00\uff0c\u975e\u5e38\u611f\u8c22\uff01 \u95ee\u9898\u5185\u5bb9 \u6211\u7684\u540e\u7aef\u5e94\u7528\u7a0b\u5e8f\u6709\u51e0\u4e2a neo4j Cypher \u67e5\u8be2\u3002\u5728\u6781\u5c11\u6570\u60c5\u51b5\u4e0b\uff0c\u5176\u4e2d\u4e00\u4e2a\u67e5\u8be2\u9700\u8981\u5f88\u957f\u65f6\u95f4\u624d\u80fd\u5b8c\u6210\uff08\u6211\u731c\u662f\u7531\u4e8e\u672a\u4f18\u5316\u7684\u67e5\u8be2\uff09\uff0c\u4e0d\u4ec5\u5982\u6b64\uff0c\u5b83\u8fd8\u5bfc\u81f4\u670d\u52a1\u5668\u8d44\u6e90\u4f7f\u7528\u91cf\u98d9\u5347\u3002 \u6211\u76ee\u524d\u6b63\u5728\u4ece\u4e8bGo\u7f16\u7a0b\uff0c\u6211\u4f7f\u7528\u5b98\u65b9\u7684neo4j-go-driver\u3002 \u6709\u4ec0\u4e48\u65b9\u6cd5\u53ef\u4ee5\u4f7f\u7528\u9a71\u52a8\u7a0b\u5e8f\u7ec8\u6b62\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u67e5\u8be2\u5417\uff1f\u4ece\u9a71\u52a8\u7a0b\u5e8f\u7684\u6587\u6863\u4e2d\u6211\u627e\u5230\u4e86\u8fd9\u4e2a API WithTxTimeout\u3002\u4f46\u662f\uff0c\u6211\u4e0d\u786e\u5b9a\u8be5 API \u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff0c\u5b83\u662f\u5426\u53ea\u662f\u8868\u9762\u4e0a\u5ffd\u7565\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u67e5\u8be2\uff0c\u8fd8\u662f\u5b9e\u9645\u4e0a\u7ec8\u6b62\u5b83\u3002 \u786e\u5b9e\u9700\u8981\u5e2e\u52a9\u3002\u63d0\u524d\u81f4\u8c22\u3002 \u89e3\u51b3\u65b9\u6848 \u6211\u8ba4\u4e3a\u5b83\u5e94\u8be5\u7ec8\u6b62\u5b83\u3002 \u4ee3\u7801\u5e94\u5982\u4e0b\u6240\u793a\uff08\u6839\u636e\u67e5\u8be2\uff0c\u5c06 readtransaction \u66ff\u6362\u4e3a writetransaction\uff09\uff1a query := &#8220;match (n) return n&#8221; timeout := 30 * time.second result, err := session.readtransaction(func(tx neo4j.transaction) (interface{}, error) { result, err [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-43025","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/43025","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=43025"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/43025\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=43025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=43025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=43025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}