2023-04-18 14:41:16 -06:00
|
|
|
const connection = require('./connection');
|
2023-04-29 20:48:03 -06:00
|
|
|
|
|
|
|
async function getPublisherNames() {
|
|
|
|
let selectSql = `SELECT id,name FROM publishers`
|
|
|
|
|
|
|
|
return await connection.query(selectSql);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getPublisher(id) {
|
|
|
|
|
|
|
|
let selectSql = `SELECT name,homepage,description FROM publishers`,
|
|
|
|
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 addNewPublisher(formInput) {
|
|
|
|
let insertSql = `INSERT INTO publishers (name, description, homepage) VALUES (?, ?, ?)`;
|
|
|
|
let queryParameters = [formInput.name,
|
|
|
|
formInput.description,
|
|
|
|
formInput.homepage];
|
|
|
|
|
|
|
|
return await connection.query(insertSql, queryParameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getPublisherNames,
|
|
|
|
getPublisher,
|
|
|
|
addNewPublisher
|
|
|
|
}
|