mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2025-06-28 21:05:36 -04:00
feat: added a comment section
This commit is contained in:
parent
27840f3537
commit
eda40eb113
11 changed files with 197 additions and 12 deletions
|
@ -8,15 +8,43 @@ async function getAllMessages() {
|
|||
});
|
||||
}
|
||||
|
||||
async function getMessageById(id) {
|
||||
return new Promise((resolve) => {
|
||||
db.get("SELECT * FROM messages WHERE id = (?)", [id], async (err, rows) => {
|
||||
resolve(rows);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function insertMessage(msg) {
|
||||
db.run("INSERT INTO MESSAGES (message, username, date) VALUES ($1, $2, $3)", [
|
||||
db.run("INSERT INTO messages (message, username, date) VALUES ($1, $2, $3)", [
|
||||
msg.message,
|
||||
msg.username,
|
||||
msg.date,
|
||||
]);
|
||||
}
|
||||
|
||||
async function getAllCommentsForMessage(msgId) {
|
||||
return new Promise((resolve) => {
|
||||
db.all(
|
||||
"SELECT * FROM COMMENTS WHERE message_id = (?)",
|
||||
[msgId],
|
||||
async (err, rows) => resolve(rows),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async function insertComment(msgId, comment) {
|
||||
db.run("INSERT INTO comments (comment, message_id) VALUES ($1, $2)", [
|
||||
comment,
|
||||
msgId,
|
||||
]);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getMessageById,
|
||||
getAllMessages,
|
||||
insertMessage,
|
||||
getAllCommentsForMessage,
|
||||
insertComment,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue