{"id":6982,"date":"2024-11-14T09:32:59","date_gmt":"2024-11-14T01:32:59","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6982\/"},"modified":"2024-11-14T09:32:59","modified_gmt":"2024-11-14T01:32:59","slug":"node-mysql-sequelize-%e4%ba%8b%e5%8a%a1%e6%97%a0%e6%b3%95%e5%9b%9e%e6%bb%9a%ef%bc%9a%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3-myisam-%e5%ad%98%e5%82%a8%e5%bc%95%e6%93%8e%e9%97%ae%e9%a2%98%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6982\/","title":{"rendered":"Node MySQL Sequelize \u4e8b\u52a1\u65e0\u6cd5\u56de\u6eda\uff1a\u5982\u4f55\u89e3\u51b3 MyISAM \u5b58\u50a8\u5f15\u64ce\u95ee\u9898\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173024954984016.jpg\" class=\"aligncenter\" title=\"Node MySQL Sequelize \u4e8b\u52a1\u65e0\u6cd5\u56de\u6eda\uff1a\u5982\u4f55\u89e3\u51b3 MyISAM \u5b58\u50a8\u5f15\u64ce\u95ee\u9898\uff1f\u63d2\u56fe\" alt=\"Node MySQL Sequelize \u4e8b\u52a1\u65e0\u6cd5\u56de\u6eda\uff1a\u5982\u4f55\u89e3\u51b3 MyISAM \u5b58\u50a8\u5f15\u64ce\u95ee\u9898\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>node  sequelize \u65e0\u6cd5\u8fdb\u884c\u4e8b\u52a1\u56de\u6eda\u95ee\u9898\u89e3\u7b54<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 node mysql sequelize \u8fdb\u884c\u4e8b\u52a1\u5904\u7406\u65f6\uff0c\u9047\u5230\u65e0\u6cd5\u56de\u6eda\u7684\u60c5\u51b5\uff0c\u63d2\u5165\u7684\u8bb0\u5f55\u4ecd\u7136\u5b58\u5728\u3002\u5206\u6790\u4ee5\u4e0b\u914d\u7f6e\u548c\u4ee3\u7801\uff1a<\/p>\n<pre>\/\/ groups \u6a21\u578b\u5b9a\u4e49\nconst groups = sequelize.define('groups', { ... });\n\n\/\/ \u6a21\u578b\u8c03\u7528\u65b9\u6cd5\nvar groups = _groups(sequelize, datatypes);\n\n\/\/ \u63a5\u53e3\u5b9e\u73b0\nexports.creategroup = async function (user_id, name, img_url) {\n    \/\/ \u521b\u5efa\u4e8b\u52a1\n    const t = await sequelize.transaction();\n    try {\n        \/\/ \u521b\u5efa\u8bb0\u5f55\n        let result = await groups.create({\n            user_id: user_id,\n            name: name,\n            img_url: img_url\n        },{ transaction: t });\n        \/\/ \u5c1d\u8bd5\u56de\u6eda\n        await t.rollback();\n        console.log('\u56de\u6eda');\n        return func.resjsonsuccess(result, '\u5efa\u7fa4\u6210\u529f!');\n    } catch (error) {\n        return func.resjsonerror([], error.message);\n    }\n};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u95ee\u9898\u539f\u56e0\u5728\u4e8e mysql \u8868\u7684\u5b58\u50a8\u5f15\u64ce\u3002<strong>\u786e\u4fdd\u4f7f\u7528\u7684\u8868\u5b58\u50a8\u5f15\u64ce\u4e3a innodb<\/strong>\uff0c\u8be5\u5f15\u64ce\u652f\u6301\u4e8b\u52a1\u5904\u7406\uff0c\u800c myisam \u5219\u4e0d\u652f\u6301\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u6253\u5f00 mysql \u547d\u4ee4\u884c\u5de5\u5177\uff0c\u4f8b\u5982 mysql workbench\u3002<br \/>2.\u8fde\u63a5\u5230\u60a8\u7684\u6570\u636e\u5e93\u3002<br \/>3.\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u66f4\u6539\u8868\u5b58\u50a8\u5f15\u64ce\uff1a<\/li>\n<\/ol>\n<pre>ALTER TABLE groups ENGINE=InnoDB;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fNode MySQL Sequelize \u4e8b\u52a1\u65e0\u6cd5\u56de\u6eda\uff1a\u5982\u4f55\u89e3\u51b3 MyISAM \u5b58\u50a8\u5f15\u64ce\u95ee\u9898\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>node sequelize \u65e0\u6cd5\u8fdb\u884c\u4e8b\u52a1\u56de\u6eda\u95ee\u9898\u89e3\u7b54 \u5728\u4f7f\u7528 node mysql sequelize \u8fdb\u884c\u4e8b\u52a1\u5904\u7406\u65f6\uff0c\u9047\u5230\u65e0\u6cd5\u56de\u6eda\u7684\u60c5\u51b5\uff0c\u63d2\u5165\u7684\u8bb0\u5f55\u4ecd\u7136\u5b58\u5728\u3002\u5206\u6790\u4ee5\u4e0b\u914d\u7f6e\u548c\u4ee3\u7801\uff1a \/\/ groups \u6a21\u578b\u5b9a\u4e49 const groups = sequelize.define(&#8216;groups&#8217;, { &#8230; }); \/\/ \u6a21\u578b\u8c03\u7528\u65b9\u6cd5 var groups = _groups(sequelize, datatypes); \/\/ \u63a5\u53e3\u5b9e\u73b0 exports.creategroup = async function (user_id, name, img_url) { \/\/ \u521b\u5efa\u4e8b\u52a1 const t = await sequelize.transaction(); try { \/\/ \u521b\u5efa\u8bb0\u5f55 let result = await groups.create({ user_id: user_id, name: name, [&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-6982","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6982","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=6982"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6982\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6982"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6982"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6982"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}