mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2025-06-29 05:15:35 -04:00
adding mini msg board
Squashed commit of the following: commit5e685faff0
Author: Mike Smith <89040888+smiggiddy@users.noreply.github.com> Date: Wed Jan 1 20:39:19 2025 -0500 feat: mobile styling commit30a4ac6326
Author: Mike Smith <89040888+smiggiddy@users.noreply.github.com> Date: Wed Jan 1 16:51:53 2025 -0500 another test commitb847c0f231
Author: Mike Smith <89040888+smiggiddy@users.noreply.github.com> Date: Wed Jan 1 16:48:29 2025 -0500 fix: cf header commitacc580fb79
Author: Mike Smith <89040888+smiggiddy@users.noreply.github.com> Date: Wed Jan 1 16:46:22 2025 -0500 feat: add client ip tracking commit289b95d957
Author: Mike Smith <89040888+smiggiddy@users.noreply.github.com> Date: Wed Jan 1 16:40:49 2025 -0500 feat: add footer and styling commiteda40eb113
Author: Mike Smith <89040888+smiggiddy@users.noreply.github.com> Date: Wed Jan 1 14:59:35 2025 -0500 feat: added a comment section commit27840f3537
Author: Mike Smith <89040888+smiggiddy@users.noreply.github.com> Date: Tue Dec 31 14:45:21 2024 -0500 css: black color commit3c3deda986
Author: Mike Smith <89040888+smiggiddy@users.noreply.github.com> Date: Tue Dec 31 14:29:00 2024 -0500 ui: better design and stuff commitcd43c949aa
Author: Mike Smith <89040888+smiggiddy@users.noreply.github.com> Date: Sat Dec 28 17:47:39 2024 -0500 fix: styling commit8c0a4a773e
Author: Mike Smith <89040888+smiggiddy@users.noreply.github.com> Date: Sat Dec 28 14:32:07 2024 -0500 styling added + better templates commit0a21838c91
Author: Mike Smith <89040888+smiggiddy@users.noreply.github.com> Date: Fri Dec 27 22:33:44 2024 -0500 fix: create tables commit77832d73de
Author: Mike Smith <89040888+smiggiddy@users.noreply.github.com> Date: Fri Dec 27 22:21:48 2024 -0500 dockerfile_update commit90769c9bf1
Author: Mike Smith <89040888+smiggiddy@users.noreply.github.com> Date: Fri Dec 27 22:17:36 2024 -0500 more code commite07590d6e5
Author: Mike Smith <89040888+smiggiddy@users.noreply.github.com> Date: Thu Dec 26 08:15:00 2024 -0500 updates commit1d28883841
Author: Mike Smith <89040888+smiggiddy@users.noreply.github.com> Date: Thu Dec 26 07:38:38 2024 -0500 updated docker file commiteb3068af96
Author: Mike Smith <89040888+smiggiddy@users.noreply.github.com> Date: Thu Dec 26 07:27:38 2024 -0500 added dockerfile commit15a77883f4
Author: Mike Smith <89040888+smiggiddy@users.noreply.github.com> Date: Wed Dec 25 22:45:54 2024 -0500 basic msg board
This commit is contained in:
parent
b66089f97e
commit
59a08e23a9
23 changed files with 3198 additions and 0 deletions
50
nodejs-mini-message-board/src/db/query.js
Normal file
50
nodejs-mini-message-board/src/db/query.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
const db = require("../db");
|
||||
|
||||
async function getAllMessages() {
|
||||
return new Promise((resolve) => {
|
||||
db.all("SELECT * FROM messages ORDER BY date DESC;", async (err, rows) =>
|
||||
resolve(rows),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
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)", [
|
||||
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,
|
||||
};
|
26
nodejs-mini-message-board/src/db/seedDb.js
Normal file
26
nodejs-mini-message-board/src/db/seedDb.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
const db = require("../db");
|
||||
|
||||
const SQL = `
|
||||
CREATE TABLE IF NOT EXISTS messages (
|
||||
id INTEGER PRIMARY KEY ASC,
|
||||
message TEXT,
|
||||
username VARCHAR(25),
|
||||
date NUMBER
|
||||
|
||||
);
|
||||
|
||||
INSERT INTO messages (message, username, date)
|
||||
VALUES
|
||||
('this is cool', 'smig.tech', '1735391440168.0'),
|
||||
('I like this app', 'smigz', '1733577117'),
|
||||
('For real, it is nice', 'mikey', '1735391626')
|
||||
`;
|
||||
|
||||
async function main(db) {
|
||||
console.log("seeding db...");
|
||||
db.serialize(() => {
|
||||
db.exec(SQL);
|
||||
});
|
||||
}
|
||||
|
||||
main(db);
|
Loading…
Add table
Add a link
Reference in a new issue