sql..
This commit is contained in:
@ -1,8 +1,16 @@
|
||||
import express from "express";
|
||||
const router = express.Router();
|
||||
|
||||
import db from "../../lib/sql";
|
||||
|
||||
router.get("/", (req, res) => {
|
||||
res.render("index");
|
||||
db.exec("select * from `languages`")
|
||||
.then(rows => {
|
||||
res.render("index", { languages: rows.map(r => r.name) } )
|
||||
})
|
||||
.catch(err => {
|
||||
res.send(err);
|
||||
});
|
||||
});
|
||||
|
||||
export default router;
|
@ -2,31 +2,31 @@ import express from "express";
|
||||
const router = express.Router();
|
||||
|
||||
import highlight from "highlight.js";
|
||||
import db from "../../lib/sql";
|
||||
|
||||
router.get("/", (req, res) => {
|
||||
const data = {
|
||||
pastes: [
|
||||
{
|
||||
title: "title 01",
|
||||
paste: highlight.highlightAuto("<?php\necho 'blah';\n?>").value,
|
||||
language: "PHP",
|
||||
rows: "<?php\necho 'blah';\n?>".split(/\n/).length
|
||||
},
|
||||
{
|
||||
title: "title 02",
|
||||
paste: highlight.highlightAuto("blub").value,
|
||||
language: "Plaintext",
|
||||
rows: "blub".split(/\n/).length
|
||||
},
|
||||
{
|
||||
title: "title 03",
|
||||
paste: highlight.highlightAuto("muh").value,
|
||||
language: "Plaintext",
|
||||
rows: "muh".split(/\n/).length
|
||||
}
|
||||
]
|
||||
};
|
||||
res.render("view", data);
|
||||
const query = "select p.uuid, p.stamp, p.title, p.paste, l.name as language, r.uuid as reply from `pastes` as p "
|
||||
+ "left join `languages` as l on l.id = p.lang "
|
||||
+ "left join `pastes` as r on r.id = p.reply "
|
||||
+ "order by p.id desc "
|
||||
+ "limit 5";
|
||||
db.exec(query)
|
||||
.then(rows => {
|
||||
const pastes = rows.map(r => {
|
||||
return {
|
||||
title: r.title,
|
||||
uuid: r.uuid,
|
||||
paste: highlight.highlightAuto(r.paste).value,
|
||||
language: r.language,
|
||||
desc: r.reply ? `Reply to <a href="/${r.reply}/" class="descID">/${r.reply}/</a>` : "No description.",
|
||||
rows: r.paste.split(/\r?\n/).length
|
||||
};
|
||||
});
|
||||
res.render("view", { pastes: pastes });
|
||||
})
|
||||
.catch(err => {
|
||||
res.render("view");
|
||||
});
|
||||
});
|
||||
|
||||
export default router;
|
Reference in New Issue
Block a user