mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2025-06-28 21:05:36 -04:00
more code
This commit is contained in:
parent
e07590d6e5
commit
90769c9bf1
16 changed files with 1710 additions and 63 deletions
22
nodejs-mini-message-board/src/db/query.js
Normal file
22
nodejs-mini-message-board/src/db/query.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
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 insertMessage(msg) {
|
||||
db.run("INSERT INTO MESSAGES (message, username, date) VALUES (?, ?, ?)", [
|
||||
msg.message,
|
||||
msg.username,
|
||||
msg.date,
|
||||
]);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getAllMessages,
|
||||
insertMessage,
|
||||
};
|
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 TEXT
|
||||
|
||||
);
|
||||
|
||||
INSERT INTO messages (message, username, date)
|
||||
VALUES
|
||||
('this is cool', 'smig.tech', '2024-12-24T01:12:340Z'),
|
||||
('I like this app', 'smigz', '2024-12-25T00:32:43.540Z'),
|
||||
('For real, it is nice', 'mikey', '2024-12-28T00:35:43.540Z')
|
||||
`;
|
||||
|
||||
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