Dwelling/dwelling/mindflow.js

49 lines
1.4 KiB
JavaScript

const mysql = require("mysql");
const config = require("../config");
const util = require("../util");
let connection = mysql.createConnection(config.dwelling.database);
connection.config.queryFormat = util.mysqlQueryFormat;
exports.closeConnection = () => connection.end();
exports.getPosts = category => {
return new Promise((resolve, reject) => {
let query = "\
SELECT\
`blog`.`entry_id` AS `post_id`,\
`blog`.`date`,\
`blog`.`title`,\
`blog`.`body`\
FROM `blog`\
LEFT JOIN `blog_categories` ON `blog_categories`.`category_id` = `blog`.`category`\
WHERE `blog_categories`.`category` = :category\
ORDER BY `blog`.`date` DESC;";
connection.query(query, { category: category }, (err, results) => {
if (err) reject(err);
resolve(results); });
});
};
exports.getPostsForRSS = () => {
return new Promise((resolve, reject) => {
let query = "\
SELECT\
`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); });
});
};