Moved queryFormat func that is used in several places to util.js.
This commit is contained in:
parent
02f046c789
commit
3b5c08936d
@ -1,27 +1,17 @@
|
||||
const mysql = require("mysql");
|
||||
|
||||
const config = require("../config");
|
||||
const util = require("../util");
|
||||
|
||||
|
||||
let connection = mysql.createConnection(config.dwelling.database);
|
||||
|
||||
|
||||
// This code was taken from https://www.npmjs.com/package/mysql#custom-format
|
||||
// Only fourth line was changed.
|
||||
connection.config.queryFormat = function (query, values) {
|
||||
if (!values) return query;
|
||||
return query.replace(/\:(\w+)/g, function (txt, key) {
|
||||
if (values[key] !== undefined)
|
||||
return this.escape(values[key]);
|
||||
return txt;
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
connection.config.queryFormat = util.mysqlQueryFormat;
|
||||
|
||||
exports.pageSize = config.dwelling.guestbook.pageSize !== undefined
|
||||
? config.dwelling.guestbook.pageSize : 20;
|
||||
|
||||
|
||||
exports.closeConnection = () => connection.end();
|
||||
|
||||
exports.getPosts = async (page = 1, page_size = exports.pageSize) => {
|
||||
|
@ -1,19 +1,13 @@
|
||||
const mysql = require("mysql");
|
||||
|
||||
const config = require("../config");
|
||||
const util = require("../util");
|
||||
|
||||
|
||||
let connection = mysql.createConnection(config.dwelling.database);
|
||||
|
||||
// This code was taken from https://www.npmjs.com/package/mysql#custom-format
|
||||
// Only fourth line was changed.
|
||||
connection.config.queryFormat = function (query, values) {
|
||||
if (!values) return query;
|
||||
return query.replace(/\:(\w+)/g, function (txt, key) {
|
||||
if (values[key] !== undefined)
|
||||
return this.escape(values[key]);
|
||||
return txt;
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
connection.config.queryFormat = util.mysqlQueryFormat;
|
||||
|
||||
exports.closeConnection = () => connection.end();
|
||||
|
||||
|
11
util.js
11
util.js
@ -40,3 +40,14 @@ exports.datetime = datetime;
|
||||
exports.rssLink = (proto, host, date, category, timezone="UTC") =>
|
||||
`${proto}://${host}/mindflow#${category}-${datetime(date, formats.id_date, timezone)}`;
|
||||
|
||||
// This code was taken from https://www.npmjs.com/package/mysql#custom-format
|
||||
// Only fourth line was changed.
|
||||
exports.mysqlQueryFormat = function (query, values) {
|
||||
if (!values) return query;
|
||||
return query.replace(/\:(\w+)/g, function (txt, key) {
|
||||
if (values[key] !== undefined)
|
||||
return this.escape(values[key]);
|
||||
return txt;
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user