mirror of
https://github.com/gnmyt/myspeed.git
synced 2026-01-06 13:09:43 -06:00
Created the speedtest controller
This commit is contained in:
28
server/controller/speedtests.js
Normal file
28
server/controller/speedtests.js
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user