UNPKG

@trithanka/sql-builder

Version:

A lightweight, function-based, chainable SQL query builder for Node.js using MySQL pool connections.

10 lines (8 loc) 380 B
function buildUpdateQuery(table, data, whereClause, whereValues = []) { const keys = Object.keys(data); const setClause = keys.map(key => `${key} = ?`).join(', '); const values = [...Object.values(data), ...whereValues]; const sql = `UPDATE ${table} SET ${setClause} WHERE ${whereClause}`; return { sql, values }; } module.exports = buildUpdateQuery;