2021-06-05 18:58:22 +04:00
|
|
|
const mysql = require("mysql");
|
|
|
|
|
|
|
|
const config = require("./config");
|
|
|
|
const util = require("../shared/util");
|
|
|
|
|
|
|
|
|
|
|
|
let connection = mysql.createConnection(config.database);
|
|
|
|
|
|
|
|
|
|
|
|
connection.config.queryFormat = util.mysqlQueryFormat;
|
|
|
|
|
|
|
|
exports.closeConnection = () => connection.end();
|
|
|
|
|
2022-01-21 20:56:46 +04:00
|
|
|
exports.getPosts = () => {
|
2021-06-05 18:58:22 +04:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
let query = `
|
|
|
|
SELECT
|
|
|
|
blog.entry_id AS post_id,
|
|
|
|
blog.date,
|
|
|
|
blog_categories.category,
|
|
|
|
blog.title,
|
|
|
|
blog.body
|
|
|
|
FROM blog
|
|
|
|
LEFT JOIN blog_categories ON blog_categories.category_id = blog.category
|
|
|
|
ORDER BY blog.date DESC;`;
|
|
|
|
|
|
|
|
connection.query(query, (err, results) => {
|
|
|
|
if (err) reject(err);
|
|
|
|
resolve(results); });
|
|
|
|
});
|
|
|
|
};
|