{"id":269769,"date":"2015-12-07T14:40:02","date_gmt":"2015-12-07T11:40:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=269769"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=269769","title":{"rendered":"\u041f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 PostgreSQL \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e API: \u041d\u0430\u0445\u043e\u0434\u044f \u0438\u0441\u043a\u043e\u043c\u043e\u0435(\u0427\u0430\u0441\u0442\u044c 3)"},"content":{"rendered":"<p>       \u0412 \u0447\u0430\u0441\u0442\u044f\u0445 \u043f\u0435\u0440\u0432\u043e\u0439 \u0438 \u0432\u0442\u043e\u0440\u043e\u0439 \u044d\u0442\u043e\u0439 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439, \u044f \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b <a href=\"http:\/\/habrahabr.ru\/post\/272395\/\">\u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430<\/a> \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e <a href=\"http:\/\/habrahabr.ru\/post\/272411\/\">\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044f<\/a>. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u044f \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u043a\u0430\u043a \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u043e\u043d\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0431\u0443\u0434\u0443 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4><b>\u041b\u0443\u0447\u0448\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u0438\u0441\u043a\u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432<\/b><\/h4>\n<p>  \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"sql\">create table my_docs(   id serial primary key,   body jsonb not null,   search tsvector,   created_at timestamptz not null default now(),   updated_at timestamptz not null default now() ) <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u043d\u0430\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u043d\u043e\u0433\u0438\u043c\u0438 \u0432\u0435\u0441\u0435\u043b\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438! \u0412\u0441\u0435 \u0441\u0430\u043c\u043e\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0435 \u043f\u043e\u0437\u0430\u0434\u0438 (\u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435, \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u0442.\u0434.) \u2014 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0432\u0435\u0441\u0435\u043b\u0438\u043c\u0441\u044f.<\/p>\n<h4><b>\u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u043f\u043e ID<\/b><\/h4>\n<p>  \u041a\u0430\u0436\u0434\u044b\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0438\u043c\u0435\u0435\u0442 \u043f\u043e\u043b\u0435 <b>id<\/b>, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0435 \u0441 \u043d\u0438\u043c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <b>save_document<\/b>. \u042d\u0442\u043e \u0432\u0441\u0435 \u0435\u0449\u0435 Postgres, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u043e\u043b\u044e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 \u0438 \u043c\u044b \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0435\u0433\u043e \u0432\u043d\u0443\u0442\u0440\u044c \u0441\u0430\u043c\u043e\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430. \u042f \u0441\u0434\u0435\u043b\u0430\u043b \u0441\u0432\u043e\u0439 integer&#8217;\u043e\u043c, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"http:\/\/rob.conery.io\/2014\/05\/29\/a-better-id-generator-for-postgresql\/\"><b>bigint <\/b>\u0441\u043d\u0435\u0436\u0438\u043d\u043a\u0443 \u0422\u0432\u0438\u0442\u0442\u0435\u0440\u0430<\/a>, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0436\u0435\u043b\u0430\u043d\u0438\u0435. \u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f <b>serial<\/b>.<\/p>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0439\u043d\u0430:<\/p>\n<pre><code class=\"sql\">create function find_document(tbl varchar, id int, out jsonb) as $$   \/\/find by the id of the row   var result = plv8.execute(&quot;select * from &quot; + tbl + &quot; where id=$1;&quot;,id);   return result[0] ? result[0].body : null;  $$ language plv8;  select * from find_document('customers',20); <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u043d\u0430\u0438\u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0430\u044f \u0438\u0437 \u0432\u0441\u0435\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u2014 \u043e\u043d\u0430 \u0431\u0435\u0440\u0435\u0442 \u0438\u043c\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 ID, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u0439\u0442\u0438 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0441\u0430\u043c\u044b\u0439 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0438\u0437 \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0440\u043e\u0441 (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043b\u044e\u0431\u0438\u043c!): <b>\u043f\u043e\u0438\u0441\u043a \u043f\u043e \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u043c\u0443 \u043a\u043b\u044e\u0447\u0443<\/b>. \u0421\u043a\u043e\u0440\u043e\u0441\u0442\u044c: <i>\u043d\u0430\u043c \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f<\/i>.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0434\u043d\u0443 \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043c\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f \u0445\u043e\u0447\u0443 \u0432\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0435\u043a\u0438\u0439 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439 \u0438 \u043f\u043e\u0443\u0447\u0430\u0442\u044c \u043d\u0430\u0437\u0430\u0434 \u043f\u0435\u0440\u0432\u043e\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435. \u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u044f \u0431\u0443\u0434\u0443 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e <b>ORDER BY<\/b> \u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e ID:<\/p>\n<pre><code class=\"sql\">create function find_document(   tbl varchar,    criteria varchar,    orderby varchar default 'id' ) returns jsonb as $$   var valid = JSON.parse(criteria); \/\/this will throw if it invalid   var results = plv8.execute(&quot;select body from &quot; +                  tbl +                  &quot; where body @&gt; $1 order by body -&gt;&gt; '&quot; +                  orderby + &quot;' limit 1;&quot;,criteria);   return results[0] ? results[0].body : null $$ language plv8;  select * from find_document('customers','{&quot;last&quot;: &quot;Conery&quot;}', 'first'); <\/code><\/pre>\n<p>  \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043d\u0430\u0441 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u0441\u0442\u0440\u0430\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c. \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u044f \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>find_document<\/b>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e Postgres \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e. \u0427\u0442\u043e \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u043d\u0430\u0448\u0435\u0439 \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0449\u0435\u0442 \u043f\u043e id, \u0438 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u2014 \u044d\u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>  \u0414\u043b\u044f Npgsql \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 \u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439. \u0414\u043b\u044f node_pg \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 \u2014 \u044d\u0442\u043e \u0435\u0449\u0435 \u043a\u0430\u043a\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044f \u0437\u0430\u0434\u0430\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 <b>orderby<\/b>, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0443\u0442\u0430\u043d\u0438\u0446\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043f\u0440\u0438 \u0432\u044b\u0431\u043e\u0440\u0435, \u043a\u0430\u043a\u0443\u044e \u0438\u043c\u0435\u043d\u043d\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c. \u041d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044f \u043c\u043e\u0433\u0443 \u0441\u0443\u0434\u0438\u0442\u044c, node_pg \u0434\u0440\u0430\u0439\u0432\u0435\u0440 \u0437\u0430\u0431\u043e\u0442\u0438\u0442\u0441\u044f \u043d\u0435 \u0442\u0438\u043f\u043e\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, <b>\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0445 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c<\/b>. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u00ab\u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e id\u00bb, \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u0443\u044e \u0432\u044b\u0448\u0435, \u0442\u043e \u043d\u0430\u0448\u0430 \u0432\u0442\u043e\u0440\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0441\u0442\u0440\u0435\u043b\u0438\u0442.<\/p>\n<p>  \u0412\u043d\u043e\u0432\u044c: \u0443 Npgsql (.NET \u0434\u0440\u0430\u0439\u0432\u0435\u0440) \u043d\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b. \u0422\u0430\u043a \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u0443\u0439\u0442\u0435 \u043e\u0434\u043d\u0443 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0438\u043b\u0438 \u0443\u0431\u0435\u0440\u0438\u0442\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430.<\/p>\n<p>  \u0414\u0440\u0443\u0433\u043e\u0435, \u043d\u0430 \u0447\u0442\u043e \u043c\u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u044f \u0437\u0430\u0434\u0430\u043b \u0434\u043b\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 <b>criteria<\/b> \u0442\u0438\u043f <b>varchar<\/b>\/ \u042d\u0442\u043e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e, \u0445\u043e\u0442\u044c \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438 \u0438 \u043d\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u043d\u043e \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 API \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043b\u0443\u0447\u0448\u0435. \u0415\u0441\u043b\u0438 \u0431\u044b \u044f \u0437\u0430\u0434\u0430\u043b \u0435\u0433\u043e \u043a\u0430\u043a jsonb, \u0437\u0430\u043f\u0440\u043e\u0441 \u0431\u044b \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0432\u0438\u0434\u0435:<\/p>\n<pre><code class=\"sql\">select * from find_document('customers','{&quot;last&quot;: &quot;Conery&quot;}'::jsonb, 'first'); <\/code><\/pre>\n<p>  \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043d\u0435\u0432\u0435\u043b\u0438\u043a\u0430, \u0432\u0435\u0434\u044c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c API \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0437 \u043a\u043e\u0434\u0430 (\u043e \u0447\u0435\u043c \u043f\u043e\u0439\u0434\u0435\u0442 \u0440\u0435\u0447\u044c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u043e\u0441\u0442\u0435).<\/p>\n<h4><b>\u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f<\/b><\/h4>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u043c \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<pre><code class=\"sql\">create function filter_documents(     tbl varchar,    criteria varchar,    orderby varchar default 'id' ) returns setof jsonb as $$   var valid = JSON.parse(criteria);\/\/this will throw if it invalid   var results = plv8.execute(&quot;select body from &quot; +                  tbl +                  &quot; where body @&gt; $1 order by body -&gt;&gt; '&quot; +                  orderby +                  &quot;'&quot;,criteria);    var out = [];   for(var i = 0;i &lt; results.length; i++){     out.push(results[i].body);   }   return out; $$ language plv8;  select * from find_document('customer_docs','{&quot;last&quot;: &quot;Conery&quot;}'); <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u0443\u0436\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u044b\u0439 \u043c\u043d\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u2014 \u044d\u0442\u043e <b>setof jsonb<\/b>, \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u044f \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a <b>jsonb<\/b>. \u041d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e PLV8, \u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u0443\u0447\u0448\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431, \u043d\u0435\u0436\u0435\u043b\u0438 \u043c\u043e\u0439 \u2014 \u043d\u043e \u044d\u0442\u043e \u0442\u043e, \u0432 \u0447\u0435\u043c \u044f \u0443\u0432\u0435\u0440\u0435\u043d \u0447\u0442\u043e \u043e\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<p>  \u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u044f \u043f\u043e\u043b\u0443\u0447\u0430\u044e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 (\u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0437 \u043d\u0430\u0448\u0435\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b), \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0446\u0438\u043a\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0431\u0440\u0430\u0442\u044c \u0438 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0442\u0435\u043b\u043e <b>jsonb<\/b> \u043f\u043e\u043b\u044f \u0432 \u043c\u0430\u0441\u0441\u0438\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u043f\u043e\u0442\u043e\u043c \u0432\u0435\u0440\u043d\u0443.<\/p>\n<p>  \u0412\u0441\u0435 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043f\u043e\u043b\u0435 body \u044d\u0442\u043e jsonb, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u043c. \u042d\u0442\u043e \u043d\u0435 javascript \u043e\u0431\u044a\u0435\u043a\u0442, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0431\u044b \u043e\u043d \u0438\u043c \u0431\u044b\u043b, \u0442\u043e \u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u0431\u044b \u043e\u0448\u0438\u0431\u043a\u0443 (\u0441\u0442\u0430\u0440\u0430\u044f [Object object] \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u043e\u0432\u0430\u044f \u0433\u043b\u0443\u043f\u043e\u0441\u0442\u044c).<\/p>\n<h4><b>SQL \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0438 <\/b><\/h4>\n<p>  \u041c\u043d\u043e\u0433\u0438\u0435 \u0438\u0437 \u0432\u0430\u0441 \u0437\u0430\u043c\u0435\u0442\u044f\u0442, \u0447\u0442\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <b>orderby<\/b> \u0437\u0434\u0435\u0441\u044c \u043a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u043d\u0443\u0442\u0440\u044c. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442\u0435 \u0441\u0432\u043e\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u043f\u0438\u0441\u0430\u0442\u044c SQL \u0432 \u0432\u0430\u0448\u0443 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e \u0434\u0430, \u044d\u0442\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u041d\u043e, \u0441 \u043d\u0430\u0434\u0435\u0436\u0434\u043e\u0439, \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438\u0437 \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0432\u0430\u0448\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0437\u0430 \u0412\u0430\u0441, \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0434\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u0432\u0438\u0434\u0430:<\/p>\n<pre><code class=\"sql\">db.filter(&quot;customers&quot;, {   last : &quot;Conery&quot;,    orderBy : &quot;a';DROP TABLE test; SELECT * FROM users WHERE 't' = 't&quot; }, function(err, res){   console.log(err);   console.log(res); }); <\/code><\/pre>\n<p>  \u2026 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u041f\u043e\u0447\u0435\u043c\u0443 \u043d\u0435\u0442? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 \u0438\u0434\u0435\u0430\u043b\u0435 \u0432\u044b \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u0447\u0442\u043e-\u0442\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u0432\u0438\u0434\u0430: <\/p>\n<pre><code class=\"sql\">select * from filter_documents($1, $2, $3); <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0436\u0435 \u043d\u0435\u0442, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0435 \u0442\u043e, \u0447\u0435\u0433\u043e \u0437\u0430\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0435\u0442\u0435 :).<\/p>\n<h4><b>\u041f\u043e\u043b\u043d\u043e\u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u043f\u043e\u0438\u0441\u043a<\/b><\/h4>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043c \u043f\u043e\u043b\u043d\u043e\u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u043c \u043f\u043e\u0438\u0441\u043a\u043e\u043c \u043f\u043e \u043d\u0430\u0448\u0438\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u043c, \u043a\u0430\u043a \u0438 \u0441\u043b\u0435\u0434\u0443\u0435\u0442. \u042d\u0442\u043e \u043c\u043e\u044f \u043b\u044e\u0431\u0438\u043c\u0430\u044f \u0447\u0430\u0441\u0442\u044c:<\/p>\n<pre><code class=\"sql\">create function search_documents(tbl varchar, query varchar) returns setof jsonb as $$   var sql = &quot;select body, ts_rank_cd(search,to_tsquery($1)) as rank from &quot; +               tbl +              &quot; where search @@ to_tsquery($1) &quot; +              &quot; order by rank desc;&quot;    var results = plv8.execute(sql,query);   var out = [];   for(var i = 0; i &lt; results.length; i++){     out.push(results[i].body);   }   return out; $$ language plv8;  select * from search_documents('customers', 'jolene'); <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u0432\u0441\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e, \u0435\u0441\u043b\u0438 \u0437\u043d\u0430\u0442\u044c \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u0432 Postgres. \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 <b>search <\/b> \u043f\u043e\u043b\u0435\u043c (\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043e GIN \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u0434\u043b\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438), \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438. \u042d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0431\u044b\u0441\u0442\u0440 \u043a\u0430\u043a \u043c\u043e\u043b\u043d\u0438\u044f \u0438 \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043e\u043a \u0432 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438.<\/p>\n<h4><b>\u0414\u0435\u043b\u0430\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0431\u043e\u043b\u0435\u0435 \u0433\u0438\u0431\u043a\u0438\u043c\u0438<\/b><\/h4>\n<p>  \u0412 \u0434\u0432\u0443\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439 (\u043f\u043e\u0438\u0441\u043a \u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f), \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e <a href=\"http:\/\/www.postgresql.org\/docs\/current\/static\/datatype-json.html\">\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u00ab\u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f\u00bb<\/a>. \u042d\u0442\u043e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b <b>@&gt;<\/b>.<\/p>\n<p>  \u042d\u0442\u043e\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u043d \u0434\u043b\u044f <b>jsonb <\/b> \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c GIN \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0430 \u043f\u043e\u043b\u0435 <b>body<\/b>. \u042d\u0442\u043e\u0442 \u0438\u043d\u0434\u0435\u043a\u0441 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"sql\">create index idx_customers on customers using GIN(body jsonb_path_ops); <\/code><\/pre>\n<p>  \u041e\u0441\u043e\u0431\u0443\u044e \u043f\u0438\u043a\u0430\u043d\u0442\u043d\u043e\u0441\u0442\u044c \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u0438\u0434\u0430\u0435\u0442 <b>jsonb_path_ops<\/b>. \u041e\u043d \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u0442\u043e\u0440\u0443 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u00ab\u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f\u00bb <b>jsonb<\/b> (\u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438: \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u043b\u0438 \u044d\u0442\u043e\u0442 \u043a\u0443\u0441\u043e\u043a jsonb \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043a\u0443\u0441\u043a\u0435 jsonb). \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0447\u0442\u043e \u0438\u043d\u0434\u0435\u043a\u0441 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0438 \u043c\u0435\u043d\u044c\u0448\u0435.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u044f \u043c\u043e\u0433 \u0431\u044b \u0441\u043e\u0441\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u0443\u0447\u0443 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432 \u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a PostgreSQL \u043e\u0431\u0445\u043e\u0434\u0438\u0442 MongoDB \u0438 \u043f\u0440\u043e\u0447\u0438\u0445, \u043a\u043e\u0433\u0434\u0430 \u0440\u0435\u0447\u044c \u0438\u0434\u0435\u0442 \u043e \u0437\u0430\u043f\u0438\u0441\u0438\/\u0447\u0442\u0435\u043d\u0438\u0438. \u041d\u043e \u044d\u0442\u043e \u0432\u0432\u043e\u0434\u0438\u0442 \u0432 \u0437\u0430\u0431\u043b\u0443\u0436\u0434\u0435\u043d\u0438\u0435.<\/p>\n<h4><b>\u0421\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438<\/b><\/h4>\n<p>  \u0415\u0441\u043b\u0438 \u0412\u044b \u0432\u043e\u0437\u044c\u043c\u0435\u0442\u0435 \u043e\u0434\u0438\u043d PostgreSQL \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u043e\u0442\u0438\u0432 \u043e\u0434\u043d\u043e\u0433\u043e MongoDB \u0441\u0435\u0440\u0432\u0435\u0440\u0430, MongoDB \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0433\u043b\u0443\u043f\u0435\u0435 \u0438 Postgres \u0431\u0443\u0434\u0435\u0442 \u043a\u0443\u0440\u0438\u0442\u044c \u043f\u043e\u0447\u0442\u0438 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u043c\u0435\u0442\u0440\u0438\u043a\u0435. \u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e Postgres \u0431\u044b\u043b \u0442\u0430\u043a \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u2014 \u00ab\u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u0430\u044f\u00bb \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0412\u044b \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0435 MongoDB \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432, \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438, \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u0441\u0442\u0430\u043d\u0443\u0442 \u0443\u0436\u0435 \u0431\u043b\u0438\u0436\u0435 \u0434\u0440\u0443\u0433 \u043a \u0434\u0440\u0443\u0433\u0443, \u043d\u043e, \u043a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0438\u043c\u0435\u0442\u044c \u0434\u0435\u043b\u043e \u0441 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f <a href=\"https:\/\/aphyr.com\/posts\/322-call-me-maybe-mongodb-stale-reads\">\u043c\u043e\u0436\u0435\u0442 \u0432\u0435\u0441\u0442\u0438 \u0441\u0435\u0431\u044f \u0442\u0430\u043a, \u043a\u0430\u043a \u0432\u044b \u043e\u0442 \u043d\u0435\u0435 \u043d\u0435 \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0435<\/a>. \u042d\u0442\u043e \u0432\u0441\u0435 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u0441\u043f\u043e\u0440\u043d\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435, \u043d\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ul>\n<li>\u0418\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 Postgres \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0435\u0442. \u0422\u0430\u043a \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0440\u0443\u0448\u0438\u0442 \u0412\u0430\u0448\u0443 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0438, \u0412\u0430\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c (\u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044f <b>(body -&gt; my_field)<\/b>) \u043f\u0440\u0438 \u0437\u0430\u0434\u0430\u043d\u0438\u0438 GIN \u0438\u043d\u0434\u0435\u043a\u0441\u0430<\/li>\n<li>\u0415\u0441\u043b\u0438 \u0432\u044b \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0435\u0441\u044c \u043a \u0447\u0435\u043c\u0443-\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0447\u0430\u0441\u0442\u043e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0430\u0434\u0440\u0435\u0441 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b), \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043a\u043e\u043f\u0438\u0440\u0443\u0439\u0442\u0435 \u0435\u0433\u043e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u043a\u043e\u043b\u043e\u043d\u043a\u0443 \u0438 \u0441\u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u0435\u0433\u043e <b>UNIQUE<\/b> \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044e \u0432 \u043a\u043e\u0434\u0435, \u0438\u043b\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/li>\n<\/ul>\n<p>  \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u0433\u0440\u0443\u0436\u0443\u0441\u044c \u0432 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0438\u0437 \u043a\u043e\u0434\u0430!       <\/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\/272545\/\"> http:\/\/habrahabr.ru\/post\/272545\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u0412 \u0447\u0430\u0441\u0442\u044f\u0445 \u043f\u0435\u0440\u0432\u043e\u0439 \u0438 \u0432\u0442\u043e\u0440\u043e\u0439 \u044d\u0442\u043e\u0439 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439, \u044f \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b <a href=\"http:\/\/habrahabr.ru\/post\/272395\/\">\u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430<\/a> \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e <a href=\"http:\/\/habrahabr.ru\/post\/272411\/\">\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044f<\/a>. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u044f \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u043a\u0430\u043a \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u043e\u043d\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0431\u0443\u0434\u0443 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.  <\/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-269769","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/269769","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=269769"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/269769\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=269769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=269769"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=269769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}