const connection = require('./connection'); 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 }