{"id":398468,"date":"2024-06-29T14:05:37","date_gmt":"2024-06-29T14:05:37","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=398468"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=398468","title":{"rendered":"<span>\u0420\u0435\u0446\u0435\u043f\u0442\u044b nginx: \u0432\u0438\u0434\u0436\u0435\u0442 \u0413\u043e\u0441\u0443\u0434\u0430\u0440\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0410\u0434\u0440\u0435\u0441\u043d\u043e\u0433\u043e \u0420\u0435\u0435\u0441\u0442\u0440\u0430<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u0438\u0434\u0436\u0435\u0442\u0430 \u0413\u043e\u0441\u0443\u0434\u0430\u0440\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0410\u0434\u0440\u0435\u0441\u043d\u043e\u0433\u043e \u0420\u0435\u0435\u0441\u0442\u0440\u0430, \u043a\u0440\u043e\u043c\u0435 <a href=\"https:\/\/habr.com\/ru\/post\/585244\/\" rel=\"noopener noreferrer nofollow\">\u0431\u0430\u0437\u044b<\/a>, \u043d\u0430\u043c \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f <a href=\"https:\/\/nginx.org\/ru\/\" rel=\"noopener noreferrer nofollow\">nginx<\/a> \u0438 \u0435\u0433\u043e \u043f\u043b\u0430\u0433\u0438\u043d\u044b <a href=\"https:\/\/github.com\/RekGRpth\/ngx_postgres\" rel=\"noopener noreferrer nofollow\">postgres<\/a> \u0438 <a href=\"https:\/\/github.com\/RekGRpth\/ngx_http_json_module\" rel=\"noopener noreferrer nofollow\">json<\/a>. \u041c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f <a href=\"https:\/\/github.com\/RekGRpth\/nginx.docker\/pkgs\/container\/nginx.docker\" rel=\"noopener noreferrer nofollow\">\u0433\u043e\u0442\u043e\u0432\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c<\/a>.<\/p>\n<p>\u0412 \u0431\u0430\u0437\u0435 \u0431\u044b\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f gar_select \u043e\u0442 json \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0430\u044f json. \u0412\u043e\u0442 \u043a\u0430\u043a \u0440\u0430\u0437 \u043e\u043d\u0430 \u0438 \u043d\u0443\u0436\u043d\u0430 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 nginx.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c (\u0432 http-\u0441\u0435\u043a\u0446\u0438\u044e \u0432\u043d\u0435 server-\u0441\u0435\u043a\u0446\u0438\u0439) \u0430\u043f\u0441\u0442\u0440\u0438\u043c \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0431\u0430\u0437\u0435:<\/p>\n<pre><code class=\"nginx\">upstream gar {   # \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u0445\u043e\u0441\u0442\u0443 postgres   # \u043d\u0430 \u043f\u043e\u0440\u0442 5432   # \u043a \u0431\u0430\u0437\u0435 gar   # \u043f\u043e\u0434 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c gar     postgres_server host=postgres port=5432 dbname=gar user=gar;   # \u0437\u0430\u0434\u0430\u0451\u043c \u043b\u043e\u0433 \u0434\u043b\u044f \u0430\u043f\u0441\u0442\u0440\u0438\u043c\u0430     postgres_log \/var\/log\/nginx\/gar.err;   # \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u043c\u0443 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044e \u0441 \u0431\u0430\u0437\u043e\u0439   # (\u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0435\u0441\u0441)     postgres_keepalive 1;   # \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0443   # (\u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0431\u0430\u0437\u043e\u0439)     postgres_prepare 1 overflow=deallocate; }<\/code><\/pre>\n<p>\u0430 \u0432 server-\u0441\u0435\u043a\u0446\u0438\u044e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435<\/p>\n<pre><code class=\"nginx\">location =\/gar_select.json {   # \u0437\u0430\u0434\u0430\u0451\u043c \u043b\u043e\u0433\u0438     access_log \/var\/log\/nginx\/gar_select.json.log main;     error_log \/var\/log\/nginx\/gar_select.json.err;   # \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u0430\u043f\u0441\u0442\u0440\u0438\u043c     postgres_pass gar;   # \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432     postgres_prepare true;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0437\u0430\u043f\u0440\u043e\u0441   # (\u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u0442\u0443 \u0441\u0430\u043c\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e gar_select,   # \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u0435\u0439 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 GET-\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b   # \u0432 \u0432\u0438\u0434\u0435 json)   # ** \u0441\u0440\u0430\u0437\u0443 \u0445\u043e\u0447\u0443 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0434\u0438\u0442\u044c: \u0437\u0434\u0435\u0441\u044c \u041d\u0415\u0422 sql-\u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0439! **     postgres_query \"select gar_select($json_get_vars::json)\";   # \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432\u044b\u0434\u0430\u0451\u043c json     postgres_output json; }<\/code><\/pre>\n<p>\u0422.\u043e. \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0447\u0442\u043e-\u0442\u043e \u0442\u0438\u043f\u0430 REST \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0435 gar, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0437 JavaScript.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u0441\u0442\u0438\u043b\u0438 \u0438 \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u0432 index.html<\/p>\n<pre><code class=\"xml\">&lt;html>     &lt;head>         &lt;meta http-equiv=\"content-type\" content=\"text\/html; charset=utf-8\" \/>         &lt;title>\u0413\u0410\u0420&lt;\/title>         &lt;link rel=\"stylesheet\" href=\"\/static\/bootstrap-5.1.1\/css\/bootstrap.css\" \/>         &lt;link rel=\"stylesheet\" href=\"\/static\/select2-4.1.0-rc.0\/css\/select2.css\" \/>         &lt;script src=\"\/static\/jquery-3.4.1\/jquery-3.4.1.js\">&lt;\/script>         &lt;script src=\"\/static\/bootstrap-5.1.1\/js\/bootstrap.js\">&lt;\/script>         &lt;script src=\"\/static\/select2-4.1.0-rc.0\/js\/select2.js\">&lt;\/script>         &lt;script src=\"\/static\/select2-4.1.0-rc.0\/js\/i18n\/ru.js\">&lt;\/script>         &lt;script src=\"index.js\">&lt;\/script>     &lt;\/head>     &lt;body>         &lt;form action=\"gar_select.html\" method=\"get\">&lt;table class=\"table\">&lt;tr>             &lt;td>gar-select:&lt;\/td>             &lt;td>&lt;select id=\"id_label_single\" class=\"gar-select\" name=\"id\" data-width=\"100%\" data-placeholder=\"\u0410\u0434\u0440\u0435\u0441\" data-initial=\"9ae64229-9f7b-4149-b27a-d1f6ec74b5ce\" data-id=\"[b5701907-1537-4e52-b93a-d566a47086f7,daa79543-d4e1-4cf7-bd3a-5936e670aea8]\"\/>&lt;\/td>             &lt;td>&lt;input class=\"btn btn-primary\" type=\"submit\" value=\"OK\"\/>&lt;\/td>         &lt;\/tr>&lt;\/table>&lt;\/form>     &lt;\/body> &lt;\/html><\/code><\/pre>\n<p>\u0430 \u0432\u043e\u0442 \u0441\u0430\u043c \u0441\u043a\u0440\u0438\u043f\u0442 index.js<\/p>\n<pre><code class=\"javascript\">\/\/ \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b $(document).ready(function() {   \/\/ \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0435\u043b\u0435\u043a\u0442\u0430 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c     $('select.gar-select').each(function(number, select) {       \/\/ \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430         function data(item) {return {           \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u0434\u043b\u044f select2             id: $.isArray(item) ? item[item.length - 1].id : item.id,             item: item,             text: $.isArray(item) ? item.map(function(item) {return item.text}).join(', ') : item.text,         }}       \/\/ \u0430 \u0442\u0430\u043a\u0436\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 select2         function select2(item) {$(select).data('select2').trigger('select', {data: data(item)})}       \/\/ \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c select2         $(select).select2({           \/\/ \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b             ajax: {               \/\/ \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c GET-\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 gar_select                 data: function(params) {return {                     full: !$.isEmptyObject(select.value) || ($.isEmptyObject(params.term) &amp;&amp; $.isEmptyObject(select.value) &amp;&amp; !$.isEmptyObject(select.dataset.id)),                     id: $.isEmptyObject(params.term) &amp;&amp; $.isEmptyObject(select.value) &amp;&amp; !$.isEmptyObject(select.dataset.id) ? select.dataset.id : undefined,                     limit: select.dataset.limit || 10,                     offset: ((params.page || 1) - 1) * (select.dataset.limit || 10),                     parent: !$.isEmptyObject(select.value) ? select.value : undefined,                     text: params.term,                 }},                 dataType: 'json', \/\/ \u0437\u0430\u0434\u0430\u0451\u043c \u0442\u0438\u043f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430                 delay: 300, \/\/ \u0438 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443               \/\/ \u0437\u0430\u0434\u0430\u0451\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430                 processResults: function(response, params) {return {                     results: response.data.map(data),                     pagination: {more: response.offset &lt; response.count}                 }},               \/\/ \u0430\u0434\u0440\u0435\u0441 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043f\u0440\u044f\u043c\u043e \u0432 \u0442\u0435\u0433\u0435                 url: select.dataset.url || 'gar_select.json',             },             allowClear: true, \/\/ \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043a\u043d\u043e\u043f\u043a\u0443 \u043e\u0447\u0438\u0441\u0442\u043a\u0438             closeOnSelect: false, \/\/ \u043d\u0435 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u0438 \u0432\u044b\u0431\u043e\u0440\u0435             dropdownParent: $(select).parent(), \/\/ \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c \u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435             language: 'ru', \/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0435\u0443\u043c \u0440\u0443\u0441\u0441\u043a\u0438\u0439 \u044f\u0437\u044b\u043a         })       \/\/ \u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 \u043e\u0447\u0438\u0441\u0442\u043a\u0438         $(select).on('select2:clear', function(event) {           \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442             var item = event.params.data[0].item             if ($.isArray(item)) {               \/\/ \u0438 \u0435\u0441\u043b\u0438 \u0435\u0449\u0451 \u043d\u0435 \u0434\u043e\u0448\u043b\u0438 \u0434\u043e \u0432\u0435\u0440\u0445\u0430                 item = item.slice(0, -1)               \/\/ \u0442\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f                 if (item.length) {select2(item)}             }           \/\/ \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0432\u044b\u0431\u043e\u0440             setTimeout(function() {$(select).select2('open')})         })       \/\/ \u043f\u0440\u0438 \u0432\u044b\u0431\u043e\u0440\u0435         $(select).on('select2:select', function(event) {           \/\/ \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u043e\u0438\u0441\u043a             $(select).data('select2').trigger('query', {})           \/\/ \u043e\u0447\u0438\u0449\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043e\u0438\u0441\u043a\u0430             $(select).parent().find('.select2-search__field').val('').trigger('focus')         })       \/\/ \u0435\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u043d \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0443\u0438\u0434         if (select.dataset.initial) {$.ajax({           \/\/ \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441             url: $(select).data('select2').options.options.ajax.url,             dataType: $(select).data('select2').options.options.ajax.dataType,             data: {id: select.dataset.initial}         }).done(function(response) {           \/\/ \u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442             select2(response.data)           \/\/ \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0432\u044b\u0431\u043e\u0440             $(select).select2('close')         })}     }) })<\/code><\/pre>\n<p>\u0415\u0449\u0451, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u0432 <a href=\"https:\/\/github.com\/RekGRpth\/ngx_http_evaluate_module\" rel=\"noopener noreferrer nofollow\">evaluate<\/a> \u0438 <a href=\"https:\/\/github.com\/RekGRpth\/ngx_http_mustach_module\" rel=\"noopener noreferrer nofollow\">mustach<\/a> \u043c\u043e\u0436\u043d\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c html-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441:<\/p>\n<pre><code class=\"nginx\">location =\/gar_select.html {   # \u0437\u0430\u0434\u0430\u0451\u043c \u043b\u043e\u0433\u0438     access_log \/var\/log\/nginx\/gar_select.html.log main;     error_log \/var\/log\/nginx\/gar_select.html.err;   # \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u043e\u0434-\u0437\u0430\u043f\u0440\u043e\u0441\u044b     # \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435     evaluate $json \/gar_select.json;     evaluate $template \/gar_select.template;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430     mustach_json $json;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0448\u0430\u0431\u043b\u043e\u043d     mustach_template $template;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0442\u0438\u043f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430     mustach_content text\/html; } location =\/gar_select.template {     access_log \/var\/log\/nginx\/gar_select.template.log main;     error_log \/var\/log\/nginx\/gar_select.template.err;     internal; }<\/code><\/pre>\n<p>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c \u0448\u0430\u0431\u043b\u043e\u043d gar_select.template<\/p>\n<pre><code class=\"xml\">&lt;html>     &lt;head>         &lt;meta http-equiv=\"content-type\" content=\"text\/html; charset=utf-8\" \/>         &lt;title>\u0413\u0410\u0420&lt;\/title>         &lt;link rel=\"stylesheet\" href=\"\/static\/bootstrap-5.1.1\/css\/bootstrap.min.css\" \/>         &lt;script src=\"\/static\/jquery-3.4.1\/jquery-3.4.1.min.js\">&lt;\/script>         &lt;script src=\"\/static\/bootstrap-5.1.1\/js\/bootstrap.min.js\">&lt;\/script>         &lt;script>             var limit = {{limit}};             var offset = {{offset}};             var count = {{count}};         &lt;\/script>         &lt;script src=\"gar_select.js\">&lt;\/script>     &lt;\/head>     &lt;body>         &lt;form action=\"\" method=\"get\">             &lt;input type=\"hidden\" name=\"child\" value=\"true\"\/>             &lt;table class=\"table table-bordered table-striped table-hover table-condensed text-nowrap\">                 &lt;thead>                     &lt;th class=\"id\" title=\"id\">&lt;input style=\"width:100%\" class=\"offset\" placeholder=\"id\" name=\"id\" value='{{query.id}}'\/>&lt;\/th>                     &lt;th class=\"parent\" title=\"parent\">&lt;input style=\"width:100%\" class=\"offset\" placeholder=\"parent\" name=\"parent\" value=\"{{query.parent}}\"\/>&lt;\/th>                     &lt;th class=\"name\" title=\"name\">&lt;input style=\"width:100%\" class=\"offset\" placeholder=\"name\" name=\"name\" value=\"{{query.name}}\"\/>&lt;\/th>                     &lt;th class=\"short\" title=\"short\">&lt;input style=\"width:100%\" class=\"offset\" placeholder=\"short\" name=\"short\" value=\"{{query.short}}\"\/>&lt;\/th>                     &lt;th class=\"type\" title=\"type\">&lt;input style=\"width:100%\" class=\"offset\" placeholder=\"type\" name=\"type\" value=\"{{query.type}}\"\/>&lt;\/th>                     &lt;th class=\"post\" title=\"post\">&lt;input style=\"width:100%\" class=\"offset\" placeholder=\"post\" name=\"post\" value=\"{{query.post}}\"\/>&lt;\/th>                     &lt;th class=\"object\" title=\"object\">&lt;input style=\"width:100%\" class=\"offset\" placeholder=\"object\" name=\"object\" value=\"{{query.object}}\"\/>&lt;\/th>                     &lt;th class=\"region\" title=\"region\">&lt;input style=\"width:100%\" class=\"offset\" placeholder=\"region\" name=\"region\" value=\"{{query.region}}\"\/>&lt;\/th>                     &lt;th class=\"text\" title=\"text\">&lt;input style=\"width:100%\" class=\"offset\" placeholder=\"text\" name=\"text\" value=\"{{query.text}}\"\/>&lt;\/th>                     &lt;th class=\"child\" title=\"child\">&lt;input style=\"width:100%\" class=\"\" type=\"submit\" value=\"child\"\/>&lt;\/th>                 &lt;\/thead>                 {{#data}}                 &lt;tr>                     &lt;td class=\"id\" title=\"id\">{{id}}&lt;\/td>                     &lt;td class=\"parent\" title=\"parent\">&lt;a href=\"gar_select.html?child=true&amp;id={{parent}}\">{{parent}}&lt;\/a>&lt;\/td>                     &lt;td class=\"name\" title=\"name\">{{name}}&lt;\/td>                     &lt;td class=\"short\" title=\"short\">{{short}}&lt;\/td>                     &lt;td class=\"type\" title=\"type\">{{type}}&lt;\/td>                     &lt;td class=\"post\" title=\"post\">{{post}}&lt;\/td>                     &lt;td class=\"object\" title=\"text\">{{object}}&lt;\/td>                     &lt;td class=\"region\" title=\"text\">{{region}}&lt;\/td>                     &lt;td class=\"text\" title=\"text\">{{text}}&lt;\/td>                     &lt;td class=\"child\" title=\"child\">&lt;input name=\"child\" type=\"button\" value=\"{{child}}\" parent=\"{{id}}\"\/>&lt;\/td>                 &lt;\/tr>                 {{\/data}}             &lt;\/table>             &lt;table class=\"table\">&lt;tr>                 &lt;td id=\"pagination\"\/>                 &lt;td>limit: &lt;input title=\"limit\" class=\"offset\" placeholder=\"limit\" name=\"limit\" value=\"{{limit}}\"\/>&lt;\/td>                 &lt;td>offset: &lt;input title=\"offset\" class=\"\" placeholder=\"offset\" name=\"offset\" value=\"{{offset}}\"\/>&lt;\/td>                 &lt;td id=\"record\"\/>&lt;td>\u0412\u0441\u0435\u0433\u043e {{count}}&lt;\/td>             &lt;\/tr>&lt;\/table>         &lt;\/form>     &lt;\/body> &lt;\/html><\/code><\/pre>\n<p>\u0438 \u0441\u043a\u0440\u0438\u043f\u0442 \u0434\u043b\u044f \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u0438 gar_select.js<\/p>\n<pre><code class=\"javascript\">\/\/ \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b document.addEventListener('DOMContentLoaded', function() {   \/\/ \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446     var pages = Math.ceil(count \/ limit)     \/\/ \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443     var page = Math.ceil(offset \/ limit) + 1     \/\/ \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0430\u0442\u044b \u043f\u043e\u043c\u0435\u0449\u044f\u044e\u0442\u0441\u044f \u043d\u0430 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443     if (count &lt;= limit) {       \/\/ \u0442\u043e \u0441\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u044e         $('#pagination').parent().parent().hide()     }   \/\/ \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b     if (count > 0) {       \/\/ \u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u044d\u0442\u043e\u043c         $('#record').append('\u0417\u0430\u043f\u0438\u0441\u0438 \u0441 ' + (offset + 1) + ' \u043f\u043e ' + Math.min(offset + limit, count))     } else {       \/\/ \u0438\u043d\u0430\u0447\u0435 - \u0441\u043a\u0440\u044b\u0432\u0430\u0435\u043c         $('#record').hide()     }   \/\/ \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u043a\u043d\u043e\u043f\u043a\u0438 \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u0438     for (var pag = 1, more = false; pag &lt;= pages; pag++) {         if (pages &lt;= 15 || pag &lt;= 3 || pag >= pages - 2 || (page - 1 &lt;= pag &amp;&amp; pag &lt;= page + 1)) {             $('#pagination').append(                 $('&lt;input>', {                     type: 'button',                     value: pag,                     disabled: pag == page,                 }).click(function(event) {                     $('input[name=offset]').val((this.value - 1) * limit)                     $('form').submit()                 })             )             more = false         } else if (!more &amp;&amp; (pag == 4 || pag == pages - 3)) {             $('#pagination').append($('&lt;span>').text('...'))             more = true         }     }   \/\/ \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0432 \u0432\u0435\u0440\u0445\u043d\u0438\u0445 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0445     $('input.offset').change(function(event) {       \/\/ \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u043e\u0444\u0441\u0435\u0442         $('input[name=offset]').val(0)     })   \/\/ \u043f\u043e \u043a\u043b\u0438\u043a\u0435 \u043d\u0430 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445     $('input[name=child]').click(function(event) {       \/\/ \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u043e\u0444\u0441\u0435\u0442         $('input[name=offset]').val(0)       \/\/ \u0438 \u0432\u0441\u0451, \u043a\u0440\u043e\u043c\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430         $('input.offset').not('[name=limit]').val('')       \/\/ \u0437\u0430\u0434\u0430\u0451\u043c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f         $('input[name=parent]').val($(this).attr('parent'))       \/\/ \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u043e\u0440\u043c\u0443         $('form').submit()     }) })<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u043b\u0430\u0433\u0438\u043d <a href=\"https:\/\/github.com\/RekGRpth\/ngx_http_evaluate_module\" rel=\"noopener noreferrer nofollow\">evaluate<\/a> \u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043f\u043e\u0434-\u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043b\u0430\u0433\u0438\u043d\u0430 <a href=\"https:\/\/github.com\/RekGRpth\/ngx_http_htmldoc_module\" rel=\"noopener noreferrer nofollow\">htmldoc<\/a> \u043c\u043e\u0436\u043d\u043e html \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432 pdf:<\/p>\n<pre><code class=\"nginx\">location =\/gar_select.pdf {   # \u0437\u0430\u0434\u0430\u0451\u043c \u043b\u043e\u0433\u0438     access_log \/var\/log\/nginx\/gar_select.pdf.log main;     error_log \/var\/log\/nginx\/gar_select.pdf.err;   # \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043f\u043e\u0434-\u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e     evaluate $html \/gar_select.html;   # \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c html \u0432 pdf     html2pdf $html; }<\/code><\/pre>\n<p>\u0422.\u043e., \u043c\u043e\u0436\u043d\u043e \u0432 \u043b\u044e\u0431\u043e\u043c \u043c\u0435\u0441\u0442\u0435, \u0433\u0434\u0435 \u043d\u0443\u0436\u0435\u043d \u0432\u044b\u0431\u043e\u0440 \u0430\u0434\u0440\u0435\u0441\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0438\u0434\u0436\u0435\u0442. \u0415\u0433\u043e \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e &#171;\u043d\u0430\u0439\u0442\u0438 \u0432\u0441\u0435 \u0443\u0441\u043b\u0443\u0433\u0438 \u043d\u0430 \u0442\u0430\u043a\u043e\u0439-\u0442\u043e \u0443\u043b\u0438\u0446\u0435&#187;, \u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0443\u043b\u0438\u0446\u0443 \u0432 \u0432\u0438\u0434\u0436\u0435\u0442\u0435, \u0431\u0430\u043a\u0435\u043d\u0434 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0443\u0438\u0434 \u044d\u0442\u043e\u0439 \u0443\u043b\u0438\u0446\u044b, \u0430 \u043f\u043e \u043d\u0435\u043c\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0433\u043e\u0442\u043e\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 gar_select_child \u043f\u043e\u043b\u0443\u0447\u0435\u0442 \u0443\u0438\u0434\u044b \u0432\u0441\u0435\u0445 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 (\u0434\u043e\u043c\u043e\u0432, \u043a\u0432\u0430\u0440\u0442\u0438\u0440, \u043a\u043e\u043c\u043d\u0430\u0442, &#8230;) \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0443\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u0432\u043e\u0435\u0439 \u0431\u0430\u0437\u0435.<\/p>\n<pre><code class=\"sql\">-- \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0438\u043b\u0438 \u043c\u0435\u043d\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0442 ... CREATE OR REPLACE FUNCTION gar_select_child(parent uuid, name text, short text, type text, post text, region text) RETURNS SETOF gar_view LANGUAGE sql STABLE AS $body$     with _ as (         with recursive _ as ( -- \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e           -- \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441\u0432\u0435\u0440\u0445\u0443 \u0438\u043b\u0438 \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430             select gar.*, 0 as i from gar where (gar_select_child.parent is null and parent is null) or id = gar_select_child.parent             union           -- \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044f \u0432\u043d\u0438\u0437             select gar.*, _.i + 1 as i from gar inner join _ on _.id = gar.parent         ) select * from _ where i > 0       -- \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044f \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u044b         and (gar_select_child.name is null or name ilike gar_select_child.name||'%' or name ilike '% '||gar_select_child.name||'%' or name ilike '%-'||gar_select_child.name||'%' or name ilike '%.'||gar_select_child.name||'%')         and (gar_select_child.short is null or short ilike gar_select_child.short)         and (gar_select_child.type is null or case when gar_select_child.type ilike '{%}' then type = any(gar_select_child.type::text[]) else type ilike gar_select_child.type||'%' end)         and (gar_select_child.post is null or post ilike gar_select_child.post||'%')         and (gar_select_child.region is null or case when gar_select_child.region ilike '{%}' then region = any(gar_select_child.region::smallint[]) else region = gar_select_child.region::smallint end)         order by i     ) select id, parent, name, short, type, post, region, gar_text(name, short, type) AS text from _ order by to_number('0'||name, '999999999'), name; $body$;<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/585476\/\"> https:\/\/habr.com\/ru\/articles\/585476\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u0438\u0434\u0436\u0435\u0442\u0430 \u0413\u043e\u0441\u0443\u0434\u0430\u0440\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0410\u0434\u0440\u0435\u0441\u043d\u043e\u0433\u043e \u0420\u0435\u0435\u0441\u0442\u0440\u0430, \u043a\u0440\u043e\u043c\u0435 <a href=\"https:\/\/habr.com\/ru\/post\/585244\/\" rel=\"noopener noreferrer nofollow\">\u0431\u0430\u0437\u044b<\/a>, \u043d\u0430\u043c \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f <a href=\"https:\/\/nginx.org\/ru\/\" rel=\"noopener noreferrer nofollow\">nginx<\/a> \u0438 \u0435\u0433\u043e \u043f\u043b\u0430\u0433\u0438\u043d\u044b <a href=\"https:\/\/github.com\/RekGRpth\/ngx_postgres\" rel=\"noopener noreferrer nofollow\">postgres<\/a> \u0438 <a href=\"https:\/\/github.com\/RekGRpth\/ngx_http_json_module\" rel=\"noopener noreferrer nofollow\">json<\/a>. \u041c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f <a href=\"https:\/\/github.com\/RekGRpth\/nginx.docker\/pkgs\/container\/nginx.docker\" rel=\"noopener noreferrer nofollow\">\u0433\u043e\u0442\u043e\u0432\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c<\/a>.<\/p>\n<p>\u0412 \u0431\u0430\u0437\u0435 \u0431\u044b\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f gar_select \u043e\u0442 json \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0430\u044f json. \u0412\u043e\u0442 \u043a\u0430\u043a \u0440\u0430\u0437 \u043e\u043d\u0430 \u0438 \u043d\u0443\u0436\u043d\u0430 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 nginx.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c (\u0432 http-\u0441\u0435\u043a\u0446\u0438\u044e \u0432\u043d\u0435 server-\u0441\u0435\u043a\u0446\u0438\u0439) \u0430\u043f\u0441\u0442\u0440\u0438\u043c \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0431\u0430\u0437\u0435:<\/p>\n<pre><code class=\"nginx\">upstream gar {   # \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u0445\u043e\u0441\u0442\u0443 postgres   # \u043d\u0430 \u043f\u043e\u0440\u0442 5432   # \u043a \u0431\u0430\u0437\u0435 gar   # \u043f\u043e\u0434 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c gar     postgres_server host=postgres port=5432 dbname=gar user=gar;   # \u0437\u0430\u0434\u0430\u0451\u043c \u043b\u043e\u0433 \u0434\u043b\u044f \u0430\u043f\u0441\u0442\u0440\u0438\u043c\u0430     postgres_log \/var\/log\/nginx\/gar.err;   # \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u043c\u0443 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044e \u0441 \u0431\u0430\u0437\u043e\u0439   # (\u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0435\u0441\u0441)     postgres_keepalive 1;   # \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0443   # (\u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0431\u0430\u0437\u043e\u0439)     postgres_prepare 1 overflow=deallocate; }<\/code><\/pre>\n<p>\u0430 \u0432 server-\u0441\u0435\u043a\u0446\u0438\u044e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435<\/p>\n<pre><code class=\"nginx\">location =\/gar_select.json {   # \u0437\u0430\u0434\u0430\u0451\u043c \u043b\u043e\u0433\u0438     access_log \/var\/log\/nginx\/gar_select.json.log main;     error_log \/var\/log\/nginx\/gar_select.json.err;   # \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u0430\u043f\u0441\u0442\u0440\u0438\u043c     postgres_pass gar;   # \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432     postgres_prepare true;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0437\u0430\u043f\u0440\u043e\u0441   # (\u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u0442\u0443 \u0441\u0430\u043c\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e gar_select,   # \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u0435\u0439 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 GET-\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b   # \u0432 \u0432\u0438\u0434\u0435 json)   # ** \u0441\u0440\u0430\u0437\u0443 \u0445\u043e\u0447\u0443 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0434\u0438\u0442\u044c: \u0437\u0434\u0435\u0441\u044c \u041d\u0415\u0422 sql-\u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0439! **     postgres_query \"select gar_select($json_get_vars::json)\";   # \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432\u044b\u0434\u0430\u0451\u043c json     postgres_output json; }<\/code><\/pre>\n<p>\u0422.\u043e. \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0447\u0442\u043e-\u0442\u043e \u0442\u0438\u043f\u0430 REST \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0435 gar, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0437 JavaScript.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u0441\u0442\u0438\u043b\u0438 \u0438 \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u0432 index.html<\/p>\n<pre><code class=\"xml\">&lt;html>     &lt;head>         &lt;meta http-equiv=\"content-type\" content=\"text\/html; charset=utf-8\" \/>         &lt;title>\u0413\u0410\u0420&lt;\/title>         &lt;link rel=\"stylesheet\" href=\"\/static\/bootstrap-5.1.1\/css\/bootstrap.css\" \/>         &lt;link rel=\"stylesheet\" href=\"\/static\/select2-4.1.0-rc.0\/css\/select2.css\" \/>         &lt;script src=\"\/static\/jquery-3.4.1\/jquery-3.4.1.js\">&lt;\/script>         &lt;script src=\"\/static\/bootstrap-5.1.1\/js\/bootstrap.js\">&lt;\/script>         &lt;script src=\"\/static\/select2-4.1.0-rc.0\/js\/select2.js\">&lt;\/script>         &lt;script src=\"\/static\/select2-4.1.0-rc.0\/js\/i18n\/ru.js\">&lt;\/script>         &lt;script src=\"index.js\">&lt;\/script>     &lt;\/head>     &lt;body>         &lt;form action=\"gar_select.html\" method=\"get\">&lt;table class=\"table\">&lt;tr>             &lt;td>gar-select:&lt;\/td>             &lt;td>&lt;select id=\"id_label_single\" class=\"gar-select\" name=\"id\" data-width=\"100%\" data-placeholder=\"\u0410\u0434\u0440\u0435\u0441\" data-initial=\"9ae64229-9f7b-4149-b27a-d1f6ec74b5ce\" data-id=\"[b5701907-1537-4e52-b93a-d566a47086f7,daa79543-d4e1-4cf7-bd3a-5936e670aea8]\"\/>&lt;\/td>             &lt;td>&lt;input class=\"btn btn-primary\" type=\"submit\" value=\"OK\"\/>&lt;\/td>         &lt;\/tr>&lt;\/table>&lt;\/form>     &lt;\/body> &lt;\/html><\/code><\/pre>\n<p>\u0430 \u0432\u043e\u0442 \u0441\u0430\u043c \u0441\u043a\u0440\u0438\u043f\u0442 index.js<\/p>\n<pre><code class=\"javascript\">\/\/ \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b $(document).ready(function() {   \/\/ \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0435\u043b\u0435\u043a\u0442\u0430 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c     $('select.gar-select').each(function(number, select) {       \/\/ \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430         function data(item) {return {           \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u0434\u043b\u044f select2             id: $.isArray(item) ? item[item.length - 1].id : item.id,             item: item,             text: $.isArray(item) ? item.map(function(item) {return item.text}).join(', ') : item.text,         }}       \/\/ \u0430 \u0442\u0430\u043a\u0436\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 select2         function select2(item) {$(select).data('select2').trigger('select', {data: data(item)})}       \/\/ \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c select2         $(select).select2({           \/\/ \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b             ajax: {               \/\/ \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c GET-\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 gar_select                 data: function(params) {return {                     full: !$.isEmptyObject(select.value) || ($.isEmptyObject(params.term) &amp;&amp; $.isEmptyObject(select.value) &amp;&amp; !$.isEmptyObject(select.dataset.id)),                     id: $.isEmptyObject(params.term) &amp;&amp; $.isEmptyObject(select.value) &amp;&amp; !$.isEmptyObject(select.dataset.id) ? select.dataset.id : undefined,                     limit: select.dataset.limit || 10,                     offset: ((params.page || 1) - 1) * (select.dataset.limit || 10),                     parent: !$.isEmptyObject(select.value) ? select.value : undefined,                     text: params.term,                 }},                 dataType: 'json', \/\/ \u0437\u0430\u0434\u0430\u0451\u043c \u0442\u0438\u043f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430                 delay: 300, \/\/ \u0438 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443               \/\/ \u0437\u0430\u0434\u0430\u0451\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430                 processResults: function(response, params) {return {                     results: response.data.map(data),                     pagination: {more: response.offset &lt; response.count}                 }},               \/\/ \u0430\u0434\u0440\u0435\u0441 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043f\u0440\u044f\u043c\u043e \u0432 \u0442\u0435\u0433\u0435                 url: select.dataset.url || 'gar_select.json',             },             allowClear: true, \/\/ \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043a\u043d\u043e\u043f\u043a\u0443 \u043e\u0447\u0438\u0441\u0442\u043a\u0438             closeOnSelect: false, \/\/ \u043d\u0435 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u0438 \u0432\u044b\u0431\u043e\u0440\u0435             dropdownParent: $(select).parent(), \/\/ \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c \u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435             language: 'ru', \/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0435\u0443\u043c \u0440\u0443\u0441\u0441\u043a\u0438\u0439 \u044f\u0437\u044b\u043a         })       \/\/ \u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 \u043e\u0447\u0438\u0441\u0442\u043a\u0438         $(select).on('select2:clear', function(event) {           \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442             var item = event.params.data[0].item             if ($.isArray(item)) {               \/\/ \u0438 \u0435\u0441\u043b\u0438 \u0435\u0449\u0451 \u043d\u0435 \u0434\u043e\u0448\u043b\u0438 \u0434\u043e \u0432\u0435\u0440\u0445\u0430                 item = item.slice(0, -1)               \/\/ \u0442\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f                 if (item.length) {select2(item)}             }           \/\/ \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0432\u044b\u0431\u043e\u0440             setTimeout(function() {$(select).select2('open')})         })       \/\/ \u043f\u0440\u0438 \u0432\u044b\u0431\u043e\u0440\u0435         $(select).on('select2:select', function(event) {           \/\/ \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u043e\u0438\u0441\u043a             $(select).data('select2').trigger('query', {})           \/\/ \u043e\u0447\u0438\u0449\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043e\u0438\u0441\u043a\u0430             $(select).parent().find('.select2-search__field').val('').trigger('focus')         })       \/\/ \u0435\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u043d \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0443\u0438\u0434         if (select.dataset.initial) {$.ajax({           \/\/ \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441             url: $(select).data('select2').options.options.ajax.url,             dataType: $(select).data('select2').options.options.ajax.dataType,             data: {id: select.dataset.initial}         }).done(function(response) {           \/\/ \u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442             select2(response.data)           \/\/ \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0432\u044b\u0431\u043e\u0440             $(select).select2('close')         })}     }) })<\/code><\/pre>\n<p>\u0415\u0449\u0451, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u0432 <a href=\"https:\/\/github.com\/RekGRpth\/ngx_http_evaluate_module\" rel=\"noopener noreferrer nofollow\">evaluate<\/a> \u0438 <a href=\"https:\/\/github.com\/RekGRpth\/ngx_http_mustach_module\" rel=\"noopener noreferrer nofollow\">mustach<\/a> \u043c\u043e\u0436\u043d\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c html-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441:<\/p>\n<pre><code class=\"nginx\">location =\/gar_select.html {   # \u0437\u0430\u0434\u0430\u0451\u043c \u043b\u043e\u0433\u0438     access_log \/var\/log\/nginx\/gar_select.html.log main;     error_log \/var\/log\/nginx\/gar_select.html.err;   # \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u043e\u0434-\u0437\u0430\u043f\u0440\u043e\u0441\u044b     # \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435     evaluate $json \/gar_select.json;     evaluate $template \/gar_select.template;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430     mustach_json $json;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0448\u0430\u0431\u043b\u043e\u043d     mustach_template $template;   # \u0437\u0430\u0434\u0430\u0451\u043c \u0442\u0438\u043f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430     mustach_content text\/html; } location =\/gar_select.template {     access_log \/var\/log\/nginx\/gar_select.template.log main;     error_log \/var\/log\/nginx\/gar_select.template.err;     internal; }<\/code><\/pre>\n<p>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c \u0448\u0430\u0431\u043b\u043e\u043d gar_select.template<\/p>\n<pre><code class=\"xml\">&lt;html>     &lt;head>         &lt;meta http-equiv=\"content-type\" content=\"text\/html; charset=utf-8\" \/>         &lt;title>\u0413\u0410\u0420&lt;\/title>         &lt;link rel=\"stylesheet\" href=\"\/static\/bootstrap-5.1.1\/css\/bootstrap.min.css\" \/>         &lt;script src=\"\/static\/jquery-3.4.1\/jquery-3.4.1.min.js\">&lt;\/script>         &lt;script src=\"\/static\/bootstrap-5.1.1\/js\/bootstrap.min.js\">&lt;\/script>         &lt;script>             var limit = {{limit}};             var offset = {{offset}};             var count = {{count}};         &lt;\/script>         &lt;script src=\"gar_select.js\">&lt;\/script>     &lt;\/head>     &lt;body>         &lt;form action=\"\" method=\"get\">             &lt;input type=\"hidden\" name=\"child\" value=\"true\"\/>             &lt;table class=\"table table-bordered table-striped table-hover table-condensed text-nowrap\">                 &lt;thead>                     &lt;th class=\"id\" title=\"id\">&lt;input style=\"width:100%\" class=\"offset\" placeholder=\"id\" name=\"id\" value='{{query.id}}'\/>&lt;\/th>                     &lt;th class=\"parent\" title=\"parent\">&lt;input style=\"width:100%\" class=\"offset\" placeholder=\"parent\" name=\"parent\" value=\"{{query.parent}}\"\/>&lt;\/th>                     &lt;th class=\"name\" title=\"name\">&lt;input style=\"width:100%\" class=\"offset\" placeholder=\"name\" name=\"name\" value=\"{{query.name}}\"\/>&lt;\/th>                     &lt;th class=\"short\" title=\"short\">&lt;input style=\"width:100%\" class=\"offset\" placeholder=\"short\" name=\"short\" value=\"{{query.short}}\"\/>&lt;\/th>                     &lt;th class=\"type\" title=\"type\">&lt;input style=\"width:100%\" class=\"offset\" placeholder=\"type\" name=\"type\" value=\"{{query.type}}\"\/>&lt;\/th>                     &lt;th class=\"post\" title=\"post\">&lt;input style=\"width:100%\" class=\"offset\" placeholder=\"post\" name=\"post\" value=\"{{query.post}}\"\/>&lt;\/th>                     &lt;th class=\"object\" title=\"object\">&lt;input style=\"width:100%\" class=\"offset\" placeholder=\"object\" name=\"object\" value=\"{{query.object}}\"\/>&lt;\/th>                     &lt;th class=\"region\" title=\"region\">&lt;input style=\"width:100%\" class=\"offset\" placeholder=\"region\" name=\"region\" value=\"{{query.region}}\"\/>&lt;\/th>                     &lt;th class=\"text\" title=\"text\">&lt;input style=\"width:100%\" class=\"offset\" placeholder=\"text\" name=\"text\" value=\"{{query.text}}\"\/>&lt;\/th>                     &lt;th class=\"child\" title=\"child\">&lt;input style=\"width:100%\" class=\"\" type=\"submit\" value=\"child\"\/>&lt;\/th>                 &lt;\/thead>                 {{#data}}                 &lt;tr>                     &lt;td class=\"id\" title=\"id\">{{id}}&lt;\/td>                     &lt;td class=\"parent\" title=\"parent\">&lt;a href=\"gar_select.html?child=true&amp;id={{parent}}\">{{parent}}&lt;\/a>&lt;\/td>                     &lt;td class=\"name\" title=\"name\">{{name}}&lt;\/td>                     &lt;td class=\"short\" title=\"short\">{{short}}&lt;\/td>                     &lt;td class=\"type\" title=\"type\">{{type}}&lt;\/td>                     &lt;td<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-398468","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/398468","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=398468"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/398468\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=398468"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=398468"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=398468"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}