Created the speedtest controller

This commit is contained in:
Mathias Wagner
2022-04-06 21:10:50 +02:00
parent 81f6bb6514
commit 0c64342b2c

View File

@@ -0,0 +1,28 @@
const db = require('../index').database;
// Inserts a new speedtest into the database
module.exports.create = (ping, download, upload) => {
return db.prepare("INSERT INTO speedtests (ping, download, upload) VALUES (?, ?, ?)").run(ping, download, upload).lastInsertRowid;
}
// Gets a specific speedtest by id
module.exports.get = (id) => {
return db.prepare("SELECT * FROM speedtests WHERE id = ?").get(id);
}
// Lists all speedtests from the database
module.exports.list = () => {
return db.prepare("SELECT * FROM speedtests").all();
}
// Gets the latest speedtest from the database
module.exports.latest = () => {
return db.prepare("SELECT * FROM speedtests ORDER BY id DESC").get();
}
// Deletes a specific speedtest
module.exports.delete = (id) => {
if (this.get(id) === undefined) return undefined;
db.prepare("DELETE FROM speedtests WHERE id = ?").run(id);
return true;
}