2023-04-18 14:41:16 -06:00
|
|
|
const connection = require('./connection');
|
2023-04-29 20:48:03 -06:00
|
|
|
|
|
|
|
async function getDeveloperNames() {
|
|
|
|
let selectSql = `SELECT id,name FROM developers`
|
|
|
|
|
|
|
|
return await connection.query(selectSql);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getDeveloper(id) {
|
|
|
|
|
|
|
|
let selectSql = `SELECT name,homepage,description FROM developers`,
|
|
|
|
whereStatements = [],
|
|
|
|
queryParameters = [];
|
|
|
|
|
|
|
|
if (typeof id !== 'undefined' && id.length > 0) {
|
|
|
|
whereStatements.push("id LIKE ?");
|
|
|
|
queryParameters.push('%' + id + '%');
|
|
|
|
}
|
|
|
|
|
|
|
|
//Dynamically add WHERE expressions to SELECT statements if needed
|
|
|
|
if (whereStatements.length > 0) {
|
|
|
|
selectSql = selectSql + ' WHERE ' + whereStatements.join(' AND ');
|
|
|
|
}
|
|
|
|
|
|
|
|
return await connection.query(selectSql, queryParameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function addNewDeveloper(formInput) {
|
|
|
|
let insertSql = `INSERT INTO developers (name, description, homepage) VALUES (?, ?, ?)`;
|
|
|
|
let queryParameters = [formInput.name,
|
|
|
|
formInput.description,
|
|
|
|
formInput.homepage];
|
|
|
|
|
|
|
|
return await connection.query(insertSql, queryParameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getDeveloperNames,
|
|
|
|
getDeveloper,
|
|
|
|
addNewDeveloper
|
|
|
|
}
|