41 lines
No EOL
1.1 KiB
JavaScript
41 lines
No EOL
1.1 KiB
JavaScript
const connection = require('./connection');
|
|
|
|
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
|
|
} |