Dynamic columns in updates
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 374
- Avg merge
- 11d 16h
- Merged PRs (30d)
- 1
Description
trying to make an update with dynamic columns and i'm getting a bunch of errors
object
cliente: {
id: 3,
nome: 'Teste Um',
tipo: 'F',
cpf: '12345678910',
cnpj: null,
email: 'teste@black.com',
telefone: '46111111111',
status: 'A',
datacadastro: '2024-02-01'
}
query
const cols = ['nome', 'tipo', 'cpf', 'cnpj', 'email', 'telefone'];
const update = await sql`UPDATE clientes SET (${sql(cliente, cols)}) WHERE id=${sql(cliente.id)}`;
error: Cannot convert undefined or null to object
query 2 (removed the null fields)
const cols = ['nome', 'tipo', 'cpf', 'email', 'telefone'];
const update = await sql`UPDATE clientes SET (${sql(cliente, cols)}) WHERE id=${sql(cliente.id)}`;
error: syntax error at or near "$1"
query 3 (removed the () after SET)
const cols = ['nome', 'tipo', 'cpf', 'cnpj', 'email', 'telefone'];
const update = await sql`UPDATE clientes SET ${sql(cliente, cols)} WHERE id=${sql(cliente.id)}`;
error: syntax error at end of input
any thoughts?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file or test is named. Start by reproducing the three UPDATE examples using the sql helper and PostgreSQL, comparing the behavior of null values, the parenthesized SET expression, and the unparenthesized form. Done means establishing the supported dynamic-column syntax and documenting or correcting the failing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs, postgresql
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100