{"id":233,"date":"2015-02-19T15:03:46","date_gmt":"2015-02-19T06:03:46","guid":{"rendered":"http:\/\/tech.at-iroha.jp\/?p=233"},"modified":"2015-06-19T14:36:51","modified_gmt":"2015-06-19T05:36:51","slug":"nw-js-%e3%81%a7-sqlite","status":"publish","type":"post","link":"https:\/\/tech.at-iroha.jp\/?p=233","title":{"rendered":"NW.js \u3067 SQLite \u3092\u5229\u7528\u3059\u308b\u306b\u306f"},"content":{"rendered":"<p>SQLite \u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30d5\u30a1\u30a4\u30eb\u3078\u306e\u30a2\u30af\u30bb\u30b9\u306f NW.js \u81ea\u4f53\u306b\u306f\u30e2\u30b8\u30e5\u30fc\u30eb\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u306a\u3044\u305f\u3081\u3001node-sqlite3 \u3068\u3044\u3046\u00a0Node.js \u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u5225\u9014\u8ffd\u52a0\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305f\u3060 NW.js \u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306b\u3088\u3063\u3066\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3066\u3044\u306a\u3044\u3068\u3044\u3046<a href=\"https:\/\/github.com\/mapbox\/node-sqlite3\/issues\/366\" target=\"_blank\">\u60c5\u5831<\/a>\u3082\u3042\u308a\u3001(\u5b9f\u969b\u306b\u6700\u65b0\u7248\u3067\u3042\u308b 0.11.0 \u3067\u306f\u52d5\u4f5c\u3057\u307e\u305b\u3093\u3067\u3057\u305f\u3002)\u4eca\u56de\u306f node-webkit 0.10.5 (NW.js \u306e\u65e7\u30d0\u30fc\u30b8\u30e7\u30f3)\u3092\u4f7f\u7528\u81f4\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u307e\u305f node-sqlite3 \u3092\u4f7f\u7528\u305b\u305a\u306b\u3001sql.js \u3068\u3044\u3046\u30d4\u30e5\u30a2 JavaScript \u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3067 SQLite \u3092\u6271\u3046\u65b9\u6cd5\u3082\u3042\u308a\u307e\u3059\u3002\u3053\u3061\u3089\u306e\u65b9\u304c\u5c0e\u5165\u304c\u3044\u305f\u3063\u3066\u30b7\u30f3\u30d7\u30eb\u3067\u3059\u3002\u8a73\u7d30\u306b\u3064\u3044\u3066\u306f<a href=\"http:\/\/tech.at-iroha.jp\/?p=233#sqljs\">\u3053\u3061\u3089<\/a>\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2>node-sqlite3 \u306e\u5c0e\u5165<\/h2>\n<p>[Mac \u306e\u5834\u5408]<\/p>\n<ol>\n<li>terminal \u3092\u8d77\u52d5<\/li>\n<li>node \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<br \/>\nbrew install node<br \/>\n<img decoding=\"async\" src=\"http:\/\/i.gyazo.com\/249b3964dc3b16b0cbdf9abf0bab4d1e.png\" alt=\"\" \/><\/li>\n<li>app\/node_modules \u306b\u79fb\u52d5 (node_modules \u30d5\u30a9\u30eb\u30c0\u304c\u306a\u3044\u5834\u5408\u306f\u4f5c\u6210)<br \/>\ncd app\/node_modules<\/li>\n<li>npm (Node.js Package Manager)\u306b\u3066sqlite3 \u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<br \/>\nnpm install sqlite3<br \/>\n<img decoding=\"async\" src=\"http:\/\/i.gyazo.com\/ad2d6c46844dcc0c64f27620e0c94d23.png\" alt=\"\" \/><\/li>\n<li>node-gyp (Generate Your Projects \u306e\u7565) \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<br \/>\nnpm install -g node-gyp<\/li>\n<li>nw-gyp rebuild &#8211;target=0.5.0<\/li>\n<li>node-pre-gyp (Node.js native addon binary install tool) \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/li>\n<li>node-webkit \u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u6307\u5b9a\u3059\u308b<br \/>\nnpm install node-pre-gyp -g<\/li>\n<li>sqlite3 \u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u30ea\u30d3\u30eb\u30c9<br \/>\nnode-pre-gyp rebuild &#8211;runtime=node-webkit &#8211;target=0.10.5 &#8211;target_arch=x64<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"http:\/\/i.gyazo.com\/08d16b81629bc230f99c04cbca129a44.png\" alt=\"\" width=\"697\" height=\"478\" \/><\/li>\n<li>\u30a2\u30d7\u30ea\u3092\u8d77\u52d5\n<p class=\"p1\"><span class=\"s1\">nw=&#8221;\/Applications\/node-webkit.app\/Contents\/MacOS\/node-webkit&#8221;<br \/>\n<\/span>nw app<\/p>\n<\/li>\n<\/ol>\n<ul>\n<li><a href=\"https:\/\/github.com\/mapbox\/node-sqlite3\" target=\"_blank\">node-sqlite3<\/a><\/li>\n<li><a href=\"https:\/\/www.npmjs.com\/package\/node-pre-gyp\" target=\"_blank\">node-pre-gyp (Node.js native addon binary install tool)<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/nwjs\/nw.js\/wiki\/Build-native-modules-with-nw-gyp\" target=\"_blank\">Build native modules with nw gyp<\/a><\/li>\n<\/ul>\n<p><!--more-->\u00a0<strong>\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0<\/strong><\/p>\n<p>NW.js \u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u304c11\u4ee5\u964d\u306e\u5834\u5408\u3001\u30d3\u30eb\u30c9\u6642\u306b\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u5834\u5408\u3042\u308a\u307e\u3059\u3002\u305d\u306e\u5834\u5408 0.10.x \u3067\u30d3\u30eb\u30c9\u3059\u308b\u3068\u3046\u307e\u304f\u3044\u304f\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/github.com\/mapbox\/node-sqlite3\/issues\/366\" target=\"_blank\">https:\/\/github.com\/mapbox\/node-sqlite3\/issues\/366<\/a><\/p>\n<p>\u30d3\u30eb\u30c9\u6642\u306b\u4ee5\u4e0b\u306e\u69d8\u306a\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u3001\u30b3\u30f3\u30d1\u30a4\u30e9\u304c\u6b63\u3057\u304f\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u306a\u3044\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"http:\/\/i.gyazo.com\/8b692b2a592735411b8e649fcd237cee.png\" alt=\"\" width=\"697\" height=\"478\" \/><\/p>\n<p>\u4ee5\u4e0b\u306e\u65b9\u6cd5\u3067\u30b3\u30f3\u30d1\u30a4\u30e9\u3092\u8a2d\u5b9a<\/p>\n<p class=\"p1\"><span class=\"s1\">sudo xcode-select -switch \/Applications\/Xcode.app\/Contents\/Developer<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"http:\/\/i.gyazo.com\/447fba11fc7d764b40872fc434dba168.png\" alt=\"\" width=\"697\" height=\"478\" \/><\/p>\n<p>Windows \u306e\u5834\u5408\u3001\u30d3\u30eb\u30c9\u6642\u306b\u4ee5\u4e0b\u306e\u69d8\u306a\u300cMicrosoft.Cpp.Default.props\u304c\u898b\u3064\u304b\u3089\u306a\u3044\u300d\u3068\u3044\u3046\u8da3\u65e8\u306e\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u306f\u30d3\u30eb\u30c9\u306b\u4f7f\u7528\u3059\u308b\u30b3\u30f3\u30d1\u30a4\u30e9\u304c\u6b63\u3057\u304f\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u306a\u3044\u5834\u5408\u306b\u767a\u751f\u3059\u308b\u3068\u601d\u308f\u308c\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"http:\/\/i.gyazo.com\/3a46aa65997d7fdfa1d502267b6aeaa0.png\" alt=\"\" width=\"708\" height=\"517\" \/><\/p>\n<p>\u305d\u306e\u5834\u5408\u3001\u307e\u305a Visual Studio \u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u308b\u304b\u78ba\u8a8d\u3057\u3066\u4e0b\u3055\u3044\u3002\u305d\u308c\u3067\u3082\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u5834\u5408\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u6539\u5584\u3055\u308c\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>npm install contextify &#8211;msvs_version=2012<\/p>\n<p>\u5229\u7528\u4f8b<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar sqlite3 = require('sqlite3').verbose();\r\nvar db = new sqlite3.Database('mydb.db');\r\n\r\ndb.serialize(function()\r\n{\r\n    db.each(\r\n        &quot;SELECT filed_name1, filed_name2 &quot; +\r\n        &quot;  FROM table_name\u201d,\r\n        function(err, row)\r\n        {\r\n            console.log(row.filed_name1 + &quot;: &quot; + row.filed_name2);\r\n        }\r\n    );\r\n});\r\n\r\ndb.close();\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h2><a name=\"sqljs\"><\/a>sql.js \u306e\u5c0e\u5165<\/h2>\n<p>node-sqlite3 \u306f\u5c0e\u5165\u6642\u306b\u3044\u308d\u3044\u308d\u3068\u30c8\u30e9\u30d6\u30eb\u3082\u591a\u304f\u3001\u6700\u65b0\u7248\u306eNW.js\u3067\u306f\u52d5\u4f5c\u3057\u307e\u305b\u3093\u3067\u3057\u305f\u3002\u307e\u305f\u30cd\u30a4\u30c6\u30a3\u30f4\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u5fc5\u8981\u3068\u3059\u308b\u305f\u3081\u3001\u30de\u30eb\u30c1\u30d7\u30e9\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0\u3067\u306e\u914d\u5e03\u3084\u5b9f\u884c\u6642\u306b\u30c8\u30e9\u30d6\u30eb\u304c\u767a\u751f\u3057\u306a\u3044\u304b\u4e0d\u5b89\u304c\u6b8b\u308a\u307e\u3059\u3002\u3053\u306e\u305f\u3081\u3088\u308a\u624b\u8efd\u306b SQLite \u3092\u5229\u7528\u3057\u305f\u3044\u5834\u5408\u306b\u306f\u3001sql.js \u3068\u3044\u3046 JavaScript \u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u5927\u304d\u306a\u9078\u629e\u80a2\u306b\u306a\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305f\u00a0sql.js\u00a0\u30d5\u30a1\u30a4\u30eb\u3092\u30a4\u30f3\u30af\u30eb\u30fc\u30c9\u3059\u308b\u3060\u3051\u3067\u5229\u7528\u53ef\u80fd\u3067\u3001\u8a66\u3057\u306b\u65e2\u5b58\u306e SQLite \u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3093\u3067\u307f\u307e\u3057\u305f\u304c\u3001\u65e5\u672c\u8a9e\u3082\u554f\u984c\u306a\u304f\u8aad\u307f\u66f8\u304d\u3067\u304d\u307e\u3057\u305f\u3002\u3053\u308c\u307e\u3067\u306e\u3068\u3053\u308d\u5927\u304d\u306a\u30c8\u30e9\u30d6\u30eb\u3082\u78ba\u8a8d\u3067\u304d\u3066\u304a\u308a\u307e\u305b\u3093\u304c\u3001\u552f\u4e00\u306e\u30c7\u30e1\u30ea\u30c3\u30c8\u306f\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba\u304c\u7d041.5MB\u3068\u3001\u304b\u306a\u308a\u5927\u304d\u3044\u3053\u3068\u3067\u3059\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/kripken\/sql.js\/\" target=\"_blank\">sql.js \u516c\u5f0f\u30b5\u30a4\u30c8<\/a><\/p>\n<p>\u5229\u7528\u4f8b<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n    &lt;title&gt;SQLite test&lt;\/title&gt;\r\n    &lt;script type='text\/javascript' src='.\/sql.js'&gt;&lt;\/script&gt;\r\n    &lt;script type=&quot;text\/javascript&quot;&gt;\r\n    function file_ChangeHandler(element)\r\n    {\r\n        var file       = element.files&#x5B;0];\r\n        var fileReader = new FileReader();\r\n\r\n        fileReader.onload = function() {\r\n            var Uints = new Uint8Array(fileReader.result);\r\n            db = new SQL.Database(Uints);\r\n\r\n            if(db)\r\n            {\r\n                var result = db.exec(\r\n                    &quot;SELECT field_name1, field_name2 &quot; +\r\n                    &quot;  FROM table_name &quot;\r\n                );\r\n\r\n                var rows = result&#x5B;0]&#x5B;&quot;values&quot;];\r\n\r\n                for (var i=0; i&lt;rows.length; i++)\r\n                {\r\n                    console.log( rows&#x5B;i]&#x5B;0] ); \/\/ filed 1 value\r\n                    console.log( rows&#x5B;i]&#x5B;1] ); \/\/ filed 2 value\r\n                }\r\n            }\r\n        }\r\n\r\n        fileReader.readAsArrayBuffer(file);\r\n    }\r\n    &lt;\/script&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n    &lt;input type=&quot;file&quot; id=&quot;file&quot; accept=&quot;.db&quot; onchange=&quot;file_ChangeHandler(this)&quot;&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQLite \u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30d5\u30a1\u30a4\u30eb\u3078\u306e\u30a2\u30af\u30bb\u30b9\u306f NW.js \u81ea\u4f53\u306b\u306f\u30e2\u30b8\u30e5\u30fc\u30eb\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u306a\u3044\u305f\u3081\u3001node-sqlite3 \u3068\u3044\u3046\u00a0Node.js \u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u5225\u9014\u8ffd\u52a0\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305f\u3060 NW.js \u306e\u30d0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":350,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,13,1],"tags":[],"class_list":["post-233","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-html5js","category-nw-js","category-unclassified"],"_links":{"self":[{"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=\/wp\/v2\/posts\/233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=233"}],"version-history":[{"count":26,"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=\/wp\/v2\/posts\/233\/revisions"}],"predecessor-version":[{"id":268,"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=\/wp\/v2\/posts\/233\/revisions\/268"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=\/wp\/v2\/media\/350"}],"wp:attachment":[{"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}