Closed uladkasach closed 4 years ago
note: generate the mysqlBestPracticesExecute - to make it easy to edit for users, or import it?
not importing is more in line with the spirit of generator.
const executeQueryWithBestPracticesForMysql = async ({
dbExecute,
logDebug,
name,
sql,
input,
}: {
dbExecute: DatabaseExecuteCommand;
logDebug: LogMethod;
name: string;
sql: string;
input: any;
}) => {
// 1. define the query with yesql
const { sql: preparedSql, values: preparedValues } = prepare(sql)(input);
// 2. log that we're running the request
logDebug(`${name}.input`, { input });
// 3. execute the query
const [output] = await dbExecute({ sql: preparedSql, values: preparedValues });
// 4. log that we've executed the request
logDebug(`${name}.output`, { output });
// 5. return the output
return output;
};
but importing might help prevent the changing generated code
problem.
plus, it is really easy to swap out for your own - so it wouldn't be a blocker...
significant con of "importing" - it would then have to be a "dependency" instead of a "dev dependency". so, no imports
to
where