MCPcopy Create free account
hub / github.com/electric-sql/electric / generateUpdateQuery

Function generateUpdateQuery

examples/todo-app/server.js:201–221  ·  view source on GitHub ↗
(table, updates, conditions)

Source from the content-addressed store, hash-verified

199*/
200
201function generateUpdateQuery(table, updates, conditions) {
202 const setClauses = []
203 const values = []
204 let index = 1
205
206 for (const [key, value] of Object.entries(updates)) {
207 setClauses.push(`"${key}" = $${index}`)
208 values.push(value)
209 index++
210 }
211
212 const conditionClauses = []
213 for (const [key, value] of Object.entries(conditions)) {
214 conditionClauses.push(`"${key}" = $${index}`)
215 values.push(value)
216 index++
217 }
218
219 const query = `UPDATE "${table}" SET ${setClauses.join(`, `)} WHERE ${conditionClauses.join(` AND `)}`
220 return { query, values }
221}

Callers 1

server.jsFile · 0.85

Calls 3

entriesMethod · 0.45
pushMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected