{"id":256410,"date":"2015-04-30T14:59:02","date_gmt":"2015-04-30T10:59:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=256410"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=256410","title":{"rendered":"OrientDB \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 Node.js. \u041d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0435 \u0438 \u043d\u0435\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0435"},"content":{"rendered":"<p>     \t<habracut\/>\u0420\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0447\u0435\u043c\u0443 OrientDB \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0443\u0442\u0430\u044f \u0431\u0430\u0437\u0430, \u043d\u0435 \u0441\u0442\u0430\u043d\u0443. \u0420\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0435 \u043d\u044e\u0430\u043d\u0441\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 node.js.<\/p>\n<p>  <b>inset if not exist.<\/b> \u0412\u0440\u043e\u0434\u0435 \u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e\u0439 sql \u0437\u0430\u043f\u0440\u043e\u0441, \u0430\u043d \u043d\u0435\u0442 upsert \u0437\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439! \u041d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0432\u0438\u0434\u0435\u043b\u0438? \u042f \u0442\u043e\u0436\u0435, \u0430 \u043e\u043d\u043e \u0435\u0441\u0442\u044c \ud83d\ude42  <\/p>\n<pre><code class=\"sql\">update Words set word = :word upsert return after @rid where word = :word <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u043c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u044d\u0442\u0443 \u0447\u0430\u0441\u0442\u044c:  <\/p>\n<pre><code class=\"sql\">return after @rid <\/code><\/pre>\n<p>  \u0412\u0435\u0440\u043d\u0435\u0442 \u043d\u043e\u0432\u043e\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439  <a href=\"http:\/\/habrahabr.ru\/users\/rid\/\" class=\"user_link\">rid<\/a> \ud83d\ude09<\/p>\n<p>  <b>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 Edges<\/b>  <\/p>\n<pre><code class=\"sql\">create class Votes extends E create property Votes.in LINK create property Votes.out LINK create index Uniq on Votes (out, in) UNIQUE <\/code><\/pre>\n<p>  \u0418 \u0442\u0435\u043f\u0435\u0440\u044c oriento \u0431\u0443\u0434\u0435\u0442 \u043a\u0438\u0434\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432\u0442\u043e\u0440\u0443\u044e \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0443\u044e edge \u0438 \u0447\u0442\u043e\u0431\u044b \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0435\u0441\u0442\u044c \u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434<\/p>\n<pre><code class=\"javascript\">db.create('EDGE', 'VotesEdge').from(user_rid).to(vote_rid).one().then(function (err) {}) .catch(function (err) {       console.log(err);  }); <\/code><\/pre>\n<p>  \u041d\u0435 \u0432\u0438\u0434\u0435\u043b\u0438 <b>catch<\/b> \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 oriento. \u042f \u0442\u043e\u0436\u0435, \u0430 \u043e\u043d\u043e \u0435\u0441\u0442\u044c \ud83d\ude42<\/p>\n<p>  <b>\u0413\u0443\u043b\u044f\u0435\u043c \u043f\u043e \u0441\u0432\u044f\u0437\u0430\u043c(edges)<\/b><br \/>  \u042d\u0442\u043e \u0441\u0430\u043c\u0430\u044f \u043b\u0443\u0447\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c OrientDB. \u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0431\u0430\u0437\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u044c\u044e, \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c edge, \u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0439\u0442\u0438\u0441\u044c \u043f\u043e \u0434\u0435\u0441\u044f\u0442\u043a\u0443 \u0442\u0430\u0431\u043b\u0438\u0446 \u0438 \u0432\u044b\u043d\u0443\u0442\u044c \u043d\u0443\u0436\u043d\u043e\u0435 \u0437\u0430 1 \u0437\u0430\u043f\u0440\u043e\u0441. \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0438\u043c\u0445\u043e, \u0431\u044b\u0441\u0442\u0440\u043e. \ud83d\ude42<\/p>\n<p>  \u0412\u044b\u0431\u0435\u0440\u0435\u043c \u043d\u0438\u043a\u043d\u0435\u0439\u043c\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445  <\/p>\n<pre><code class=\"sql\">select out('ArticleCommentsEdge').out('CommentsUsersEdge').include('id', 'nick') as users <\/code><\/pre>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e, \u043d\u0443\u0436\u043d\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c \u0441 OrientDB.<\/p>\n<p>  include() \u2014 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434<\/p>\n<p>  \u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0443\u044e \u0437\u0430\u043f\u0441\u044c \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"sql\">select out('ArticleCommentsEdge').out('CommentsUsersEdge').id, out('ArticleCommentsEdge').out('CommentsUsersEdge').nick <\/code><\/pre>\n<p>  \u041d\u043e\u0432\u0438\u0447\u043a\u0438 \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u044e\u0442 \u0432\u0441\u0435\u0433\u0434\u0430, \u043d\u043e \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438 \u043d\u0430\u043b\u0438\u0446\u043e. \u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c 2 \u043c\u0430\u0441\u0441\u0438\u0432\u0430(\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u0442\u044b\u043a\u043e\u0432\u0430\u0442\u044c), \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 (users). <\/p>\n<p>  <b>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e edge<\/b>  <\/p>\n<pre><code class=\"sql\">select out('VotesEdge').size(); <\/code><\/pre>\n<p>  \u041c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 size(), \u0432\u044b\u0434\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u043e count() \u0432 mysql.<\/p>\n<p>  \u041f\u043e\u043d\u0430\u0447\u0430\u043b\u0443 OrientDB \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u0430\u043d\u043d\u043e\u0432\u0430\u0442\u043e\u0439, \u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u0443\u0437\u043d\u0430\u0435\u0448\u044c \u0435\u0451 \u043f\u043e\u0431\u043b\u0438\u0436\u0435, \u0442\u043e \u0441\u043d\u043e\u0441\u0438\u0442 \u043a\u0440\u044b\u0448\u0443 \ud83d\ude42     \t<\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/257061\/\"> http:\/\/habrahabr.ru\/post\/257061\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>     \t<habracut\/>\u0420\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0447\u0435\u043c\u0443 OrientDB \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0443\u0442\u0430\u044f \u0431\u0430\u0437\u0430, \u043d\u0435 \u0441\u0442\u0430\u043d\u0443. \u0420\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0435 \u043d\u044e\u0430\u043d\u0441\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 node.js.<\/p>\n<p>  <b>inset if not exist.<\/b> \u0412\u0440\u043e\u0434\u0435 \u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e\u0439 sql \u0437\u0430\u043f\u0440\u043e\u0441, \u0430\u043d \u043d\u0435\u0442 upsert \u0437\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439! \u041d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0432\u0438\u0434\u0435\u043b\u0438? \u042f \u0442\u043e\u0436\u0435, \u0430 \u043e\u043d\u043e \u0435\u0441\u0442\u044c \ud83d\ude42  <\/p>\n<pre><code class=\"sql\">update Words set word = :word upsert return after @rid where word = :word <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u043c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u044d\u0442\u0443 \u0447\u0430\u0441\u0442\u044c:  <\/p>\n<pre><code class=\"sql\">return after @rid <\/code><\/pre>\n<p>  \u0412\u0435\u0440\u043d\u0435\u0442 \u043d\u043e\u0432\u043e\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439  <a href=\"http:\/\/habrahabr.ru\/users\/rid\/\" class=\"user_link\">rid<\/a> \ud83d\ude09<\/p>\n<p>  <b>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 Edges<\/b>  <\/p>\n<pre><code class=\"sql\">create class Votes extends E create property Votes.in LINK create property Votes.out LINK create index Uniq on Votes (out, in) UNIQUE <\/code><\/pre>\n<p>  \u0418 \u0442\u0435\u043f\u0435\u0440\u044c oriento \u0431\u0443\u0434\u0435\u0442 \u043a\u0438\u0434\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432\u0442\u043e\u0440\u0443\u044e \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0443\u044e edge \u0438 \u0447\u0442\u043e\u0431\u044b \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0435\u0441\u0442\u044c \u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434<\/p>\n<pre><code class=\"javascript\">db.create('EDGE', 'VotesEdge').from(user_rid).to(vote_rid).one().then(function (err) {}) .catch(function (err) {       console.log(err);  }); <\/code><\/pre>\n<p>  \u041d\u0435 \u0432\u0438\u0434\u0435\u043b\u0438 <b>catch<\/b> \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 oriento. \u042f \u0442\u043e\u0436\u0435, \u0430 \u043e\u043d\u043e \u0435\u0441\u0442\u044c \ud83d\ude42<\/p>\n<p>  <b>\u0413\u0443\u043b\u044f\u0435\u043c \u043f\u043e \u0441\u0432\u044f\u0437\u0430\u043c(edges)<\/b><br \/>  \u042d\u0442\u043e \u0441\u0430\u043c\u0430\u044f \u043b\u0443\u0447\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c OrientDB. \u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0431\u0430\u0437\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u044c\u044e, \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c edge, \u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0439\u0442\u0438\u0441\u044c \u043f\u043e \u0434\u0435\u0441\u044f\u0442\u043a\u0443 \u0442\u0430\u0431\u043b\u0438\u0446 \u0438 \u0432\u044b\u043d\u0443\u0442\u044c \u043d\u0443\u0436\u043d\u043e\u0435 \u0437\u0430 1 \u0437\u0430\u043f\u0440\u043e\u0441. \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0438\u043c\u0445\u043e, \u0431\u044b\u0441\u0442\u0440\u043e. \ud83d\ude42<\/p>\n<p>  \u0412\u044b\u0431\u0435\u0440\u0435\u043c \u043d\u0438\u043a\u043d\u0435\u0439\u043c\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445  <\/p>\n<pre><code class=\"sql\">select out('ArticleCommentsEdge').out('CommentsUsersEdge').include('id', 'nick') as users <\/code><\/pre>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e, \u043d\u0443\u0436\u043d\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c \u0441 OrientDB.<\/p>\n<p>  include() \u2014 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434<\/p>\n<p>  \u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0443\u044e \u0437\u0430\u043f\u0441\u044c \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"sql\">select out('ArticleCommentsEdge').out('CommentsUsersEdge').id, out('ArticleCommentsEdge').out('CommentsUsersEdge').nick <\/code><\/pre>\n<p>  \u041d\u043e\u0432\u0438\u0447\u043a\u0438 \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u044e\u0442 \u0432\u0441\u0435\u0433\u0434\u0430, \u043d\u043e \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438 \u043d\u0430\u043b\u0438\u0446\u043e. \u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c 2 \u043c\u0430\u0441\u0441\u0438\u0432\u0430(\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u0442\u044b\u043a\u043e\u0432\u0430\u0442\u044c), \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 (users). <\/p>\n<p>  <b>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e edge<\/b>  <\/p>\n<pre><code class=\"sql\">select out('VotesEdge').size(); <\/code><\/pre>\n<p>  \u041c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 size(), \u0432\u044b\u0434\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u043e count() \u0432 mysql.<\/p>\n<p>  \u041f\u043e\u043d\u0430\u0447\u0430\u043b\u0443 OrientDB \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u0430\u043d\u043d\u043e\u0432\u0430\u0442\u043e\u0439, \u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u0443\u0437\u043d\u0430\u0435\u0448\u044c \u0435\u0451 \u043f\u043e\u0431\u043b\u0438\u0436\u0435, \u0442\u043e \u0441\u043d\u043e\u0441\u0438\u0442 \u043a\u0440\u044b\u0448\u0443 \ud83d\ude42     \t<\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/257061\/\"> http:\/\/habrahabr.ru\/post\/257061\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-256410","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/256410","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=256410"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/256410\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=256410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=256410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=256410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}