{"id":322731,"date":"2021-05-07T15:00:22","date_gmt":"2021-05-07T15:00:22","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=322731"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=322731","title":{"rendered":"\u041c\u043e\u0434\u0443\u043b\u044c \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 sqlite3"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u042f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0435\u0439 \u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043c\u043d\u0435 \u0443\u0436\u0435 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u043f\u043e\u043b \u0433\u043e\u0434\u0430: &#171;\u041c\u043e\u0434\u0443\u043b\u044c \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 sqlite3&#187;.<\/p>\n<h2>\u041a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f<\/h2>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f SQL \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u0438, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446, \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438 callback&#8217;\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432(\u0432 \u043a\u0430\u0436\u0434\u044b\u0439 callback \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u0435\u0441\u0442\u044c).<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u043c\u043e\u0434\u0443\u043b\u044c \u0432 \u0432\u0438\u0434\u0435 \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>\u0412\u0441\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 4 \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<ol>\n<li>\n<p>getData() &#8212; \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<\/li>\n<li>\n<p>insertData() &#8212; \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443.<\/p>\n<\/li>\n<li>\n<p>updateData() &#8212; \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435.<\/p>\n<\/li>\n<li>\n<p>deleteData() &#8212; \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<\/li>\n<\/ol>\n<blockquote>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e 4 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u043c\u044b \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0432\u0438\u0434\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043d\u043e \u0432 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0438 \u044d\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0441\u0430\u043c\u044b\u0435 \u0447\u0430\u0441\u0442\u044b\u0435.<\/p>\n<\/blockquote>\n<h2>\u041a\u043e\u0434\u0438\u043c<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0430\u043c \u043a\u043b\u0430\u0441\u0441, \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043c \u044d\u043a\u0441\u043f\u043e\u0440\u0442 \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c\u0441\u044f \u043a \u0411\u0414 \u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u0430\u0432\u044b\u0447\u043a\u0438 \u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0435\u0441\u043b\u0438 \u0442\u0438\u043f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0438\u043f\u0443 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<pre><code class=\"javascript\">class DataBase {      \/**      *       * @readonly      *\/     static sqlite3 = require('sqlite3').verbose();          \/**     *      * @readonly     *\/    static database = new this.sqlite3.Database('.\/database\/database.db');      static ToString(value) {         return typeof(value) === 'string' ? '\\'' + value + '\\'' : value;     } }  module.exports = {     database: DataBase };<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u043e \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c, \u043a\u043e\u043b-\u0432\u043e \u0441\u0442\u0440\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u0431\u0443\u0434\u0443\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f(\u043e\u0434\u043d\u0430 \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e).<\/p>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 &#171;SELECT&#187;, \u0434\u0430\u043b\u0435\u0435 \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0438 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0438\u0445, <strong>\u043d\u043e \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u0441\u0438\u043c\u0432\u043e\u043b &#171;*&#187; \u043d\u0435 \u043d\u0443\u0436\u043d\u043e &#171;\u0437\u0430\u043a\u043e\u0432\u044b\u0432\u0430\u0442\u044c&#187; \u0432 \u043a\u0430\u0432\u044b\u0447\u043a\u0438, \u0442 \u043a \u044d\u0442\u043e\u0442 \u0441\u0438\u043c\u0432\u043e\u043b \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043d\u0430\u043c, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b<\/strong>. \u0417\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u043c \u0441\u043e\u0431\u043e\u0440 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u044f. \u0414\u0430\u043b\u0435\u0435, \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u043a\u043e\u043b-\u0432\u043e \u0441\u0442\u0440\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434.<\/p>\n<pre><code class=\"javascript\">class DataBase {      \/**      *       * @readonly      *\/     static sqlite3 = require('sqlite3').verbose();          \/**     *      * @readonly     *\/    static database = new this.sqlite3.Database('.\/database\/database.db');          \/**      *       * @param {String[]} keys       * @param {String} table       * @param {String} condition       * @param {Boolean} some       * @param {Function()} callback       *\/     static getData(keys, table, condition = '', some = true, callback = () =&gt; {}) {         let sql = 'SELECT ';         for (let i = 0; i &lt; keys.length; i++) {             sql += keys[i] === '*' ? keys[i] : '`' + keys[i] + '`';             if (keys.length &gt; i + 1)                 sql += ', ';         }         sql += ' FROM `' + table + '` ' + condition;                  if (some)             this.database.all(sql, (err, rows) =&gt; {                 callback(err, rows);             });         else             this.database.get(sql, (err, row) =&gt; {                 callback(err, row);             });     };      static ToString(value) {         return typeof(value) === 'string' ? '\\'' + value + '\\'' : value;     } }  module.exports = {     database: DataBase };<\/code><\/pre>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0439 \u0437\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 \u043a\u043b\u044e\u0447\u0435\u0439 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u044f.<\/p>\n<pre><code class=\"javascript\">class DataBase {      \/**      *       * @readonly      *\/     static sqlite3 = require('sqlite3').verbose();          \/**     *      * @readonly     *\/    static database = new this.sqlite3.Database('.\/database\/database.db');          \/**      *       * @param {String[]} keys       * @param {String} table       * @param {String} condition       * @param {Boolean} some       * @param {Function()} callback       *\/     static getData(keys, table, condition = '', some = true, callback = () =&gt; {}) {         let sql = 'SELECT ';         for (let i = 0; i &lt; keys.length; i++) {             sql += keys[i] === '*' ? keys[i] : '`' + keys[i] + '`';             if (keys.length &gt; i + 1)                 sql += ', ';         }         sql += ' FROM `' + table + '` ' + condition;                  if (some)             this.database.all(sql, (err, rows) =&gt; {                 callback(err, rows);             });         else             this.database.get(sql, (err, row) =&gt; {                 callback(err, row);             });     };          \/**      *       * @param {String[]} keys       * @param {Values[]} values       * @param {String} table       * @param {String} condition       * @param {Function()} callback       *\/     static updateData(keys, values, table, condition, callback = () =&gt; {}) {         let sql = 'UPDATE `' + table + '` SET ';         for (let i = 0; i &lt; keys.length; i++) {             sql += '`' + keys[i] + '` = ' + this.ToString(values[i]);             if (keys.length &gt; i + 1)                 sql += ', ';         }         sql += ' ' + condition;                  this.database.run(sql, (err) =&gt; {             callback(err);         });     }      static ToString(value) {         return typeof(value) === 'string' ? '\\'' + value + '\\'' : value;     } }  module.exports = {     database: DataBase };<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0432\u0441\u0435\u043c \u0447\u0443\u0442\u044c-\u0447\u0443\u0442\u044c, \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445(\u043e\u043d\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439) \u0438 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043f\u043e\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u0432\u0441\u0435 \u043a\u043b\u044e\u0447\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0438 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 \u0432\u0441\u0435\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439(<strong>\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0438\u043d\u0434\u0435\u043a\u0441 \u043a\u0430\u043a \u0438 \u043a\u043b\u044e\u0447<\/strong>, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435).<\/p>\n<pre><code class=\"javascript\">class DataBase {      \/**      *       * @readonly      *\/     static sqlite3 = require('sqlite3').verbose();          \/**     *      * @readonly     *\/    static database = new this.sqlite3.Database('.\/database\/database.db');          \/**      *       * @param {String[]} keys       * @param {String} table       * @param {String} condition       * @param {Boolean} some       * @param {Function()} callback       *\/     static getData(keys, table, condition = '', some = true, callback = () =&gt; {}) {         let sql = 'SELECT ';         for (let i = 0; i &lt; keys.length; i++) {             sql += keys[i] === '*' ? keys[i] : '`' + keys[i] + '`';             if (keys.length &gt; i + 1)                 sql += ', ';         }         sql += ' FROM `' + table + '` ' + condition;                  if (some)             this.database.all(sql, (err, rows) =&gt; {                 callback(err, rows);             });         else             this.database.get(sql, (err, row) =&gt; {                 callback(err, row);             });     };          \/**      *       * @param {String[]} keys       * @param {Values[]} values       * @param {String} table       * @param {String} condition       * @param {Function()} callback       *\/     static updateData(keys, values, table, condition, callback = () =&gt; {}) {         let sql = 'UPDATE `' + table + '` SET ';         for (let i = 0; i &lt; keys.length; i++) {             sql += '`' + keys[i] + '` = ' + this.ToString(values[i]);             if (keys.length &gt; i + 1)                 sql += ', ';         }         sql += ' ' + condition;                  this.database.run(sql, (err) =&gt; {             callback(err);         });     }          \/**      * @param {String[]} keys      * @param {String[]} values      * @param {String} table       * @param {Function()} callback       *\/     static insertData(keys, values, table, callback = () =&gt; {}) {         let sql = 'INSERT INTO `' + table + '` (';         for (let i = 0; i &lt; keys.length; i++) {             sql += '`' + keys[i] + '`';             if (keys.length &gt; i + 1)                 sql += ', ';         }         sql += ') VALUES (';         for (let i = 0; i &lt; values.length; i++) {             sql += this.ToString(values[i]);             if (values.length &gt; i + 1)                 sql += ', ';         }         sql += ')';          this.database.run(sql, (err) =&gt; {             callback(err);         });     };      \/**      *       * @param {String} table       * @param {String} condition       * @param {Function()} callback       *\/     static deleteData(table, condition = '', callback = () =&gt; {}) {         this.database.run('DELETE FROM `' + table + '` ' + condition, (err) =&gt; {             callback(err);         });     }      static ToString(value) {         return typeof(value) === 'string' ? '\\'' + value + '\\'' : value;     } }  module.exports = {     database: DataBase };<\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0435, \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435!<br \/><a href=\"https:\/\/github.com\/Ilya-cmd\/Modul-for-sqlite3\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 GitHub<\/a><\/p>\n<\/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=\"https:\/\/habr.com\/ru\/post\/556314\/\"> https:\/\/habr.com\/ru\/post\/556314\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u042f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0435\u0439 \u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043c\u043d\u0435 \u0443\u0436\u0435 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u043f\u043e\u043b \u0433\u043e\u0434\u0430: &#171;\u041c\u043e\u0434\u0443\u043b\u044c \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 sqlite3&#187;.<\/p>\n<h2>\u041a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f<\/h2>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f SQL \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u0438, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446, \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438 callback&#8217;\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432(\u0432 \u043a\u0430\u0436\u0434\u044b\u0439 callback \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u0435\u0441\u0442\u044c).<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u043c\u043e\u0434\u0443\u043b\u044c \u0432 \u0432\u0438\u0434\u0435 \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>\u0412\u0441\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 4 \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<ol>\n<li>\n<p>getData() &#8212; \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<\/li>\n<li>\n<p>insertData() &#8212; \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443.<\/p>\n<\/li>\n<li>\n<p>updateData() &#8212; \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435.<\/p>\n<\/li>\n<li>\n<p>deleteData() &#8212; \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<\/li>\n<\/ol>\n<blockquote>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e 4 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u043c\u044b \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0432\u0438\u0434\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043d\u043e \u0432 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0438 \u044d\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0441\u0430\u043c\u044b\u0435 \u0447\u0430\u0441\u0442\u044b\u0435.<\/p>\n<\/blockquote>\n<h2>\u041a\u043e\u0434\u0438\u043c<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0430\u043c \u043a\u043b\u0430\u0441\u0441, \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043c \u044d\u043a\u0441\u043f\u043e\u0440\u0442 \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c\u0441\u044f \u043a \u0411\u0414 \u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u0430\u0432\u044b\u0447\u043a\u0438 \u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0435\u0441\u043b\u0438 \u0442\u0438\u043f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0438\u043f\u0443 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<pre><code class=\"javascript\">class DataBase {      \/**      *       * @readonly      *\/     static sqlite3 = require('sqlite3').verbose();          \/**     *      * @readonly     *\/    static database = new this.sqlite3.Database('.\/database\/database.db');      static ToString(value) {         return typeof(value) === 'string' ? '\\'' + value + '\\'' : value;     } }  module.exports = {     database: DataBase };<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u043e \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c, \u043a\u043e\u043b-\u0432\u043e \u0441\u0442\u0440\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u0431\u0443\u0434\u0443\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f(\u043e\u0434\u043d\u0430 \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e).<\/p>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 &#171;SELECT&#187;, \u0434\u0430\u043b\u0435\u0435 \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0438 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0438\u0445, <strong>\u043d\u043e \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u0441\u0438\u043c\u0432\u043e\u043b &#171;*&#187; \u043d\u0435 \u043d\u0443\u0436\u043d\u043e &#171;\u0437\u0430\u043a\u043e\u0432\u044b\u0432\u0430\u0442\u044c&#187; \u0432 \u043a\u0430\u0432\u044b\u0447\u043a\u0438, \u0442 \u043a \u044d\u0442\u043e\u0442 \u0441\u0438\u043c\u0432\u043e\u043b \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043d\u0430\u043c, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b<\/strong>. \u0417\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u043c \u0441\u043e\u0431\u043e\u0440 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u044f. \u0414\u0430\u043b\u0435\u0435, \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u043a\u043e\u043b-\u0432\u043e \u0441\u0442\u0440\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434.<\/p>\n<pre><code class=\"javascript\">class DataBase {      \/**      *       * @readonly      *\/     static sqlite3 = require('sqlite3').verbose();          \/**     *      * @readonly     *\/    static database = new this.sqlite3.Database('.\/database\/database.db');          \/**      *       * @param {String[]} keys       * @param {String} table       * @param {String} condition       * @param {Boolean} some       * @param {Function()} callback       *\/     static getData(keys, table, condition = '', some = true, callback = () =&gt; {}) {         let sql = 'SELECT ';         for (let i = 0; i &lt; keys.length; i++) {             sql += keys[i] === '*' ? keys[i] : '`' + keys[i] + '`';             if (keys.length &gt; i + 1)                 sql += ', ';         }         sql += ' FROM `' + table + '` ' + condition;                  if (some)             this.database.all(sql, (err, rows) =&gt; {                 callback(err, rows);             });         else             this.database.get(sql, (err, row) =&gt; {                 callback(err, row);             });     };      static ToString(value) {         return typeof(value) === 'string' ? '\\'' + value + '\\'' : value;     } }  module.exports = {     database: DataBase };<\/code><\/pre>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0439 \u0437\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 \u043a\u043b\u044e\u0447\u0435\u0439 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u044f.<\/p>\n<pre><code class=\"javascript\">class DataBase {      \/**      *       * @readonly      *\/     static sqlite3 = require('sqlite3').verbose();          \/**     *      * @readonly     *\/    static database = new this.sqlite3.Database('.\/database\/database.db');          \/**      *       * @param {String[]} keys       * @param {String} table       * @param {String} condition       * @param {Boolean} some       * @param {Function()} callback       *\/     static getData(keys, table, condition = '', some = true, callback = () =&gt; {}) {         let sql = 'SELECT ';         for (let i = 0; i &lt; keys.length; i++) {             sql += keys[i] === '*' ? keys[i] : '`' + keys[i] + '`';             if (keys.length &gt; i + 1)                 sql += ', ';         }         sql += ' FROM `' + table + '` ' + condition;                  if (some)             this.database.all(sql, (err, rows) =&gt; {                 callback(err, rows);             });         else             this.database.get(sql, (err, row) =&gt; {                 callback(err, row);             });     };          \/**      *       * @param {String[]} keys       * @param {Values[]} values       * @param {String} table       * @param {String} condition       * @param {Function()} callback       *\/     static updateData(keys, values, table, condition, callback = () =&gt; {}) {         let sql = 'UPDATE `' + table + '` SET ';         for (let i = 0; i &lt; keys.length; i++) {             sql += '`' + keys[i] + '` = ' + this.ToString(values[i]);             if (keys.length &gt; i + 1)                 sql += ', ';         }         sql += ' ' + condition;                  this.database.run(sql, (err) =&gt; {             callback(err);         });     }      static ToString(value) {         return typeof(value) === 'string' ? '\\'' + value + '\\'' : value;     } }  module.exports = {     database: DataBase };<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0432\u0441\u0435\u043c \u0447\u0443\u0442\u044c-\u0447\u0443\u0442\u044c, \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445(\u043e\u043d\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439) \u0438 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043f\u043e\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u0432\u0441\u0435 \u043a\u043b\u044e\u0447\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0438 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 \u0432\u0441\u0435\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439(<strong>\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0438\u043d\u0434\u0435\u043a\u0441 \u043a\u0430\u043a \u0438 \u043a\u043b\u044e\u0447<\/strong>, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435).<\/p>\n<pre><code class=\"javascript\">class DataBase {      \/**      *       * @readonly      *\/     static sqlite3 = require('sqlite3').verbose();          \/**     *      * @readonly     *\/    static database = new this.sqlite3.Database('.\/database\/database.db');          \/**      *       * @param {String[]} keys       * @param {String} table       * @param {String} condition       * @param {Boolean} some       * @param {Function()} callback       *\/     static getData(keys, table, condition = '', some = true, callback = () =&gt; {}) {         let sql = 'SELECT ';         for (let i = 0; i &lt; keys.length; i++) {             sql += keys[i] === '*' ? keys[i] : '`' + keys[i] + '`';             if (keys.length &gt; i + 1)                 sql += ', ';         }         sql += ' FROM `' + table + '` ' + condition;                  if (some)             this.database.all(sql, (err, rows) =&gt; {                 callback(err, rows);             });         else             this.database.get(sql, (err, row) =&gt; {                 callback(err, row);             });     };          \/**      *       * @param {String[]} keys       * @param {Values[]} values       * @param {String} table       * @param {String} condition       * @param {Function()} callback       *\/     static updateData(keys, values, table, condition, callback = () =&gt; {}) {         let sql = 'UPDATE `' + table + '` SET ';         for (let i = 0; i &lt; keys.length; i++) {             sql += '`' + keys[i] + '` = ' + this.ToString(values[i]);             if (keys.length &gt; i + 1)                 sql += ', ';         }         sql += ' ' + condition;                  this.database.run(sql, (err) =&gt; {             callback(err);         });     }          \/**      * @param {String[]} keys      * @param {String[]} values      * @param {String} table       * @param {Function()} callback       *\/     static insertData(keys, values, table, callback = () =&gt; {}) {         let sql = 'INSERT INTO `' + table + '` (';         for (let i = 0; i &lt; keys.length; i++) {             sql += '`' + keys[i] + '`';             if (keys.length &gt; i + 1)                 sql += ', ';         }         sql += ') VALUES (';         for (let i = 0; i &lt; values.length; i++) {             sql += this.ToString(values[i]);             if (values.length &gt; i + 1)                 sql += ', ';         }         sql += ')';          this.database.run(sql, (err) =&gt; {             callback(err);         });     };      \/**      *       * @param {String} table       * @param {String} condition       * @param {Function()} callback       *\/     static deleteData(table, condition = '', callback = () =&gt; {}) {         this.database.run('DELETE FROM `' + table + '` ' + condition, (err) =&gt; {             callback(err);         });     }      static ToString(value) {         return typeof(value) === 'string' ? '\\'' + value + '\\'' : value;     } }  module.exports = {     database: DataBase };<\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0435, \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435!<br \/><a href=\"https:\/\/github.com\/Ilya-cmd\/Modul-for-sqlite3\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 GitHub<\/a><\/p>\n<\/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=\"https:\/\/habr.com\/ru\/post\/556314\/\"> https:\/\/habr.com\/ru\/post\/556314\/<\/a><br \/><\/br><\/br><\/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-322731","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/322731","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=322731"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/322731\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=322731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=322731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=322731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}