{"id":43168,"date":"2024-12-01T11:05:26","date_gmt":"2024-12-01T03:05:26","guid":{"rendered":"https:\/\/fwq.ai\/blog\/43168\/"},"modified":"2024-12-01T11:05:26","modified_gmt":"2024-12-01T03:05:26","slug":"%e6%88%91%e5%8f%af%e4%bb%a5%e7%94%a8%e4%bb%80%e4%b9%88%e6%9d%a5%e4%bb%a3%e6%9b%bf-db-where","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/43168\/","title":{"rendered":"\u6211\u53ef\u4ee5\u7528\u4ec0\u4e48\u6765\u4ee3\u66ff DB.Where"},"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>\u6211\u53ef\u4ee5\u7528\u4ec0\u4e48\u6765\u4ee3\u66ff DB.Where<\/span><\/p>\n<h1>\u6211\u53ef\u4ee5\u7528\u4ec0\u4e48\u6765\u4ee3\u66ff DB.Where<\/h1>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-30 11:36:31<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5927\u5bb6\u597d\uff0c\u6211\u4eec\u53c8\u89c1\u9762\u4e86\u554a~\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u6211\u53ef\u4ee5\u7528\u4ec0\u4e48\u6765\u4ee3\u66ff DB.Where\u300b<\/span>\u7684\u5185\u5bb9\u4e2d\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u3002\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u76f8\u5173\u77e5\u8bc6\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\uff0c\u4ee5\u540e\u4f1a\u7ed9\u5927\u5bb6\u5e26\u6765\u66f4\u591a<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u76f8\u5173\u6587\u7ae0\uff0c\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u8fdb\u6b65\uff01\u4e0b\u9762\u5c31\u5f00\u59cb\u672c\u6587\u7684\u6b63\u5f0f\u5185\u5bb9~<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u5728 gorm \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 <code>db.where<\/code> \u4ece\u6570\u636e\u5e93\u4e2d\u68c0\u67e5\u7528\u6237\u7684\u6570\u636e\u4ee5\u8fdb\u884c\u8eab\u4efd\u200b\u200b\u9a8c\u8bc1\u3002\u4f46\u6211\u5fc5\u987b\u4f7f\u7528 go fiber\uff0c\u6240\u4ee5\u6211\u53ef\u4ee5\u4f7f\u7528\u4ec0\u4e48\u6765\u4ee3\u66ff <code>db.where<\/code> \u6765\u68c0\u67e5\u7528\u6237\u662f\u5426\u5b58\u5728\u4e8e\u6570\u636e\u5e93\u4e2d\u3002<\/p>\n<pre>var user models.User    \ndatabase.DB.Where(\"id = ?\", claims.Issuer).(&amp;user)<\/pre>\n<p> <\/p>\n<h2>\u6b63\u786e\u7b54\u6848<\/h2>\n<p> <\/p>\n<p>\u55ef\uff0c\u6839\u636e\u4f60\u7684\u95ee\u9898\uff0cgorm \u65e2\u4f5c\u4e3a\u6570\u636e\u5e93\u4e5f\u4f5c\u4e3a\u6846\u67b6\u5de5\u4f5c\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5\u4f7f\u7528go fiber\u4f5c\u4e3a\u6846\u67b6\uff0c\u4f46\u662f\u5982\u679c\u4f60\u60f3\u4f7f\u7528\u6570\u636e\u5e93\uff0c\u4f60\u4e0d\u80fd\u4f7f\u7528\u6765\u81eafibre\u7684\u6570\u636e\u5e93\uff0c\u800c\u662f\u5fc5\u987b\u4f7f\u7528\u4e00\u4e2a\u6570\u636e\u5e93\uff0c\u4f60\u53ef\u4ee5\u4ece\u4e2d\u627e\u5230\u6570\u636e\u5e93\u4e2d\u6570\u636e\u7684\u96c6\u5408\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u60a8\u5c06 mongodb \u4e0e gofiber \u4e00\u8d77\u4f7f\u7528\uff0c\u56e0\u6b64\u5b83\u5c06\u4f7f\u7528 <code>db.collection.findone()<\/code> \u7684\u65b9\u6cd5<\/p>\n<p>\u5728\u8868\u5355db.where\u4e2d\u7528\u4e8e\u67e5\u627e\u6570\u636e\u5e93\u96c6\u5408<\/p>\n<pre>Well, as per your question gorm is working as a database also as a framework.\n\nyou can use go fiber as a framework but if you want to use the database you cannot use the database from fiber instead you have to use a database from which you can find the collection of the data in the database.\n\nFor example, you are using MongoDB with GoFiber so it will use the method of DB.Collection.FindOne()\n\nIn form Db.Where is used to find the database collection<\/pre>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8eGolang\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &gt; &gt; \u6211\u53ef\u4ee5\u7528\u4ec0\u4e48\u6765\u4ee3\u66ff DB.Where \u6211\u53ef\u4ee5\u7528\u4ec0\u4e48\u6765\u4ee3\u66ff DB.Where \u6765\u6e90\uff1astackoverflow 2024-04-30 11:36:31 0\u6d4f\u89c8 \u6536\u85cf \u5927\u5bb6\u597d\uff0c\u6211\u4eec\u53c8\u89c1\u9762\u4e86\u554a~\u672c\u6587\u300a\u6211\u53ef\u4ee5\u7528\u4ec0\u4e48\u6765\u4ee3\u66ff DB.Where\u300b\u7684\u5185\u5bb9\u4e2d\u5c06\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\u3002\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60Golang\u76f8\u5173\u77e5\u8bc6\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\uff0c\u4ee5\u540e\u4f1a\u7ed9\u5927\u5bb6\u5e26\u6765\u66f4\u591aGolang\u76f8\u5173\u6587\u7ae0\uff0c\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u8fdb\u6b65\uff01\u4e0b\u9762\u5c31\u5f00\u59cb\u672c\u6587\u7684\u6b63\u5f0f\u5185\u5bb9~ \u95ee\u9898\u5185\u5bb9 \u5728 gorm \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 db.where \u4ece\u6570\u636e\u5e93\u4e2d\u68c0\u67e5\u7528\u6237\u7684\u6570\u636e\u4ee5\u8fdb\u884c\u8eab\u4efd\u200b\u200b\u9a8c\u8bc1\u3002\u4f46\u6211\u5fc5\u987b\u4f7f\u7528 go fiber\uff0c\u6240\u4ee5\u6211\u53ef\u4ee5\u4f7f\u7528\u4ec0\u4e48\u6765\u4ee3\u66ff db.where \u6765\u68c0\u67e5\u7528\u6237\u662f\u5426\u5b58\u5728\u4e8e\u6570\u636e\u5e93\u4e2d\u3002 var user models.User database.DB.Where(&#8220;id = ?&#8221;, claims.Issuer).(&amp;user) \u6b63\u786e\u7b54\u6848 \u55ef\uff0c\u6839\u636e\u4f60\u7684\u95ee\u9898\uff0cgorm \u65e2\u4f5c\u4e3a\u6570\u636e\u5e93\u4e5f\u4f5c\u4e3a\u6846\u67b6\u5de5\u4f5c\u3002 \u4f60\u53ef\u4ee5\u4f7f\u7528go fiber\u4f5c\u4e3a\u6846\u67b6\uff0c\u4f46\u662f\u5982\u679c\u4f60\u60f3\u4f7f\u7528\u6570\u636e\u5e93\uff0c\u4f60\u4e0d\u80fd\u4f7f\u7528\u6765\u81eafibre\u7684\u6570\u636e\u5e93\uff0c\u800c\u662f\u5fc5\u987b\u4f7f\u7528\u4e00\u4e2a\u6570\u636e\u5e93\uff0c\u4f60\u53ef\u4ee5\u4ece\u4e2d\u627e\u5230\u6570\u636e\u5e93\u4e2d\u6570\u636e\u7684\u96c6\u5408\u3002 \u4f8b\u5982\uff0c\u60a8\u5c06 mongodb \u4e0e gofiber \u4e00\u8d77\u4f7f\u7528\uff0c\u56e0\u6b64\u5b83\u5c06\u4f7f\u7528 db.collection.findone() \u7684\u65b9\u6cd5 \u5728\u8868\u5355db.where\u4e2d\u7528\u4e8e\u67e5\u627e\u6570\u636e\u5e93\u96c6\u5408 Well, as per your question gorm is working as [&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-43168","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/43168","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=43168"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/43168\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=43168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=43168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=43168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}